[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 4 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_FILE_READER_H_ |
6 | #define EXTENSIONS_BROWSER_FILE_READER_H_ | ||||
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | |||||
[email protected] | 1ec27eb5 | 2011-11-03 21:59:09 | [diff] [blame] | 10 | #include "base/callback.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 12 | #include "extensions/common/extension_resource.h" |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 13 | |
[email protected] | 5e9e96a | 2013-03-31 02:29:20 | [diff] [blame] | 14 | namespace base { |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 15 | class MessageLoop; |
[email protected] | 5e9e96a | 2013-03-31 02:29:20 | [diff] [blame] | 16 | } |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 17 | |
[email protected] | ecabe6ee | 2009-10-07 22:49:10 | [diff] [blame] | 18 | // This file defines an interface for reading a file asynchronously on a |
19 | // background thread. | ||||
20 | // Consider abstracting out a FilePathProvider (ExtensionResource) and moving | ||||
21 | // back to chrome/browser/net if other subsystems want to use it. | ||||
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 22 | class FileReader : public base::RefCountedThreadSafe<FileReader> { |
23 | public: | ||||
24 | // Reports success or failure and the data of the file upon success. | ||||
[email protected] | 1ec27eb5 | 2011-11-03 21:59:09 | [diff] [blame] | 25 | typedef base::Callback<void(bool, const std::string&)> Callback; |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 26 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 27 | FileReader(const extensions::ExtensionResource& resource, |
28 | const Callback& callback); | ||||
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 29 | |
30 | // Called to start reading the file on a background thread. Upon completion, | ||||
31 | // the callback will be notified of the results. | ||||
32 | void Start(); | ||||
33 | |||||
34 | private: | ||||
[email protected] | 8de85a6 | 2009-11-06 08:32:17 | [diff] [blame] | 35 | friend class base::RefCountedThreadSafe<FileReader>; |
36 | |||||
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 37 | virtual ~FileReader(); |
[email protected] | 8de85a6 | 2009-11-06 08:32:17 | [diff] [blame] | 38 | |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 39 | void ReadFileOnBackgroundThread(); |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 40 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 41 | extensions::ExtensionResource resource_; |
[email protected] | 1ec27eb5 | 2011-11-03 21:59:09 | [diff] [blame] | 42 | Callback callback_; |
[email protected] | 5e9e96a | 2013-03-31 02:29:20 | [diff] [blame] | 43 | base::MessageLoop* origin_loop_; |
[email protected] | 1683aedf | 2009-09-29 23:06:13 | [diff] [blame] | 44 | }; |
45 | |||||
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 46 | #endif // EXTENSIONS_BROWSER_FILE_READER_H_ |