Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: extensions/browser/file_reader.cc

Issue 2301713002: Remove some UI->FILE->UI thread hops in ExecuteCodeFunction (Closed)
Patch Set: sync, move changes from accessibility_manager.cc -> accessibility_extension_loader.cc Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/file_reader.h ('k') | extensions/browser/file_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/file_reader.cc
diff --git a/extensions/browser/file_reader.cc b/extensions/browser/file_reader.cc
index c5deb9b646e071cc844cceb9ec57922b35afab31..3efc7d51a27e7c8728e23cc46d7cbe8816728013 100644
--- a/extensions/browser/file_reader.cc
+++ b/extensions/browser/file_reader.cc
@@ -5,16 +5,20 @@
#include "extensions/browser/file_reader.h"
#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
-FileReader::FileReader(const extensions::ExtensionResource& resource,
- const Callback& callback)
+FileReader::FileReader(
+ const extensions::ExtensionResource& resource,
+ const OptionalFileThreadTaskCallback& optional_file_thread_task_callback,
+ const DoneCallback& done_callback)
: resource_(resource),
- callback_(callback),
+ optional_file_thread_task_callback_(optional_file_thread_task_callback),
+ done_callback_(done_callback),
origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
void FileReader::Start() {
@@ -28,6 +32,17 @@ FileReader::~FileReader() {}
void FileReader::ReadFileOnBackgroundThread() {
std::unique_ptr<std::string> data(new std::string());
bool success = base::ReadFileToString(resource_.GetFilePath(), data.get());
+
+ if (!optional_file_thread_task_callback_.is_null()) {
+ if (success) {
+ base::ResetAndReturn(&optional_file_thread_task_callback_)
+ .Run(data.get());
+ } else {
+ optional_file_thread_task_callback_.Reset();
+ }
+ }
+
origin_task_runner_->PostTask(
- FROM_HERE, base::Bind(callback_, success, base::Passed(std::move(data))));
+ FROM_HERE, base::Bind(base::ResetAndReturn(&done_callback_), success,
+ base::Passed(std::move(data))));
}
« no previous file with comments | « extensions/browser/file_reader.h ('k') | extensions/browser/file_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698