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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/file_reader.h" 5 #include "extensions/browser/file_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
9 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 12
12 using content::BrowserThread; 13 using content::BrowserThread;
13 14
14 FileReader::FileReader(const extensions::ExtensionResource& resource, 15 FileReader::FileReader(
15 const Callback& callback) 16 const extensions::ExtensionResource& resource,
17 const OptionalFileThreadTaskCallback& optional_file_thread_task_callback,
18 const DoneCallback& done_callback)
16 : resource_(resource), 19 : resource_(resource),
17 callback_(callback), 20 optional_file_thread_task_callback_(optional_file_thread_task_callback),
21 done_callback_(done_callback),
18 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 22 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
19 23
20 void FileReader::Start() { 24 void FileReader::Start() {
21 BrowserThread::PostTask( 25 BrowserThread::PostTask(
22 BrowserThread::FILE, FROM_HERE, 26 BrowserThread::FILE, FROM_HERE,
23 base::Bind(&FileReader::ReadFileOnBackgroundThread, this)); 27 base::Bind(&FileReader::ReadFileOnBackgroundThread, this));
24 } 28 }
25 29
26 FileReader::~FileReader() {} 30 FileReader::~FileReader() {}
27 31
28 void FileReader::ReadFileOnBackgroundThread() { 32 void FileReader::ReadFileOnBackgroundThread() {
29 std::unique_ptr<std::string> data(new std::string()); 33 std::unique_ptr<std::string> data(new std::string());
30 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get()); 34 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get());
35
36 if (!optional_file_thread_task_callback_.is_null()) {
37 if (success) {
38 base::ResetAndReturn(&optional_file_thread_task_callback_)
39 .Run(data.get());
40 } else {
41 optional_file_thread_task_callback_.Reset();
42 }
43 }
44
31 origin_task_runner_->PostTask( 45 origin_task_runner_->PostTask(
32 FROM_HERE, base::Bind(callback_, success, base::Passed(std::move(data)))); 46 FROM_HERE, base::Bind(base::ResetAndReturn(&done_callback_), success,
47 base::Passed(std::move(data))));
33 } 48 }
OLDNEW
« 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