Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/extensions/api/api_function.h

Issue 10777003: Refactor APIResourceController to ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge/antony/fix build. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/api_function.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
8 #include "chrome/browser/extensions/extension_function.h" 8 #include "chrome/browser/extensions/extension_function.h"
9 #include "chrome/browser/extensions/api/api_resource.h"
10 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
11 10
12 class ExtensionService;
13
14 namespace extensions { 11 namespace extensions {
15 12
16 class APIResourceController; 13 class ApiResourceEventNotifier;
17 class APIResourceEventNotifier;
18 14
19 // AsyncAPIFunction provides convenient thread management for APIs that need to 15 // AsyncApiFunction provides convenient thread management for APIs that need to
20 // do essentially all their work on a thread other than the UI thread. 16 // do essentially all their work on a thread other than the UI thread.
21 class AsyncAPIFunction : public AsyncExtensionFunction { 17 class AsyncApiFunction : public AsyncExtensionFunction {
22 protected: 18 protected:
23 AsyncAPIFunction(); 19 AsyncApiFunction();
24 virtual ~AsyncAPIFunction() {} 20 virtual ~AsyncApiFunction() {}
21
22 // Like Prepare(). A useful place to put common work in an ApiFunction
23 // superclass that multiple API functions want to share.
24 virtual bool PrePrepare();
25 25
26 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI 26 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI
27 // thread. 27 // thread.
28 virtual bool Prepare() = 0; 28 virtual bool Prepare() = 0;
29 29
30 // Do actual work. Guaranteed to happen on the thread specified in 30 // Do actual work. Guaranteed to happen on the thread specified in
31 // work_thread_id_. 31 // work_thread_id_.
32 virtual void Work(); 32 virtual void Work();
33 33
34 // Start the asynchronous work. Guraranteed to happen on requested thread. 34 // Start the asynchronous work. Guraranteed to happen on requested thread.
35 virtual void AsyncWorkStart(); 35 virtual void AsyncWorkStart();
36 36
37 // Notify AsyncIOAPIFunction that the work is completed 37 // Notify AsyncIOApiFunction that the work is completed
38 void AsyncWorkCompleted(); 38 void AsyncWorkCompleted();
39 39
40 // Respond. Guaranteed to happen on UI thread. 40 // Respond. Guaranteed to happen on UI thread.
41 virtual bool Respond() = 0; 41 virtual bool Respond() = 0;
42 42
43 // Looks for a kSrcId key that might have been added to a create method's 43 // Looks for a kSrcId key that might have been added to a create method's
44 // options object. 44 // options object.
45 int ExtractSrcId(const DictionaryValue* options); 45 int ExtractSrcId(const DictionaryValue* options);
46 46
47 // Deprecated. If you're still using this method, you should be converting 47 // Deprecated. If you're still using this method, you should be converting
48 // your calling code to the new-style argument-parsing code, which won't work 48 // your calling code to the new-style argument-parsing code, which won't work
49 // with this method. See the version that takes an options dictionary 49 // with this method. See the version that takes an options dictionary
50 // instead (above). 50 // instead (above).
51 int DeprecatedExtractSrcId(size_t argument_position); 51 int DeprecatedExtractSrcId(size_t argument_position);
52 52
53 // Utility. 53 // Utility.
54 APIResourceEventNotifier* CreateEventNotifier(int src_id); 54 ApiResourceEventNotifier* CreateEventNotifier(int src_id);
55
56 // Access to the controller singleton.
57 APIResourceController* controller();
58 55
59 // ExtensionFunction::RunImpl() 56 // ExtensionFunction::RunImpl()
60 virtual bool RunImpl() OVERRIDE; 57 virtual bool RunImpl() OVERRIDE;
61 58
62 protected: 59 protected:
63 void set_work_thread_id(content::BrowserThread::ID work_thread_id) { 60 void set_work_thread_id(content::BrowserThread::ID work_thread_id) {
64 work_thread_id_ = work_thread_id; 61 work_thread_id_ = work_thread_id;
65 } 62 }
66 63
67 private: 64 private:
68 void WorkOnWorkThread(); 65 void WorkOnWorkThread();
69 void RespondOnUIThread(); 66 void RespondOnUIThread();
70 67
71 // If you don't want your Work() method to happen on the IO thread, then set 68 // If you don't want your Work() method to happen on the IO thread, then set
72 // this to the thread that you do want, preferably in Prepare(). 69 // this to the thread that you do want, preferably in Prepare().
73 content::BrowserThread::ID work_thread_id_; 70 content::BrowserThread::ID work_thread_id_;
74
75 ExtensionService* extension_service_;
76 }; 71 };
77 72
78 } // namespace extensions 73 } // namespace extensions
79 74
80 #endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ 75 #endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/api_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698