OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/extensions/extension_function.h" | 9 #include "chrome/browser/extensions/extension_function.h" |
10 #include "chrome/browser/extensions/api/api_resource.h" | 10 #include "chrome/browser/extensions/api/api_resource.h" |
11 | 11 |
12 class ExtensionService; | 12 class ExtensionService; |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 class APIResourceController; | 16 class APIResourceController; |
17 class APIResourceEventNotifier; | 17 class APIResourceEventNotifier; |
18 | 18 |
19 // AsyncIOAPIFunction provides convenient thread management for APIs that | 19 // AsyncIOAPIFunction provides convenient thread management for APIs that |
20 // need to do essentially all their work on the IO thread. | 20 // need to do essentially all their work on the IO thread. |
21 class AsyncIOAPIFunction : public AsyncExtensionFunction { | 21 class AsyncIOAPIFunction : public AsyncExtensionFunction { |
22 protected: | 22 protected: |
23 virtual ~AsyncIOAPIFunction() {} | 23 virtual ~AsyncIOAPIFunction() {} |
24 | 24 |
25 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI | 25 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI |
26 // thread. | 26 // thread. |
27 virtual bool Prepare() = 0; | 27 virtual bool Prepare() = 0; |
28 | 28 |
29 // Do actual work. Guaranteed to happen on IO thread. | 29 // Do actual work. Guaranteed to happen on IO thread. |
30 virtual void Work() = 0; | 30 virtual void Work(); |
| 31 |
| 32 // Start the asynchronous work. Guraranteed to happen on IO thread. |
| 33 virtual void AsyncWorkStart(); |
| 34 |
| 35 // Notify AsyncIOAPIFunction that the work is completed |
| 36 void AsyncWorkCompleted(); |
31 | 37 |
32 // Respond. Guaranteed to happen on UI thread. | 38 // Respond. Guaranteed to happen on UI thread. |
33 virtual bool Respond() = 0; | 39 virtual bool Respond() = 0; |
34 | 40 |
35 // Looks for a kSrcId key that might have been added to a create method's | 41 // Looks for a kSrcId key that might have been added to a create method's |
36 // options object. | 42 // options object. |
37 int ExtractSrcId(size_t argument_position); | 43 int ExtractSrcId(size_t argument_position); |
38 | 44 |
39 // Utility. | 45 // Utility. |
40 APIResourceEventNotifier* CreateEventNotifier(int src_id); | 46 APIResourceEventNotifier* CreateEventNotifier(int src_id); |
41 | 47 |
42 // Access to the controller singleton. | 48 // Access to the controller singleton. |
43 APIResourceController* controller(); | 49 APIResourceController* controller(); |
44 | 50 |
45 // ExtensionFunction: | 51 // ExtensionFunction: |
46 virtual bool RunImpl() OVERRIDE; | 52 virtual bool RunImpl() OVERRIDE; |
47 | 53 |
48 private: | 54 private: |
49 void WorkOnIOThread(); | 55 void WorkOnIOThread(); |
50 void RespondOnUIThread(); | 56 void RespondOnUIThread(); |
51 | 57 |
52 ExtensionService* extension_service_; | 58 ExtensionService* extension_service_; |
53 }; | 59 }; |
54 | 60 |
55 } // namespace extensions | 61 } // namespace extensions |
56 | 62 |
57 #endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ | 63 #endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ |
OLD | NEW |