| OLD | NEW |
| 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/message_loop/message_loop.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 12 | 11 |
| 13 using content::BrowserThread; | 12 using content::BrowserThread; |
| 14 | 13 |
| 15 FileReader::FileReader(const extensions::ExtensionResource& resource, | 14 FileReader::FileReader(const extensions::ExtensionResource& resource, |
| 16 const Callback& callback) | 15 const Callback& callback) |
| 17 : resource_(resource), | 16 : resource_(resource), |
| 18 callback_(callback), | 17 callback_(callback), |
| 19 origin_loop_(base::MessageLoop::current()) {} | 18 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 20 | 19 |
| 21 void FileReader::Start() { | 20 void FileReader::Start() { |
| 22 BrowserThread::PostTask( | 21 BrowserThread::PostTask( |
| 23 BrowserThread::FILE, FROM_HERE, | 22 BrowserThread::FILE, FROM_HERE, |
| 24 base::Bind(&FileReader::ReadFileOnBackgroundThread, this)); | 23 base::Bind(&FileReader::ReadFileOnBackgroundThread, this)); |
| 25 } | 24 } |
| 26 | 25 |
| 27 FileReader::~FileReader() {} | 26 FileReader::~FileReader() {} |
| 28 | 27 |
| 29 void FileReader::ReadFileOnBackgroundThread() { | 28 void FileReader::ReadFileOnBackgroundThread() { |
| 30 std::string data; | 29 std::string data; |
| 31 bool success = base::ReadFileToString(resource_.GetFilePath(), &data); | 30 bool success = base::ReadFileToString(resource_.GetFilePath(), &data); |
| 32 origin_loop_->task_runner()->PostTask(FROM_HERE, | 31 origin_task_runner_->PostTask(FROM_HERE, |
| 33 base::Bind(callback_, success, data)); | 32 base::Bind(callback_, success, data)); |
| 34 } | 33 } |
| OLD | NEW |