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 // This file defines an interface for reading a file asynchronously on a | |
6 // background thread. | |
7 | |
8 #ifndef CHROME_BROWSER_NET_FILE_READER_H_ | |
9 #define CHROME_BROWSER_NET_FILE_READER_H_ | |
10 | |
11 #include <string> | |
12 | |
13 #include "base/file_path.h" | |
14 #include "base/ref_counted.h" | |
15 #include "base/task.h" | |
16 | |
17 class MessageLoop; | |
18 | |
19 class FileReader : public base::RefCountedThreadSafe<FileReader> { | |
20 public: | |
21 // Reports success or failure and the data of the file upon success. | |
22 typedef Callback2<bool, const std::string&>::Type Callback; | |
23 | |
24 FileReader(const FilePath& path, Callback* callback); | |
25 | |
26 // Called to start reading the file on a background thread. Upon completion, | |
27 // the callback will be notified of the results. | |
28 void Start(); | |
29 | |
30 private: | |
31 void ReadFileOnBackgroundThread(); | |
32 void RunCallback(bool success, const std::string& data); | |
33 | |
34 FilePath path_; | |
35 Callback* callback_; | |
36 MessageLoop* origin_loop_; | |
37 }; | |
38 | |
39 #endif // CHROME_BROWSER_NET_FILE_READER_H_ | |
OLD | NEW |