| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/net/file_reader.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "chrome/browser/chrome_thread.h" | |
| 9 | |
| 10 FileReader::FileReader(const FilePath& path, Callback* callback) | |
| 11 : path_(path), | |
| 12 callback_(callback), | |
| 13 origin_loop_(MessageLoop::current()) { | |
| 14 DCHECK(callback_); | |
| 15 } | |
| 16 | |
| 17 void FileReader::Start() { | |
| 18 ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(FROM_HERE, | |
| 19 NewRunnableMethod(this, &FileReader::ReadFileOnBackgroundThread)); | |
| 20 } | |
| 21 | |
| 22 void FileReader::ReadFileOnBackgroundThread() { | |
| 23 std::string data; | |
| 24 bool success = file_util::ReadFileToString(path_, &data); | |
| 25 origin_loop_->PostTask(FROM_HERE, NewRunnableMethod( | |
| 26 this, &FileReader::RunCallback, success, data)); | |
| 27 } | |
| 28 | |
| 29 void FileReader::RunCallback(bool success, const std::string& data) { | |
| 30 callback_->Run(success, data); | |
| 31 delete callback_; | |
| 32 } | |
| OLD | NEW |