Skip to content

Commit

Permalink
M101: Prevent multiple SelectFileDialog in MediaGalleriesPermissionCo…
Browse files Browse the repository at this point in the history
…ntroller

Similar to crrev.com/c/3546821

(cherry picked from commit 5d50a2d)

Bug: 1309583
Change-Id: I8089d6a1acc44131955e68d895a314270d55c291
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3569405
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#988853}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3581508
Cr-Commit-Position: refs/branch-heads/4951@{#1055}
Cr-Branched-From: 27de622-refs/heads/main@{#982481}
  • Loading branch information
Luciano Pacheco authored and Chromium LUCI CQ committed Apr 26, 2022
1 parent 28e187e commit 3d71de3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -202,6 +202,10 @@ std::u16string MediaGalleriesPermissionController::GetAuxiliaryButtonText()

// This is the 'Add Folder' button.
void MediaGalleriesPermissionController::DidClickAuxiliaryButton() {
// Early return if the select file dialog is already active.
if (select_folder_dialog_)
return;

base::FilePath default_path =
extensions::file_system_api::GetLastChooseEntryDirectory(
extensions::ExtensionPrefs::Get(GetProfile()), extension_->id());
Expand Down Expand Up @@ -275,6 +279,10 @@ content::WebContents* MediaGalleriesPermissionController::WebContents() {
return web_contents_;
}

void MediaGalleriesPermissionController::FileSelectionCanceled(void* params) {
select_folder_dialog_.reset();
}

void MediaGalleriesPermissionController::FileSelected(
const base::FilePath& path,
int /*index*/,
Expand All @@ -301,6 +309,7 @@ void MediaGalleriesPermissionController::FileSelected(
iter->second.selected = true;
forgotten_galleries_.erase(gallery_id);
dialog_->UpdateGalleries();
select_folder_dialog_.reset();
return;
}

Expand All @@ -311,6 +320,7 @@ void MediaGalleriesPermissionController::FileSelected(
iter->second.pref_info.device_id == gallery.device_id) {
iter->second.selected = true;
dialog_->UpdateGalleries();
select_folder_dialog_.reset();
return;
}
}
Expand All @@ -320,6 +330,7 @@ void MediaGalleriesPermissionController::FileSelected(
// The old prefId is retained for blocklisted galleries.
gallery.pref_id = GetDialogId(gallery.pref_id);
new_galleries_[gallery.pref_id] = Entry(gallery, true);
select_folder_dialog_.reset();
dialog_->UpdateGalleries();
}

Expand Down
Expand Up @@ -123,6 +123,7 @@ class MediaGalleriesPermissionController
void FileSelected(const base::FilePath& path,
int index,
void* params) override;
void FileSelectionCanceled(void* params) override;

// RemovableStorageObserver implementation.
// Used to keep dialog in sync with removable device status.
Expand Down

0 comments on commit 3d71de3

Please sign in to comment.