Commit e4663469 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[TaskScheduler] Migrate bookmarks_api to use TaskScheduler.

BookmarksIOFunction used to retrieve default path in FILE
thread. Use a task with traits:
1. MayBlock: Since this requires IO
2. USER_VISIBLE: As this is part of importing/exporting bookmarks.
3. SKIP_ON_SHUTDOWN: There's no point to continue on or block shutdown
  because additional operations are required (e.g. showing a file
  select dialog) for this to complete.

Bug: 689520
Change-Id: Ibed8ea5213ca71f07a47cbb4e2c45cadeb9da429
Reviewed-on: https://chromium-review.googlesource.com/577112
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487976}
parent 2257878a
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task_scheduler/post_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h" #include "chrome/browser/bookmarks/bookmark_html_writer.h"
...@@ -742,37 +743,14 @@ BookmarksIOFunction::~BookmarksIOFunction() { ...@@ -742,37 +743,14 @@ BookmarksIOFunction::~BookmarksIOFunction() {
select_file_dialog_->ListenerDestroyed(); select_file_dialog_->ListenerDestroyed();
} }
void BookmarksIOFunction::SelectFile(ui::SelectFileDialog::Type type) {
// GetDefaultFilepathForBookmarkExport() might have to touch the filesystem
// (stat or access, for example), so this requires a thread with IO allowed.
if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::BindOnce(&BookmarksIOFunction::SelectFile, this, type));
return;
}
// Pre-populating the filename field in case this is a SELECT_SAVEAS_FILE
// dialog. If not, there is no filename field in the dialog box.
base::FilePath default_path;
if (type == ui::SelectFileDialog::SELECT_SAVEAS_FILE)
default_path = GetDefaultFilepathForBookmarkExport();
else
DCHECK(type == ui::SelectFileDialog::SELECT_OPEN_FILE);
// After getting the |default_path|, ask the UI to display the file dialog.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&BookmarksIOFunction::ShowSelectFileDialog, this, type,
default_path));
}
void BookmarksIOFunction::ShowSelectFileDialog( void BookmarksIOFunction::ShowSelectFileDialog(
ui::SelectFileDialog::Type type, ui::SelectFileDialog::Type type,
const base::FilePath& default_path) { const base::FilePath& default_path) {
if (!dispatcher()) if (!dispatcher())
return; // Extension was unloaded. return; // Extension was unloaded.
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Balanced in one of the three callbacks of SelectFileDialog: // Balanced in one of the three callbacks of SelectFileDialog:
// either FileSelectionCanceled, MultiFilesSelected, or FileSelected // either FileSelectionCanceled, MultiFilesSelected, or FileSelected
AddRef(); AddRef();
...@@ -813,7 +791,8 @@ void BookmarksIOFunction::MultiFilesSelected( ...@@ -813,7 +791,8 @@ void BookmarksIOFunction::MultiFilesSelected(
bool BookmarksImportFunction::RunOnReady() { bool BookmarksImportFunction::RunOnReady() {
if (!EditBookmarksEnabled()) if (!EditBookmarksEnabled())
return false; return false;
SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); ShowSelectFileDialog(ui::SelectFileDialog::SELECT_OPEN_FILE,
base::FilePath());
return true; return true;
} }
...@@ -836,7 +815,17 @@ void BookmarksImportFunction::FileSelected(const base::FilePath& path, ...@@ -836,7 +815,17 @@ void BookmarksImportFunction::FileSelected(const base::FilePath& path,
} }
bool BookmarksExportFunction::RunOnReady() { bool BookmarksExportFunction::RunOnReady() {
SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); // "bookmarks.export" is exposed to a small number of extensions. These
// extensions use user gesture for export, so use USER_VISIBLE priority.
// GetDefaultFilepathForBookmarkExport() might have to touch filesystem
// (stat or access, for example), so this requires IO.
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&GetDefaultFilepathForBookmarkExport),
base::BindOnce(&BookmarksIOFunction::ShowSelectFileDialog, this,
ui::SelectFileDialog::SELECT_SAVEAS_FILE));
return true; return true;
} }
......
...@@ -324,17 +324,13 @@ class BookmarksIOFunction : public BookmarksFunction, ...@@ -324,17 +324,13 @@ class BookmarksIOFunction : public BookmarksFunction,
void* params) override; void* params) override;
void FileSelectionCanceled(void* params) override; void FileSelectionCanceled(void* params) override;
void SelectFile(ui::SelectFileDialog::Type type);
protected:
~BookmarksIOFunction() override;
private:
void ShowSelectFileDialog( void ShowSelectFileDialog(
ui::SelectFileDialog::Type type, ui::SelectFileDialog::Type type,
const base::FilePath& default_path); const base::FilePath& default_path);
protected: protected:
~BookmarksIOFunction() override;
scoped_refptr<ui::SelectFileDialog> select_file_dialog_; scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
}; };
......
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