OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_API_RUNTIME_RUNTIME_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ |
6 #define EXTENSIONS_BROWSER_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 "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // its related incognito instance. | 43 // its related incognito instance. |
44 class RuntimeAPI : public BrowserContextKeyedAPI, | 44 class RuntimeAPI : public BrowserContextKeyedAPI, |
45 public content::NotificationObserver, | 45 public content::NotificationObserver, |
46 public ExtensionRegistryObserver, | 46 public ExtensionRegistryObserver, |
47 public UpdateObserver, | 47 public UpdateObserver, |
48 public ProcessManagerObserver { | 48 public ProcessManagerObserver { |
49 public: | 49 public: |
50 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance(); | 50 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance(); |
51 | 51 |
52 explicit RuntimeAPI(content::BrowserContext* context); | 52 explicit RuntimeAPI(content::BrowserContext* context); |
53 virtual ~RuntimeAPI(); | 53 ~RuntimeAPI() override; |
54 | 54 |
55 // content::NotificationObserver overrides: | 55 // content::NotificationObserver overrides: |
56 virtual void Observe(int type, | 56 void Observe(int type, |
57 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
58 const content::NotificationDetails& details) override; | 58 const content::NotificationDetails& details) override; |
59 | 59 |
60 void ReloadExtension(const std::string& extension_id); | 60 void ReloadExtension(const std::string& extension_id); |
61 bool CheckForUpdates(const std::string& extension_id, | 61 bool CheckForUpdates(const std::string& extension_id, |
62 const RuntimeAPIDelegate::UpdateCheckCallback& callback); | 62 const RuntimeAPIDelegate::UpdateCheckCallback& callback); |
63 void OpenURL(const GURL& uninstall_url); | 63 void OpenURL(const GURL& uninstall_url); |
64 bool GetPlatformInfo(core_api::runtime::PlatformInfo* info); | 64 bool GetPlatformInfo(core_api::runtime::PlatformInfo* info); |
65 bool RestartDevice(std::string* error_message); | 65 bool RestartDevice(std::string* error_message); |
66 | 66 |
67 private: | 67 private: |
68 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; | 68 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; |
69 | 69 |
70 // ExtensionRegistryObserver implementation. | 70 // ExtensionRegistryObserver implementation. |
71 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 71 void OnExtensionLoaded(content::BrowserContext* browser_context, |
72 const Extension* extension) override; | 72 const Extension* extension) override; |
73 virtual void OnExtensionWillBeInstalled( | 73 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
74 content::BrowserContext* browser_context, | 74 const Extension* extension, |
75 const Extension* extension, | 75 bool is_update, |
76 bool is_update, | 76 bool from_ephemeral, |
77 bool from_ephemeral, | 77 const std::string& old_name) override; |
78 const std::string& old_name) override; | 78 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
79 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, | 79 const Extension* extension, |
80 const Extension* extension, | 80 UninstallReason reason) override; |
81 UninstallReason reason) override; | |
82 | 81 |
83 // BrowserContextKeyedAPI implementation: | 82 // BrowserContextKeyedAPI implementation: |
84 static const char* service_name() { return "RuntimeAPI"; } | 83 static const char* service_name() { return "RuntimeAPI"; } |
85 static const bool kServiceRedirectedInIncognito = true; | 84 static const bool kServiceRedirectedInIncognito = true; |
86 static const bool kServiceIsNULLWhileTesting = true; | 85 static const bool kServiceIsNULLWhileTesting = true; |
87 virtual void Shutdown() override; | 86 void Shutdown() override; |
88 | 87 |
89 // extensions::UpdateObserver overrides: | 88 // extensions::UpdateObserver overrides: |
90 virtual void OnAppUpdateAvailable(const Extension* extension) override; | 89 void OnAppUpdateAvailable(const Extension* extension) override; |
91 virtual void OnChromeUpdateAvailable() override; | 90 void OnChromeUpdateAvailable() override; |
92 | 91 |
93 // ProcessManagerObserver implementation: | 92 // ProcessManagerObserver implementation: |
94 virtual void OnBackgroundHostStartup(const Extension* extension) override; | 93 void OnBackgroundHostStartup(const Extension* extension) override; |
95 | 94 |
96 scoped_ptr<RuntimeAPIDelegate> delegate_; | 95 scoped_ptr<RuntimeAPIDelegate> delegate_; |
97 | 96 |
98 content::BrowserContext* browser_context_; | 97 content::BrowserContext* browser_context_; |
99 | 98 |
100 // True if we should dispatch the chrome.runtime.onInstalled event with | 99 // True if we should dispatch the chrome.runtime.onInstalled event with |
101 // reason "chrome_update" upon loading each extension. | 100 // reason "chrome_update" upon loading each extension. |
102 bool dispatch_chrome_updated_event_; | 101 bool dispatch_chrome_updated_event_; |
103 | 102 |
104 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const std::string& extension_id, | 142 const std::string& extension_id, |
144 UninstallReason reason); | 143 UninstallReason reason); |
145 }; | 144 }; |
146 | 145 |
147 class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction { | 146 class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction { |
148 public: | 147 public: |
149 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", | 148 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", |
150 RUNTIME_GETBACKGROUNDPAGE) | 149 RUNTIME_GETBACKGROUNDPAGE) |
151 | 150 |
152 protected: | 151 protected: |
153 virtual ~RuntimeGetBackgroundPageFunction() {} | 152 ~RuntimeGetBackgroundPageFunction() override {} |
154 virtual ResponseAction Run() override; | 153 ResponseAction Run() override; |
155 | 154 |
156 private: | 155 private: |
157 void OnPageLoaded(ExtensionHost*); | 156 void OnPageLoaded(ExtensionHost*); |
158 }; | 157 }; |
159 | 158 |
160 class RuntimeSetUninstallURLFunction : public UIThreadExtensionFunction { | 159 class RuntimeSetUninstallURLFunction : public UIThreadExtensionFunction { |
161 public: | 160 public: |
162 DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL", RUNTIME_SETUNINSTALLURL) | 161 DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL", RUNTIME_SETUNINSTALLURL) |
163 | 162 |
164 protected: | 163 protected: |
165 virtual ~RuntimeSetUninstallURLFunction() {} | 164 ~RuntimeSetUninstallURLFunction() override {} |
166 virtual ResponseAction Run() override; | 165 ResponseAction Run() override; |
167 }; | 166 }; |
168 | 167 |
169 class RuntimeReloadFunction : public UIThreadExtensionFunction { | 168 class RuntimeReloadFunction : public UIThreadExtensionFunction { |
170 public: | 169 public: |
171 DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD) | 170 DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD) |
172 | 171 |
173 protected: | 172 protected: |
174 virtual ~RuntimeReloadFunction() {} | 173 ~RuntimeReloadFunction() override {} |
175 virtual ResponseAction Run() override; | 174 ResponseAction Run() override; |
176 }; | 175 }; |
177 | 176 |
178 class RuntimeRequestUpdateCheckFunction : public UIThreadExtensionFunction { | 177 class RuntimeRequestUpdateCheckFunction : public UIThreadExtensionFunction { |
179 public: | 178 public: |
180 DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck", | 179 DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck", |
181 RUNTIME_REQUESTUPDATECHECK) | 180 RUNTIME_REQUESTUPDATECHECK) |
182 | 181 |
183 protected: | 182 protected: |
184 virtual ~RuntimeRequestUpdateCheckFunction() {} | 183 ~RuntimeRequestUpdateCheckFunction() override {} |
185 virtual ResponseAction Run() override; | 184 ResponseAction Run() override; |
186 | 185 |
187 private: | 186 private: |
188 void CheckComplete(const RuntimeAPIDelegate::UpdateCheckResult& result); | 187 void CheckComplete(const RuntimeAPIDelegate::UpdateCheckResult& result); |
189 }; | 188 }; |
190 | 189 |
191 class RuntimeRestartFunction : public UIThreadExtensionFunction { | 190 class RuntimeRestartFunction : public UIThreadExtensionFunction { |
192 public: | 191 public: |
193 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART) | 192 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART) |
194 | 193 |
195 protected: | 194 protected: |
196 virtual ~RuntimeRestartFunction() {} | 195 ~RuntimeRestartFunction() override {} |
197 virtual ResponseAction Run() override; | 196 ResponseAction Run() override; |
198 }; | 197 }; |
199 | 198 |
200 class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction { | 199 class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction { |
201 public: | 200 public: |
202 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", | 201 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", |
203 RUNTIME_GETPLATFORMINFO); | 202 RUNTIME_GETPLATFORMINFO); |
204 | 203 |
205 protected: | 204 protected: |
206 virtual ~RuntimeGetPlatformInfoFunction() {} | 205 ~RuntimeGetPlatformInfoFunction() override {} |
207 virtual ResponseAction Run() override; | 206 ResponseAction Run() override; |
208 }; | 207 }; |
209 | 208 |
210 class RuntimeGetPackageDirectoryEntryFunction | 209 class RuntimeGetPackageDirectoryEntryFunction |
211 : public UIThreadExtensionFunction { | 210 : public UIThreadExtensionFunction { |
212 public: | 211 public: |
213 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry", | 212 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry", |
214 RUNTIME_GETPACKAGEDIRECTORYENTRY) | 213 RUNTIME_GETPACKAGEDIRECTORYENTRY) |
215 | 214 |
216 protected: | 215 protected: |
217 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} | 216 ~RuntimeGetPackageDirectoryEntryFunction() override {} |
218 virtual ResponseAction Run() override; | 217 ResponseAction Run() override; |
219 }; | 218 }; |
220 | 219 |
221 } // namespace extensions | 220 } // namespace extensions |
222 | 221 |
223 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ | 222 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ |
OLD | NEW |