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

Side by Side Diff: extensions/browser/file_reader.cc

Issue 2301713002: Remove some UI->FILE->UI thread hops in ExecuteCodeFunction (Closed)
Patch Set: git cl format 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
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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 11
12 using content::BrowserThread; 12 using content::BrowserThread;
13 13
14 FileReader::FileReader(const extensions::ExtensionResource& resource, 14 FileReader::FileReader(
15 const Callback& callback) 15 const extensions::ExtensionResource& resource,
16 const OptionalFileThreadTaskCallback& optional_file_thread_task_callback,
17 const DoneCallback& done_callback)
16 : resource_(resource), 18 : resource_(resource),
17 callback_(callback), 19 optional_file_thread_task_callback_(optional_file_thread_task_callback),
20 done_callback_(done_callback),
18 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 21 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
19 22
20 void FileReader::Start() { 23 void FileReader::Start() {
21 BrowserThread::PostTask( 24 BrowserThread::PostTask(
22 BrowserThread::FILE, FROM_HERE, 25 BrowserThread::FILE, FROM_HERE,
23 base::Bind(&FileReader::ReadFileOnBackgroundThread, this)); 26 base::Bind(&FileReader::ReadFileOnBackgroundThread, this));
24 } 27 }
25 28
26 FileReader::~FileReader() {} 29 FileReader::~FileReader() {}
27 30
28 void FileReader::ReadFileOnBackgroundThread() { 31 void FileReader::ReadFileOnBackgroundThread() {
29 std::unique_ptr<std::string> data(new std::string()); 32 std::unique_ptr<std::string> data(new std::string());
30 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get()); 33 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get());
34
35 if (success && !optional_file_thread_task_callback_.is_null())
36 optional_file_thread_task_callback_.Run(data.get());
37
31 origin_task_runner_->PostTask( 38 origin_task_runner_->PostTask(
32 FROM_HERE, base::Bind(callback_, success, base::Passed(std::move(data)))); 39 FROM_HERE,
40 base::Bind(done_callback_, success, base::Passed(std::move(data))));
Devlin 2016/09/01 06:15:21 Totally separate, but let's make these (here and l
lazyboy 2016/09/01 18:10:18 As discussed on chat, there shouldn't be a leak as
33 } 41 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698