Chromium Code Reviews| Index: extensions/browser/api/runtime/runtime_api.h |
| diff --git a/extensions/browser/api/runtime/runtime_api.h b/extensions/browser/api/runtime/runtime_api.h |
| index 187f7b0d7f16d0fb8e9f60cd2d45c50782e698fb..d066925700bfd275ad832036d7ae518089ef79a9 100644 |
| --- a/extensions/browser/api/runtime/runtime_api.h |
| +++ b/extensions/browser/api/runtime/runtime_api.h |
| @@ -9,6 +9,8 @@ |
| #include "base/macros.h" |
| #include "base/scoped_observer.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "extensions/browser/api/runtime/runtime_api_delegate.h" |
| @@ -28,6 +30,8 @@ namespace content { |
| class BrowserContext; |
| } |
| +class PrefRegistrySimple; |
| + |
| namespace extensions { |
| namespace api { |
| @@ -49,8 +53,23 @@ class RuntimeAPI : public BrowserContextKeyedAPI, |
| public UpdateObserver, |
| public ProcessManagerObserver { |
| public: |
| + // The status of the restart on watchdog request. |
| + enum class RestartOnWatchdogStatus { |
| + // The request was made by a different extension other than the first one to |
| + // invoke the restartOnWatchdog runtime API. |
| + FAILED_NOT_FIRST_EXTENSION, |
| + |
| + // Any previously scheduled restart was successfully canceled. |
| + SUCCESS_RESTART_CANCELLED, |
| + |
| + // A restart was successfully scheduled. |
| + SUCCESS_RESTART_SCHEDULED, |
| + }; |
| + |
| static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance(); |
| + static void RegisterPrefs(PrefRegistrySimple* registry); |
| + |
| explicit RuntimeAPI(content::BrowserContext* context); |
| ~RuntimeAPI() override; |
| @@ -65,10 +84,16 @@ class RuntimeAPI : public BrowserContextKeyedAPI, |
| void OpenURL(const GURL& uninstall_url); |
| bool GetPlatformInfo(api::runtime::PlatformInfo* info); |
| bool RestartDevice(std::string* error_message); |
| + |
| + RestartOnWatchdogStatus RestartDeviceOnWatchdogTimeout( |
| + const std::string& extension_id, |
| + int seconds_from_now); |
| + |
| bool OpenOptionsPage(const Extension* extension); |
| private: |
| friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; |
| + friend class RestartOnWatchdogApiTest; |
| // ExtensionRegistryObserver implementation. |
| void OnExtensionLoaded(content::BrowserContext* browser_context, |
| @@ -81,6 +106,17 @@ class RuntimeAPI : public BrowserContextKeyedAPI, |
| const Extension* extension, |
| UninstallReason reason) override; |
| + // Cancels any previously scheduled restart request. |
| + void MaybeCancelRunningWatchdogTimer(); |
| + |
| + void ScheduleDelayedRestart(const base::Time& now, |
| + int seconds_from_now, |
| + double stored_last_restart); |
| + |
| + // Called when the restart watchdog timer times out so that it attempts to |
| + // execute the restart request scheduled earlier. |
| + void OnRestartWatchdogTimeout(); |
| + |
| // BrowserContextKeyedAPI implementation: |
| static const char* service_name() { return "RuntimeAPI"; } |
| static const bool kServiceRedirectedInIncognito = true; |
| @@ -102,6 +138,12 @@ class RuntimeAPI : public BrowserContextKeyedAPI, |
| void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); |
| void StorePendingOnInstallInfoToPref(const Extension* extension); |
| + void SetMinDurationBetweenRestartsForTesting(base::TimeDelta delta) { |
|
Devlin
2016/05/25 21:53:22
const base::TimeDelta&
Also, this can probably be
afakhry
2016/05/26 00:18:39
TimeDelta is just an int64_t and is always passed
|
| + minimum_duration_between_restarts_ = delta; |
| + } |
| + |
| + void AllowNonKiostAppsInRestartOnWatchdogForTesting(); |
| + |
| std::unique_ptr<RuntimeAPIDelegate> delegate_; |
| content::BrowserContext* browser_context_; |
| @@ -118,6 +160,19 @@ class RuntimeAPI : public BrowserContextKeyedAPI, |
| ScopedObserver<ProcessManager, ProcessManagerObserver> |
| process_manager_observer_; |
| + // The ID of the first extension to call the restartOnWatchdog API. Any other |
| + // extensions to call this API after that will fail. |
| + std::string schedule_restart_first_extension_id_; |
| + |
| + // The timer that will trigger a device restart when it times out. |
| + base::OneShotTimer watchdog_timer_; |
| + |
| + // The minimum allowed duration between two successive restarts on watchdog |
| + // timer. |
| + base::TimeDelta minimum_duration_between_restarts_; |
| + |
| + base::WeakPtrFactory<RuntimeAPI> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); |
| }; |
| @@ -220,6 +275,16 @@ class RuntimeRestartFunction : public UIThreadExtensionFunction { |
| ResponseAction Run() override; |
| }; |
| +class RuntimeRestartOnWatchdogFunction : public UIThreadExtensionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("runtime.restartOnWatchdog", |
| + RUNTIME_RESTARTONWATCHDOG) |
| + |
| + protected: |
| + ~RuntimeRestartOnWatchdogFunction() override {} |
| + ResponseAction Run() override; |
| +}; |
| + |
| class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo", |