Commit fe5af597 authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Allow one instance of SmbCredentialDialog for each mount ID

- This change prevents more than one instance of a UpdateCredential
  dialog for a single mount.
- Each mount, when prompted, will have their own dialog to update
  credentials.
- Previously, it was possible to have multiple dialogs and would crash
  the File App. The cause of the crash is after successfully updating
  the credentials of the share via the first dialog, the second dialog
  is no longer in a stable state and holds stale callbacks.

Bug: 931846
Test: end to end manual test
Change-Id: I09f85c084028943bceed3831e81cefce503f2bb7
Reviewed-on: https://chromium-review.googlesource.com/c/1470726
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634704}
parent 0a85d5fa
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/chromeos/smb_shares/smb_credentials_dialog.h" #include "chrome/browser/ui/webui/chromeos/smb_shares/smb_credentials_dialog.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.h" #include "chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
...@@ -35,18 +36,30 @@ void AddSmbCredentialsDialogStrings(content::WebUIDataSource* html_source) { ...@@ -35,18 +36,30 @@ void AddSmbCredentialsDialogStrings(content::WebUIDataSource* html_source) {
} }
} }
std::string GetDialogId(int32_t mount_id) {
return chrome::kChromeUISmbCredentialsURL + base::NumberToString(mount_id);
}
} // namespace } // namespace
// static // static
void SmbCredentialsDialog::Show(int32_t mount_id, void SmbCredentialsDialog::Show(int32_t mount_id,
const std::string& share_path) { const std::string& share_path) {
// If an SmbCredentialsDialog is already opened for |mount_id|, focus that
// dialog rather than opening a second one.
auto* instance = SystemWebDialogDelegate::FindInstance(GetDialogId(mount_id));
if (instance) {
instance->Focus();
return;
}
SmbCredentialsDialog* dialog = new SmbCredentialsDialog(mount_id, share_path); SmbCredentialsDialog* dialog = new SmbCredentialsDialog(mount_id, share_path);
dialog->ShowSystemDialog(); dialog->ShowSystemDialog();
} }
SmbCredentialsDialog::SmbCredentialsDialog(int32_t mount_id, SmbCredentialsDialog::SmbCredentialsDialog(int32_t mount_id,
const std::string& share_path) const std::string& share_path)
: SystemWebDialogDelegate(GURL(chrome::kChromeUISmbCredentialsURL), : SystemWebDialogDelegate(GURL(GetDialogId(mount_id)),
base::string16() /* title */), base::string16() /* title */),
mount_id_(mount_id), mount_id_(mount_id),
share_path_(share_path) {} share_path_(share_path) {}
......
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