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 #ifndef EXTENSIONS_BROWSER_FILE_READER_H_ | 5 #ifndef EXTENSIONS_BROWSER_FILE_READER_H_ |
6 #define EXTENSIONS_BROWSER_FILE_READER_H_ | 6 #define EXTENSIONS_BROWSER_FILE_READER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "extensions/common/extension_resource.h" | 13 #include "extensions/common/extension_resource.h" |
14 | 14 |
15 // This file defines an interface for reading a file asynchronously on a | 15 // This file defines an interface for reading a file asynchronously on a |
16 // background thread. | 16 // background thread. |
17 // Consider abstracting out a FilePathProvider (ExtensionResource) and moving | 17 // Consider abstracting out a FilePathProvider (ExtensionResource) and moving |
18 // back to chrome/browser/net if other subsystems want to use it. | 18 // back to chrome/browser/net if other subsystems want to use it. |
19 class FileReader : public base::RefCountedThreadSafe<FileReader> { | 19 class FileReader : public base::RefCountedThreadSafe<FileReader> { |
20 public: | 20 public: |
21 // Reports success or failure and the data of the file upon success. | 21 // Reports success or failure and the data of the file upon success. |
22 typedef base::Callback<void(bool, std::unique_ptr<std::string>)> Callback; | 22 using DoneCallback = base::Callback<void(bool, std::unique_ptr<std::string>)>; |
23 // Lets the caller accomplish tasks on the file data, after the file content | |
24 // has been read. | |
25 // If the file reading doesn't succeed, this will be ignored. | |
Devlin
2016/09/01 04:21:25
This makes sense to me, but the code seems to disa
lazyboy
2016/09/01 05:52:58
See comment in execute_code_function.cc
| |
26 using OptionalFileThreadTaskCallback = | |
27 base::Callback<void(bool, std::string*)>; | |
23 | 28 |
24 FileReader(const extensions::ExtensionResource& resource, | 29 FileReader(const extensions::ExtensionResource& resource, |
25 const Callback& callback); | 30 const OptionalFileThreadTaskCallback& file_thread_task_callback, |
31 const DoneCallback& done_callback); | |
26 | 32 |
27 // Called to start reading the file on a background thread. Upon completion, | 33 // Called to start reading the file on a background thread. Upon completion, |
28 // the callback will be notified of the results. | 34 // the callback will be notified of the results. |
29 void Start(); | 35 void Start(); |
30 | 36 |
31 private: | 37 private: |
32 friend class base::RefCountedThreadSafe<FileReader>; | 38 friend class base::RefCountedThreadSafe<FileReader>; |
33 | 39 |
34 virtual ~FileReader(); | 40 virtual ~FileReader(); |
35 | 41 |
36 void ReadFileOnBackgroundThread(); | 42 void ReadFileOnBackgroundThread(); |
37 | 43 |
38 extensions::ExtensionResource resource_; | 44 extensions::ExtensionResource resource_; |
39 Callback callback_; | 45 OptionalFileThreadTaskCallback optional_file_thread_task_callback_; |
46 DoneCallback done_callback_; | |
40 const scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; | 47 const scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
41 }; | 48 }; |
42 | 49 |
43 #endif // EXTENSIONS_BROWSER_FILE_READER_H_ | 50 #endif // EXTENSIONS_BROWSER_FILE_READER_H_ |
OLD | NEW |