Chromium Code Reviews| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 void Observe(int type, | 58 void Observe(int type, |
| 59 const content::NotificationSource& source, | 59 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) override; | 60 const content::NotificationDetails& details) override; |
| 61 | 61 |
| 62 void ReloadExtension(const std::string& extension_id); | 62 void ReloadExtension(const std::string& extension_id); |
| 63 bool CheckForUpdates(const std::string& extension_id, | 63 bool CheckForUpdates(const std::string& extension_id, |
| 64 const RuntimeAPIDelegate::UpdateCheckCallback& callback); | 64 const RuntimeAPIDelegate::UpdateCheckCallback& callback); |
| 65 void OpenURL(const GURL& uninstall_url); | 65 void OpenURL(const GURL& uninstall_url); |
| 66 bool GetPlatformInfo(api::runtime::PlatformInfo* info); | 66 bool GetPlatformInfo(api::runtime::PlatformInfo* info); |
| 67 bool RestartDevice(std::string* error_message); | 67 bool RestartDevice(std::string* error_message); |
| 68 | |
| 69 using OnWatchdogTimeoutCallback = | |
| 70 base::Callback<void(bool success, const std::string& message)>; | |
| 71 void RestartDeviceOnWatchdogTimeout( | |
| 72 const Extension* extension, | |
| 73 int seconds, | |
| 74 const OnWatchdogTimeoutCallback& callback); | |
| 75 | |
| 68 bool OpenOptionsPage(const Extension* extension); | 76 bool OpenOptionsPage(const Extension* extension); |
| 69 | 77 |
| 70 private: | 78 private: |
| 71 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; | 79 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; |
| 80 friend class RestartOnWatchdogApiTest; | |
| 72 | 81 |
| 73 // ExtensionRegistryObserver implementation. | 82 // ExtensionRegistryObserver implementation. |
| 74 void OnExtensionLoaded(content::BrowserContext* browser_context, | 83 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 75 const Extension* extension) override; | 84 const Extension* extension) override; |
| 76 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 85 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 77 const Extension* extension, | 86 const Extension* extension, |
| 78 bool is_update, | 87 bool is_update, |
| 79 const std::string& old_name) override; | 88 const std::string& old_name) override; |
| 80 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 89 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 81 const Extension* extension, | 90 const Extension* extension, |
| 82 UninstallReason reason) override; | 91 UninstallReason reason) override; |
| 83 | 92 |
| 93 void OnRestartWatchdogTimeout(const Extension* extension, | |
| 94 const OnWatchdogTimeoutCallback& callback); | |
| 95 | |
| 84 // BrowserContextKeyedAPI implementation: | 96 // BrowserContextKeyedAPI implementation: |
| 85 static const char* service_name() { return "RuntimeAPI"; } | 97 static const char* service_name() { return "RuntimeAPI"; } |
| 86 static const bool kServiceRedirectedInIncognito = true; | 98 static const bool kServiceRedirectedInIncognito = true; |
| 87 static const bool kServiceIsNULLWhileTesting = true; | 99 static const bool kServiceIsNULLWhileTesting = true; |
| 88 void Shutdown() override; | 100 void Shutdown() override; |
| 89 | 101 |
| 90 // extensions::UpdateObserver overrides: | 102 // extensions::UpdateObserver overrides: |
| 91 void OnAppUpdateAvailable(const Extension* extension) override; | 103 void OnAppUpdateAvailable(const Extension* extension) override; |
| 92 void OnChromeUpdateAvailable() override; | 104 void OnChromeUpdateAvailable() override; |
| 93 | 105 |
| 94 // ProcessManagerObserver implementation: | 106 // ProcessManagerObserver implementation: |
| 95 void OnBackgroundHostStartup(const Extension* extension) override; | 107 void OnBackgroundHostStartup(const Extension* extension) override; |
| 96 | 108 |
| 97 // Pref related functions that deals with info about installed extensions that | 109 // Pref related functions that deals with info about installed extensions that |
| 98 // has not been loaded yet. | 110 // has not been loaded yet. |
| 99 // Used to send chrome.runtime.onInstalled event upon loading the extensions. | 111 // Used to send chrome.runtime.onInstalled event upon loading the extensions. |
| 100 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, | 112 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, |
| 101 base::Version* previous_version); | 113 base::Version* previous_version); |
| 102 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); | 114 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); |
| 103 void StorePendingOnInstallInfoToPref(const Extension* extension); | 115 void StorePendingOnInstallInfoToPref(const Extension* extension); |
| 104 | 116 |
| 117 void SetMinDurationBetweenRestartsForTesting(base::TimeDelta delta) { | |
| 118 minimum_duration_between_restarts_ = delta; | |
| 119 } | |
| 120 | |
| 105 std::unique_ptr<RuntimeAPIDelegate> delegate_; | 121 std::unique_ptr<RuntimeAPIDelegate> delegate_; |
| 106 | 122 |
| 107 content::BrowserContext* browser_context_; | 123 content::BrowserContext* browser_context_; |
| 108 | 124 |
| 109 // True if we should dispatch the chrome.runtime.onInstalled event with | 125 // True if we should dispatch the chrome.runtime.onInstalled event with |
| 110 // reason "chrome_update" upon loading each extension. | 126 // reason "chrome_update" upon loading each extension. |
| 111 bool dispatch_chrome_updated_event_; | 127 bool dispatch_chrome_updated_event_; |
| 112 | 128 |
| 113 content::NotificationRegistrar registrar_; | 129 content::NotificationRegistrar registrar_; |
| 114 | 130 |
| 115 // Listen to extension notifications. | 131 // Listen to extension notifications. |
| 116 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 132 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 117 extension_registry_observer_; | 133 extension_registry_observer_; |
| 118 ScopedObserver<ProcessManager, ProcessManagerObserver> | 134 ScopedObserver<ProcessManager, ProcessManagerObserver> |
| 119 process_manager_observer_; | 135 process_manager_observer_; |
| 120 | 136 |
| 137 // The timer that will trigger a device restart when it times out. | |
| 138 base::OneShotTimer watchdog_timer_; | |
|
xiyuan
2016/05/13 17:56:15
nit: #include "base/timer/timer.h"
afakhry
2016/05/14 01:27:35
Done.
| |
| 139 | |
| 140 // The minimum allowed duration between two successive restarts on watchdog | |
| 141 // timer. | |
| 142 base::TimeDelta minimum_duration_between_restarts_; | |
|
xiyuan
2016/05/13 17:56:15
nit: #include "base/time/time.h"
afakhry
2016/05/14 01:27:35
Done.
| |
| 143 | |
| 121 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); | 144 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); |
| 122 }; | 145 }; |
| 123 | 146 |
| 124 template <> | 147 template <> |
| 125 void BrowserContextKeyedAPIFactory<RuntimeAPI>::DeclareFactoryDependencies(); | 148 void BrowserContextKeyedAPIFactory<RuntimeAPI>::DeclareFactoryDependencies(); |
| 126 | 149 |
| 127 class RuntimeEventRouter { | 150 class RuntimeEventRouter { |
| 128 public: | 151 public: |
| 129 // Dispatches the onStartup event to all currently-loaded extensions. | 152 // Dispatches the onStartup event to all currently-loaded extensions. |
| 130 static void DispatchOnStartupEvent(content::BrowserContext* context, | 153 static void DispatchOnStartupEvent(content::BrowserContext* context, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 | 236 |
| 214 class RuntimeRestartFunction : public UIThreadExtensionFunction { | 237 class RuntimeRestartFunction : public UIThreadExtensionFunction { |
| 215 public: | 238 public: |
| 216 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART) | 239 DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART) |
| 217 | 240 |
| 218 protected: | 241 protected: |
| 219 ~RuntimeRestartFunction() override {} | 242 ~RuntimeRestartFunction() override {} |
| 220 ResponseAction Run() override; | 243 ResponseAction Run() override; |
| 221 }; | 244 }; |
| 222 | 245 |
| 246 class RuntimeRestartOnWatchdogFunction : public UIThreadExtensionFunction { | |
| 247 public: | |
| 248 DECLARE_EXTENSION_FUNCTION("runtime.restartOnWatchdog", | |
| 249 RUNTIME_RESTARTONWATCHDOG) | |
| 250 | |
| 251 protected: | |
| 252 ~RuntimeRestartOnWatchdogFunction() override {} | |
| 253 ResponseAction Run() override; | |
| 254 | |
| 255 private: | |
| 256 void OnWatchdogTimeout(bool success, const std::string& message); | |
| 257 }; | |
| 258 | |
| 223 class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction { | 259 class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction { |
| 224 public: | 260 public: |
| 225 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", | 261 DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", |
| 226 RUNTIME_GETPLATFORMINFO); | 262 RUNTIME_GETPLATFORMINFO); |
| 227 | 263 |
| 228 protected: | 264 protected: |
| 229 ~RuntimeGetPlatformInfoFunction() override {} | 265 ~RuntimeGetPlatformInfoFunction() override {} |
| 230 ResponseAction Run() override; | 266 ResponseAction Run() override; |
| 231 }; | 267 }; |
| 232 | 268 |
| 233 class RuntimeGetPackageDirectoryEntryFunction | 269 class RuntimeGetPackageDirectoryEntryFunction |
| 234 : public UIThreadExtensionFunction { | 270 : public UIThreadExtensionFunction { |
| 235 public: | 271 public: |
| 236 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry", | 272 DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry", |
| 237 RUNTIME_GETPACKAGEDIRECTORYENTRY) | 273 RUNTIME_GETPACKAGEDIRECTORYENTRY) |
| 238 | 274 |
| 239 protected: | 275 protected: |
| 240 ~RuntimeGetPackageDirectoryEntryFunction() override {} | 276 ~RuntimeGetPackageDirectoryEntryFunction() override {} |
| 241 ResponseAction Run() override; | 277 ResponseAction Run() override; |
| 242 }; | 278 }; |
| 243 | 279 |
| 244 } // namespace extensions | 280 } // namespace extensions |
| 245 | 281 |
| 246 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ | 282 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ |
| OLD | NEW |