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

Side by Side Diff: extensions/browser/api/runtime/runtime_api.h

Issue 264743014: Move chrome.runtime to //extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make clang, cros happy Created 6 years, 7 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
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_RUNTIME_RUNTIME_API_H_ 5 #ifndef EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ 6 #define EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/extensions/chrome_extension_function.h"
11 #include "chrome/common/extensions/api/runtime.h"
12 #include "content/public/browser/notification_observer.h" 10 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 11 #include "content/public/browser/notification_registrar.h"
12 #include "extensions/browser/api/runtime/runtime_api_delegate.h"
14 #include "extensions/browser/browser_context_keyed_api_factory.h" 13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h"
15 #include "extensions/browser/process_manager_observer.h" 15 #include "extensions/browser/process_manager_observer.h"
16 #include "extensions/browser/update_observer.h" 16 #include "extensions/browser/update_observer.h"
17 17 #include "extensions/common/api/runtime.h"
18 class Profile;
19 18
20 namespace base { 19 namespace base {
21 class Version; 20 class Version;
22 } 21 }
23 22
24 namespace content { 23 namespace content {
25 class BrowserContext; 24 class BrowserContext;
26 } 25 }
27 26
28 namespace extensions { 27 namespace extensions {
(...skipping 11 matching lines...) Expand all
40 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance(); 39 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance();
41 40
42 explicit RuntimeAPI(content::BrowserContext* context); 41 explicit RuntimeAPI(content::BrowserContext* context);
43 virtual ~RuntimeAPI(); 42 virtual ~RuntimeAPI();
44 43
45 // content::NotificationObserver overrides: 44 // content::NotificationObserver overrides:
46 virtual void Observe(int type, 45 virtual void Observe(int type,
47 const content::NotificationSource& source, 46 const content::NotificationSource& source,
48 const content::NotificationDetails& details) OVERRIDE; 47 const content::NotificationDetails& details) OVERRIDE;
49 48
50 void MaybeReloadExtension(const std::string& extension_id); 49 void ReloadExtension(const std::string& extension_id);
50 bool CheckForUpdates(const std::string& extension_id,
51 const RuntimeAPIDelegate::UpdateCheckCallback& callback);
52 void OpenURL(const GURL& uninstall_url);
53 bool GetPlatformInfo(
54 core_api::runtime::GetPlatformInfo::Results::PlatformInfo* info);
55 bool RestartDevice(std::string* error_message);
51 56
52 private: 57 private:
53 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; 58 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>;
54 59
55 void OnExtensionsReady(); 60 void OnExtensionsReady();
56 void OnExtensionLoaded(const Extension* extension); 61 void OnExtensionLoaded(const Extension* extension);
57 void OnExtensionInstalled(const Extension* extension); 62 void OnExtensionInstalled(const Extension* extension);
58 void OnExtensionUninstalled(const Extension* extension); 63 void OnExtensionUninstalled(const Extension* extension);
59 64
60 // BrowserContextKeyedAPI implementation: 65 // BrowserContextKeyedAPI implementation:
61 static const char* service_name() { return "RuntimeAPI"; } 66 static const char* service_name() { return "RuntimeAPI"; }
62 static const bool kServiceRedirectedInIncognito = true; 67 static const bool kServiceRedirectedInIncognito = true;
63 static const bool kServiceIsNULLWhileTesting = true; 68 static const bool kServiceIsNULLWhileTesting = true;
64 virtual void Shutdown() OVERRIDE; 69 virtual void Shutdown() OVERRIDE;
65 70
66 // extensions::UpdateObserver overrides: 71 // extensions::UpdateObserver overrides:
67 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE; 72 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE;
68 virtual void OnChromeUpdateAvailable() OVERRIDE; 73 virtual void OnChromeUpdateAvailable() OVERRIDE;
69 74
70 // ProcessManagerObserver implementation: 75 // ProcessManagerObserver implementation:
71 virtual void OnBackgroundHostStartup(const Extension* extension) OVERRIDE; 76 virtual void OnBackgroundHostStartup(const Extension* extension) OVERRIDE;
72 77
78 scoped_ptr<RuntimeAPIDelegate> delegate_;
79
73 content::BrowserContext* browser_context_; 80 content::BrowserContext* browser_context_;
74 81
75 // True if we should dispatch the chrome.runtime.onInstalled event with 82 // True if we should dispatch the chrome.runtime.onInstalled event with
76 // reason "chrome_update" upon loading each extension. 83 // reason "chrome_update" upon loading each extension.
77 bool dispatch_chrome_updated_event_; 84 bool dispatch_chrome_updated_event_;
78 85
79 // Whether the API registered with the ExtensionService to receive
80 // update notifications.
81 bool registered_for_updates_;
82
83 content::NotificationRegistrar registrar_; 86 content::NotificationRegistrar registrar_;
84 87
85 // Map to prevent extensions from getting stuck in reload loops. Maps
86 // extension id to the last time it was reloaded and the number of times
87 // it was reloaded with not enough time in between reloads.
88 std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_;
89
90 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); 88 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
91 }; 89 };
92 90
93 class RuntimeEventRouter { 91 class RuntimeEventRouter {
94 public: 92 public:
95 // Dispatches the onStartup event to all currently-loaded extensions. 93 // Dispatches the onStartup event to all currently-loaded extensions.
96 static void DispatchOnStartupEvent(content::BrowserContext* context, 94 static void DispatchOnStartupEvent(content::BrowserContext* context,
97 const std::string& extension_id); 95 const std::string& extension_id);
98 96
99 // Dispatches the onInstalled event to the given extension. 97 // Dispatches the onInstalled event to the given extension.
100 static void DispatchOnInstalledEvent(content::BrowserContext* context, 98 static void DispatchOnInstalledEvent(content::BrowserContext* context,
101 const std::string& extension_id, 99 const std::string& extension_id,
102 const base::Version& old_version, 100 const base::Version& old_version,
103 bool chrome_updated); 101 bool chrome_updated);
104 102
105 // Dispatches the onUpdateAvailable event to the given extension. 103 // Dispatches the onUpdateAvailable event to the given extension.
106 static void DispatchOnUpdateAvailableEvent( 104 static void DispatchOnUpdateAvailableEvent(
107 Profile* profile, 105 content::BrowserContext* context,
108 const std::string& extension_id, 106 const std::string& extension_id,
109 const base::DictionaryValue* manifest); 107 const base::DictionaryValue* manifest);
110 108
111 // Dispatches the onBrowserUpdateAvailable event to all extensions. 109 // Dispatches the onBrowserUpdateAvailable event to all extensions.
112 static void DispatchOnBrowserUpdateAvailableEvent(Profile* profile); 110 static void DispatchOnBrowserUpdateAvailableEvent(
111 content::BrowserContext* context);
113 112
114 // Dispatches the onRestartRequired event to the given app. 113 // Dispatches the onRestartRequired event to the given app.
115 static void DispatchOnRestartRequiredEvent( 114 static void DispatchOnRestartRequiredEvent(
116 Profile* profile, 115 content::BrowserContext* context,
117 const std::string& app_id, 116 const std::string& app_id,
118 api::runtime::OnRestartRequired::Reason reason); 117 core_api::runtime::OnRestartRequired::Reason reason);
119 118
120 // Does any work needed at extension uninstall (e.g. load uninstall url). 119 // Does any work needed at extension uninstall (e.g. load uninstall url).
121 static void OnExtensionUninstalled(Profile* profile, 120 static void OnExtensionUninstalled(content::BrowserContext* context,
122 const std::string& extension_id); 121 const std::string& extension_id);
123 }; 122 };
124 123
125 class RuntimeGetBackgroundPageFunction : public ChromeAsyncExtensionFunction { 124 class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction {
126 public: 125 public:
127 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", 126 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage",
128 RUNTIME_GETBACKGROUNDPAGE) 127 RUNTIME_GETBACKGROUNDPAGE)
129 128
130 protected: 129 protected:
131 virtual ~RuntimeGetBackgroundPageFunction() {} 130 virtual ~RuntimeGetBackgroundPageFunction() {}
132 virtual bool RunAsync() OVERRIDE; 131 virtual ResponseAction Run() OVERRIDE;
133 132
134 private: 133 private:
135 void OnPageLoaded(ExtensionHost*); 134 void OnPageLoaded(ExtensionHost*);
136 }; 135 };
137 136
138 class RuntimeSetUninstallURLFunction : public ChromeSyncExtensionFunction { 137 class RuntimeSetUninstallURLFunction : public UIThreadExtensionFunction {
139 public: 138 public:
140 DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL", 139 DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL", RUNTIME_SETUNINSTALLURL)
141 RUNTIME_SETUNINSTALLURL)
142 140
143 protected: 141 protected:
144 virtual ~RuntimeSetUninstallURLFunction() {} 142 virtual ~RuntimeSetUninstallURLFunction() {}
145 virtual bool RunSync() OVERRIDE; 143 virtual ResponseAction Run() OVERRIDE;
146 }; 144 };
147 145
148 class RuntimeReloadFunction : public ChromeSyncExtensionFunction { 146 class RuntimeReloadFunction : public UIThreadExtensionFunction {
149 public: 147 public:
150 DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD) 148 DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD)
151 149
152 protected: 150 protected:
153 virtual ~RuntimeReloadFunction() {} 151 virtual ~RuntimeReloadFunction() {}
154 virtual bool RunSync() OVERRIDE; 152 virtual ResponseAction Run() OVERRIDE;
155 }; 153 };
156 154
157 class RuntimeRequestUpdateCheckFunction : public ChromeAsyncExtensionFunction, 155 class RuntimeRequestUpdateCheckFunction : public UIThreadExtensionFunction {
158 public content::NotificationObserver {
159 public: 156 public:
160 DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck", 157 DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck",
161 RUNTIME_REQUESTUPDATECHECK) 158 RUNTIME_REQUESTUPDATECHECK)
162 159
163 RuntimeRequestUpdateCheckFunction();
164 protected: 160 protected:
165 virtual ~RuntimeRequestUpdateCheckFunction() {} 161 virtual ~RuntimeRequestUpdateCheckFunction() {}
166 virtual bool RunAsync() OVERRIDE; 162 virtual ResponseAction Run() OVERRIDE;
167 163
168 // Implements content::NotificationObserver interface.
169 virtual void Observe(int type,
170 const content::NotificationSource& source,
171 const content::NotificationDetails& details) OVERRIDE;
172 private: 164 private:
173 void CheckComplete(); 165 void CheckComplete(const RuntimeAPIDelegate::UpdateCheckResult& result);
174 void ReplyUpdateFound(const std::string& version);
175
176 content::NotificationRegistrar registrar_;
177 bool did_reply_;
178 }; 166 };
179 167
180 class RuntimeRestartFunction : public ChromeSyncExtensionFunction { 168 class RuntimeRestartFunction : public UIThreadExtensionFunction {
181 public: 169 public:
182 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART) 170 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART)
183 171
184 protected: 172 protected:
185 virtual ~RuntimeRestartFunction() {} 173 virtual ~RuntimeRestartFunction() {}
186 virtual bool RunSync() OVERRIDE; 174 virtual ResponseAction Run() OVERRIDE;
187 }; 175 };
188 176
189 class RuntimeGetPlatformInfoFunction : public ChromeSyncExtensionFunction { 177 class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction {
190 public: 178 public:
191 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", 179 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo",
192 RUNTIME_GETPLATFORMINFO); 180 RUNTIME_GETPLATFORMINFO);
181
193 protected: 182 protected:
194 virtual ~RuntimeGetPlatformInfoFunction() {} 183 virtual ~RuntimeGetPlatformInfoFunction() {}
195 virtual bool RunSync() OVERRIDE; 184 virtual ResponseAction Run() OVERRIDE;
196 }; 185 };
197 186
198 class RuntimeGetPackageDirectoryEntryFunction 187 class RuntimeGetPackageDirectoryEntryFunction
199 : public ChromeSyncExtensionFunction { 188 : public UIThreadExtensionFunction {
200 public: 189 public:
201 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry", 190 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry",
202 RUNTIME_GETPACKAGEDIRECTORYENTRY) 191 RUNTIME_GETPACKAGEDIRECTORYENTRY)
203 192
204 protected: 193 protected:
205 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} 194 virtual ~RuntimeGetPackageDirectoryEntryFunction() {}
206 virtual bool RunSync() OVERRIDE; 195 virtual ResponseAction Run() OVERRIDE;
207 }; 196 };
208 197
209 } // namespace extensions 198 } // namespace extensions
210 199
211 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_ 200 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698