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

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

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/extensions/file_reader.h" 5 #include "chrome/browser/extensions/file_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "chrome/browser/chrome_thread.h" 8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/common/extensions/extension_resource.h" 9 #include "chrome/common/extensions/extension_resource.h"
10 10
11 FileReader::FileReader(const ExtensionResource& resource, Callback* callback) 11 FileReader::FileReader(const ExtensionResource& resource, Callback* callback)
12 : resource_(resource), 12 : resource_(resource),
13 callback_(callback), 13 callback_(callback),
14 origin_loop_(MessageLoop::current()) { 14 origin_loop_(MessageLoop::current()) {
15 DCHECK(callback_); 15 DCHECK(callback_);
16 } 16 }
17 17
18 void FileReader::Start() { 18 void FileReader::Start() {
19 ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(FROM_HERE, 19 ChromeThread::PostTask(
20 ChromeThread::FILE, FROM_HERE,
20 NewRunnableMethod(this, &FileReader::ReadFileOnBackgroundThread)); 21 NewRunnableMethod(this, &FileReader::ReadFileOnBackgroundThread));
21 } 22 }
22 23
23 void FileReader::ReadFileOnBackgroundThread() { 24 void FileReader::ReadFileOnBackgroundThread() {
24 std::string data; 25 std::string data;
25 bool success = file_util::ReadFileToString(resource_.GetFilePath(), &data); 26 bool success = file_util::ReadFileToString(resource_.GetFilePath(), &data);
26 origin_loop_->PostTask(FROM_HERE, NewRunnableMethod( 27 origin_loop_->PostTask(FROM_HERE, NewRunnableMethod(
27 this, &FileReader::RunCallback, success, data)); 28 this, &FileReader::RunCallback, success, data));
28 } 29 }
29 30
30 void FileReader::RunCallback(bool success, const std::string& data) { 31 void FileReader::RunCallback(bool success, const std::string& data) {
31 callback_->Run(success, data); 32 callback_->Run(success, data);
32 delete callback_; 33 delete callback_;
33 } 34 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698