Add Premount to SmbService
- Adds Premount method in SmbService in anticipation of
SmbProviderClient::Premount's implementation.
- Adds reponse callback method to connect MountOptions of the
preconfigured share to the FileSystem.
Bug: chromium:878502
Test: compiles
Change-Id: I0c9af981d0cd1f2fd57c5a5ecfec4feef6c127de
Reviewed-on: https://chromium-review.googlesource.com/c/1407660
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Reviewed-by: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625488}
diff --git a/chrome/browser/chromeos/smb_client/smb_service.cc b/chrome/browser/chromeos/smb_client/smb_service.cc
index b4a1fd4..d4f02fb 100644
--- a/chrome/browser/chromeos/smb_client/smb_service.cc
+++ b/chrome/browser/chromeos/smb_client/smb_service.cc
@@ -378,6 +378,45 @@
}
}
+void SmbService::Premount(const base::FilePath& share_path) {
+ GetSmbProviderClient()->Premount(
+ share_path, IsNTLMAuthenticationEnabled(),
+ base::BindOnce(&SmbService::OnPremountResponse, AsWeakPtr(), share_path));
+}
+
+void SmbService::OnPremountResponse(const base::FilePath& share_path,
+ smbprovider::ErrorType error,
+ int32_t mount_id) {
+ const bool allowed_error = (error == smbprovider::ERROR_OK) ||
+ (error == smbprovider::ERROR_ACCESS_DENIED);
+ if (!allowed_error) {
+ LOG(ERROR) << "Error mounting preconfigured share in smbprovider.";
+ return;
+ }
+
+ DCHECK_GE(mount_id, 0);
+
+ file_system_provider::MountOptions mount_options;
+ mount_options.display_name = share_path.BaseName().value();
+ mount_options.writable = true;
+ // |is_chromad_kerberos| is false because we do not pass user and workgroup
+ // at mount time. Premounts also do not get remounted and currently
+ // |is_chromad_kerberos| is only used at remounts to determine if the share
+ // was mounted with chromad kerberos.
+ // TODO(jimmyxgong): Support chromad kerberos for premount.
+ mount_options.file_system_id =
+ CreateFileSystemId(mount_id, share_path, false /* is_chromad_kerberos */);
+ // Disable remounting of preconfigured shares.
+ mount_options.persistent = false;
+
+ const base::File::Error result =
+ GetProviderService()->MountFileSystem(provider_id_, mount_options);
+
+ if (result != base::File::FILE_OK) {
+ LOG(ERROR) << "Error mounting preconfigured share with File Manager.";
+ }
+}
+
void SmbService::StartSetup() {
user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
diff --git a/chrome/browser/chromeos/smb_client/smb_service.h b/chrome/browser/chromeos/smb_client/smb_service.h
index 54fadeb..518c0727 100644
--- a/chrome/browser/chromeos/smb_client/smb_service.h
+++ b/chrome/browser/chromeos/smb_client/smb_service.h
@@ -128,6 +128,16 @@
void OnRemountResponse(const std::string& file_system_id,
smbprovider::ErrorType error);
+ // Calls SmbProviderClient::Premount(). |temp_file_manager_| must be
+ // initialized before this is called.
+ void Premount(const base::FilePath& share_path);
+
+ // Handles the response from attempting to premount a share configured via
+ // policy. If premounting fails it will log and exit the operation.
+ void OnPremountResponse(const base::FilePath& share_path,
+ smbprovider::ErrorType error,
+ int32_t mount_id);
+
// Sets up SmbService, including setting up Keberos if the user is ChromAD.
void StartSetup();