Use Mount() for SMB share "premount"
Premount is the same as Mount(skip_connect) with no credentials. Change
premount mode to use the regular Mount() D-Bus method so that the
interface and smbprovider can be simplified.
BUG=None
Change-Id: I7deaa33d1fbd0418752ce97e85e0561c6e2180d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1621787
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661632}
diff --git a/chrome/browser/chromeos/smb_client/smb_service.cc b/chrome/browser/chromeos/smb_client/smb_service.cc
index ffa6d01..3421132 100644
--- a/chrome/browser/chromeos/smb_client/smb_service.cc
+++ b/chrome/browser/chromeos/smb_client/smb_service.cc
@@ -464,8 +464,12 @@
}
void SmbService::Premount(const base::FilePath& share_path) {
- GetSmbProviderClient()->Premount(
- share_path, IsNTLMAuthenticationEnabled(),
+ // Premounting is equivalent to remounting, but with an empty username and
+ // password.
+ GetSmbProviderClient()->Mount(
+ share_path, IsNTLMAuthenticationEnabled(), "", "",
+ temp_file_manager_->WritePasswordToFile("" /* password */),
+ true /* skip_connect */,
base::BindOnce(&SmbService::OnPremountResponse, AsWeakPtr(), share_path));
}
diff --git a/chrome/browser/chromeos/smb_client/smb_service_unittest.cc b/chrome/browser/chromeos/smb_client/smb_service_unittest.cc
index 45b8eae..c7b5714 100644
--- a/chrome/browser/chromeos/smb_client/smb_service_unittest.cc
+++ b/chrome/browser/chromeos/smb_client/smb_service_unittest.cc
@@ -10,6 +10,7 @@
#include <utility>
#include "base/bind.h"
+#include "base/json/json_reader.h"
#include "base/run_loop.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/smb_client/smb_file_system_id.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
@@ -250,5 +252,32 @@
EXPECT_TRUE(testing::Mock::VerifyAndClearExpectations(mock_client_));
}
+TEST_F(SmbServiceTest, Premount) {
+ const char kPremountPath[] = "smb://server/foobar";
+ const char kPreconfiguredShares[] =
+ "[{\"mode\":\"pre_mount\",\"share_url\":\"\\\\\\\\server\\\\foobar\"}]";
+ auto parsed_shares = base::JSONReader::Read(kPreconfiguredShares);
+ ASSERT_TRUE(parsed_shares);
+ profile_->GetPrefs()->Set(prefs::kNetworkFileSharesPreconfiguredShares,
+ *parsed_shares);
+
+ base::RunLoop run_loop;
+ EXPECT_CALL(*mock_client_, Mount(base::FilePath(kPremountPath), _, "", "", _,
+ true /* skip_connect */, _))
+ .WillOnce(WithArg<6>(
+ Invoke([&run_loop](SmbProviderClient::MountCallback callback) {
+ std::move(callback).Run(smbprovider::ErrorType::ERROR_OK, 7);
+ run_loop.Quit();
+ })));
+
+ CreateFspRegistry(profile_);
+ CreateService(profile_);
+ run_loop.Run();
+
+ // Because the mock is potentially leaked, expectations needs to be manually
+ // verified.
+ EXPECT_TRUE(testing::Mock::VerifyAndClearExpectations(mock_client_));
+}
+
} // namespace smb_client
} // namespace chromeos