Commit 4b4e71d1 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Add ShouldOpenFileManagerAfterMount attribute to add-smb-share-dialog

This change adds an InSettings attribute that is used to determine whether
the File Manager should be automatically opened on a successful mount call.
When mounting from the free-form dialog, the File Manager will not be
automatically opened.

Bug: chromium:887135
Test: browser_tests --gtest_filter=CrSettingsSmb*
Change-Id: I4e681c1ffe104f234784c2f958d24b2d257bc33c
Reviewed-on: https://chromium-review.googlesource.com/c/1336911Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613197}
parent 35dcd9d1
...@@ -135,11 +135,12 @@ void SmbService::Mount(const file_system_provider::MountOptions& options, ...@@ -135,11 +135,12 @@ void SmbService::Mount(const file_system_provider::MountOptions& options,
const std::string& username, const std::string& username,
const std::string& password, const std::string& password,
bool use_chromad_kerberos, bool use_chromad_kerberos,
bool should_open_file_manager_after_mount,
MountResponse callback) { MountResponse callback) {
DCHECK(temp_file_manager_); DCHECK(temp_file_manager_);
CallMount(options, share_path, username, password, use_chromad_kerberos, CallMount(options, share_path, username, password, use_chromad_kerberos,
std::move(callback)); should_open_file_manager_after_mount, std::move(callback));
} }
void SmbService::GatherSharesInNetwork(HostDiscoveryResponse discovery_callback, void SmbService::GatherSharesInNetwork(HostDiscoveryResponse discovery_callback,
...@@ -154,6 +155,7 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options, ...@@ -154,6 +155,7 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options,
const std::string& username_input, const std::string& username_input,
const std::string& password_input, const std::string& password_input,
bool use_chromad_kerberos, bool use_chromad_kerberos,
bool should_open_file_manager_after_mount,
MountResponse callback) { MountResponse callback) {
std::string username; std::string username;
std::string password; std::string password;
...@@ -208,7 +210,8 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options, ...@@ -208,7 +210,8 @@ void SmbService::CallMount(const file_system_provider::MountOptions& options,
temp_file_manager_->WritePasswordToFile(password), temp_file_manager_->WritePasswordToFile(password),
base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(), base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(),
base::Passed(&callback), options, share_path, base::Passed(&callback), options, share_path,
use_chromad_kerberos)); use_chromad_kerberos,
should_open_file_manager_after_mount));
profile_->GetPrefs()->SetString(prefs::kMostRecentlyUsedNetworkFileShareURL, profile_->GetPrefs()->SetString(prefs::kMostRecentlyUsedNetworkFileShareURL,
share_path.value()); share_path.value());
...@@ -219,6 +222,7 @@ void SmbService::OnMountResponse( ...@@ -219,6 +222,7 @@ void SmbService::OnMountResponse(
const file_system_provider::MountOptions& options, const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
bool is_kerberos_chromad, bool is_kerberos_chromad,
bool should_open_file_manager_after_mount,
smbprovider::ErrorType error, smbprovider::ErrorType error,
int32_t mount_id) { int32_t mount_id) {
if (error != smbprovider::ERROR_OK) { if (error != smbprovider::ERROR_OK) {
...@@ -235,7 +239,7 @@ void SmbService::OnMountResponse( ...@@ -235,7 +239,7 @@ void SmbService::OnMountResponse(
base::File::Error result = base::File::Error result =
GetProviderService()->MountFileSystem(provider_id_, mount_options); GetProviderService()->MountFileSystem(provider_id_, mount_options);
if (result == base::File::FILE_OK) { if (result == base::File::FILE_OK && should_open_file_manager_after_mount) {
OpenFileManager(mount_options.file_system_id); OpenFileManager(mount_options.file_system_id);
} }
......
...@@ -62,6 +62,7 @@ class SmbService : public KeyedService, ...@@ -62,6 +62,7 @@ class SmbService : public KeyedService,
const std::string& username, const std::string& username,
const std::string& password, const std::string& password,
bool use_chromad_kerberos, bool use_chromad_kerberos,
bool should_open_file_manager_after_mount,
MountResponse callback); MountResponse callback);
// Completes the mounting of an SMB file system, passing |options| on to // Completes the mounting of an SMB file system, passing |options| on to
...@@ -71,6 +72,7 @@ class SmbService : public KeyedService, ...@@ -71,6 +72,7 @@ class SmbService : public KeyedService,
const file_system_provider::MountOptions& options, const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
bool is_kerberos_chromad, bool is_kerberos_chromad,
bool should_open_file_manager_after_mount,
smbprovider::ErrorType error, smbprovider::ErrorType error,
int32_t mount_id); int32_t mount_id);
...@@ -89,6 +91,7 @@ class SmbService : public KeyedService, ...@@ -89,6 +91,7 @@ class SmbService : public KeyedService,
const std::string& username, const std::string& username,
const std::string& password, const std::string& password,
bool use_chromad_kerberos, bool use_chromad_kerberos,
bool should_open_file_manager_after_mount,
MountResponse callback); MountResponse callback);
// Calls file_system_provider::Service::UnmountFileSystem(). // Calls file_system_provider::Service::UnmountFileSystem().
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<template is="dom-if" if="[[showAddSmbDialog_]]" restamp> <template is="dom-if" if="[[showAddSmbDialog_]]" restamp>
<add-smb-share-dialog on-close="onAddSmbDialogClosed_" <add-smb-share-dialog on-close="onAddSmbDialogClosed_"
last-url="[[prefs.network_file_shares.most_recently_used_url.value]]" last-url="[[prefs.network_file_shares.most_recently_used_url.value]]"
should-open-file-manager-after-mount
</add-smb-share-dialog> </add-smb-share-dialog>
</template> </template>
</template> </template>
......
...@@ -48,7 +48,7 @@ void SmbHandler::RegisterMessages() { ...@@ -48,7 +48,7 @@ void SmbHandler::RegisterMessages() {
} }
void SmbHandler::HandleSmbMount(const base::ListValue* args) { void SmbHandler::HandleSmbMount(const base::ListValue* args) {
CHECK_EQ(6U, args->GetSize()); CHECK_EQ(7U, args->GetSize());
std::string callback_id; std::string callback_id;
CHECK(args->GetString(0, &callback_id)); CHECK(args->GetString(0, &callback_id));
...@@ -57,11 +57,13 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) { ...@@ -57,11 +57,13 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) {
std::string username; std::string username;
std::string password; std::string password;
bool use_kerberos; bool use_kerberos;
bool should_open_file_manager_after_mount;
CHECK(args->GetString(1, &mount_url)); CHECK(args->GetString(1, &mount_url));
CHECK(args->GetString(2, &mount_name)); CHECK(args->GetString(2, &mount_name));
CHECK(args->GetString(3, &username)); CHECK(args->GetString(3, &username));
CHECK(args->GetString(4, &password)); CHECK(args->GetString(4, &password));
CHECK(args->GetBoolean(5, &use_kerberos)); CHECK(args->GetBoolean(5, &use_kerberos));
CHECK(args->GetBoolean(6, &should_open_file_manager_after_mount));
smb_client::SmbService* const service = GetSmbService(profile_); smb_client::SmbService* const service = GetSmbService(profile_);
if (!service) { if (!service) {
...@@ -75,10 +77,10 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) { ...@@ -75,10 +77,10 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) {
auto mount_response = auto mount_response =
base::BindOnce(&SmbHandler::HandleSmbMountResponse, base::BindOnce(&SmbHandler::HandleSmbMountResponse,
weak_ptr_factory_.GetWeakPtr(), callback_id); weak_ptr_factory_.GetWeakPtr(), callback_id);
auto mount_call = auto mount_call = base::BindOnce(
base::BindOnce(&smb_client::SmbService::Mount, base::Unretained(service), &smb_client::SmbService::Mount, base::Unretained(service), mo,
mo, base::FilePath(mount_url), username, password, base::FilePath(mount_url), username, password, use_kerberos,
use_kerberos, std::move(mount_response)); should_open_file_manager_after_mount, std::move(mount_response));
if (host_discovery_done_) { if (host_discovery_done_) {
std::move(mount_call).Run(); std::move(mount_call).Run();
......
...@@ -12,9 +12,10 @@ class TestSmbBrowserProxy extends TestBrowserProxy { ...@@ -12,9 +12,10 @@ class TestSmbBrowserProxy extends TestBrowserProxy {
} }
/** @override */ /** @override */
smbMount(smbUrl, smbName, username, password, authMethod) { smbMount(smbUrl, smbName, username, password, authMethod, inSettings) {
this.methodCalled( this.methodCalled(
'smbMount', [smbUrl, smbName, username, password, authMethod]); 'smbMount',
[smbUrl, smbName, username, password, authMethod, inSettings]);
return Promise.resolve(SmbMountResult.SUCCESS); return Promise.resolve(SmbMountResult.SUCCESS);
} }
...@@ -74,6 +75,7 @@ suite('AddSmbShareDialogTests', function() { ...@@ -74,6 +75,7 @@ suite('AddSmbShareDialogTests', function() {
const expectedUsername = 'username'; const expectedUsername = 'username';
const expectedPassword = 'password'; const expectedPassword = 'password';
const expectedAuthMethod = 'credentials'; const expectedAuthMethod = 'credentials';
const expectedShouldOpenFileManager = false;
const url = addDialog.$$('#address'); const url = addDialog.$$('#address');
expectTrue(!!url); expectTrue(!!url);
...@@ -95,6 +97,7 @@ suite('AddSmbShareDialogTests', function() { ...@@ -95,6 +97,7 @@ suite('AddSmbShareDialogTests', function() {
expectTrue(!!addButton); expectTrue(!!addButton);
addDialog.authenticationMethod_ = expectedAuthMethod; addDialog.authenticationMethod_ = expectedAuthMethod;
addDialog.shouldOpenFileManagerAfterMount = expectedShouldOpenFileManager;
addButton.click(); addButton.click();
return smbBrowserProxy.whenCalled('smbMount').then(function(args) { return smbBrowserProxy.whenCalled('smbMount').then(function(args) {
...@@ -103,6 +106,7 @@ suite('AddSmbShareDialogTests', function() { ...@@ -103,6 +106,7 @@ suite('AddSmbShareDialogTests', function() {
expectEquals(expectedUsername, args[2]); expectEquals(expectedUsername, args[2]);
expectEquals(expectedPassword, args[3]); expectEquals(expectedPassword, args[3]);
expectEquals(expectedAuthMethod, args[4]); expectEquals(expectedAuthMethod, args[4]);
expectEquals(expectedShouldOpenFileManager, args[5]);
}); });
}); });
......
...@@ -17,6 +17,11 @@ Polymer({ ...@@ -17,6 +17,11 @@ Polymer({
value: '', value: '',
}, },
shouldOpenFileManagerAfterMount: {
type: Boolean,
value: false,
},
/** @private {string} */ /** @private {string} */
mountUrl_: { mountUrl_: {
type: String, type: String,
...@@ -104,7 +109,8 @@ Polymer({ ...@@ -104,7 +109,8 @@ Polymer({
this.browserProxy_ this.browserProxy_
.smbMount( .smbMount(
this.mountUrl_, this.mountName_.trim(), this.username_, this.mountUrl_, this.mountName_.trim(), this.username_,
this.password_, this.authenticationMethod_) this.password_, this.authenticationMethod_,
this.shouldOpenFileManagerAfterMount)
.then(result => { .then(result => {
this.onAddShare_(result); this.onAddShare_(result);
}); });
......
...@@ -44,9 +44,12 @@ cr.define('smb_shares', function() { ...@@ -44,9 +44,12 @@ cr.define('smb_shares', function() {
* @param {string} username * @param {string} username
* @param {string} password * @param {string} password
* @param {string} authMethod * @param {string} authMethod
* @param {boolean} shouldOpenFileManagerAfterMount
* @return {!Promise<SmbMountResult>} * @return {!Promise<SmbMountResult>}
*/ */
smbMount(smbUrl, smbName, username, password, authMethod) {} smbMount(
smbUrl, smbName, username, password, authMethod,
shouldOpenFileManagerAfterMount) {}
/** /**
* Starts the file share discovery process. * Starts the file share discovery process.
...@@ -57,10 +60,13 @@ cr.define('smb_shares', function() { ...@@ -57,10 +60,13 @@ cr.define('smb_shares', function() {
/** @implements {smb_shares.SmbBrowserProxy} */ /** @implements {smb_shares.SmbBrowserProxy} */
class SmbBrowserProxyImpl { class SmbBrowserProxyImpl {
/** @override */ /** @override */
smbMount(smbUrl, smbName, username, password, authMethod) { smbMount(
smbUrl, smbName, username, password, authMethod,
shouldOpenFileManagerAfterMount) {
return cr.sendWithPromise( return cr.sendWithPromise(
'smbMount', smbUrl, smbName, username, password, 'smbMount', smbUrl, smbName, username, password,
authMethod == SmbAuthMethod.KERBEROS); authMethod == SmbAuthMethod.KERBEROS,
shouldOpenFileManagerAfterMount);
} }
/** @override */ /** @override */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment