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

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

Issue 2301713002: Remove some UI->FILE->UI thread hops in ExecuteCodeFunction (Closed)
Patch Set: 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 #include "net/base/filename_util.h"
12 #include "url/gurl.h"
11 13
12 using content::BrowserThread; 14 using content::BrowserThread;
13 15
14 FileReader::FileReader(const extensions::ExtensionResource& resource, 16 FileReader::FileReader(const extensions::ExtensionResource& resource,
15 const Callback& callback) 17 const Callback& callback)
16 : resource_(resource), 18 : resource_(resource),
17 callback_(callback), 19 callback_(callback),
18 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 20 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
19 21
20 void FileReader::Start() { 22 void FileReader::Start() {
21 BrowserThread::PostTask( 23 BrowserThread::PostTask(
22 BrowserThread::FILE, FROM_HERE, 24 BrowserThread::FILE, FROM_HERE,
23 base::Bind(&FileReader::ReadFileOnBackgroundThread, this)); 25 base::Bind(&FileReader::ReadFileOnBackgroundThread, this));
24 } 26 }
25 27
26 FileReader::~FileReader() {} 28 FileReader::~FileReader() {}
27 29
28 void FileReader::ReadFileOnBackgroundThread() { 30 void FileReader::ReadFileOnBackgroundThread() {
29 std::unique_ptr<std::string> data(new std::string()); 31 std::unique_ptr<std::string> data(new std::string());
30 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get()); 32 bool success = base::ReadFileToString(resource_.GetFilePath(), data.get());
33 GURL file_url = net::FilePathToFileURL(resource_.GetFilePath());
31 origin_task_runner_->PostTask( 34 origin_task_runner_->PostTask(
32 FROM_HERE, base::Bind(callback_, success, base::Passed(std::move(data)))); 35 FROM_HERE,
36 base::Bind(callback_, success, file_url, base::Passed(std::move(data))));
33 } 37 }
OLDNEW
« extensions/browser/api/execute_code_function.cc ('K') | « extensions/browser/file_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698