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

Unified Diff: extensions/browser/api/runtime/runtime_api.h

Issue 1970613003: Add a new app API to enable watchdog behavior restarts in kiosk apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nitty nit. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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..cebaad72da704fbfadd984c1a8e694e87e36f493 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,28 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
public UpdateObserver,
public ProcessManagerObserver {
public:
+ // The status of the restartAfterDelay request.
+ enum class RestartAfterDelayStatus {
+ // The request was made by a different extension other than the first one to
+ // invoke the restartAfterDelay runtime API.
+ FAILED_NOT_FIRST_EXTENSION,
+
+ // The request came too soon after a previous restart induced by the
+ // restartAfterDelay API. It failed to be scheduled as requested, and was
+ // instead throttled.
+ FAILED_THROTTLED,
+
+ // Any previously scheduled restart was successfully canceled.
+ SUCCESS_RESTART_CANCELED,
+
+ // 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 +89,16 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
void OpenURL(const GURL& uninstall_url);
bool GetPlatformInfo(api::runtime::PlatformInfo* info);
bool RestartDevice(std::string* error_message);
+
+ RestartAfterDelayStatus RestartDeviceAfterDelay(
+ const std::string& extension_id,
+ int seconds_from_now);
+
bool OpenOptionsPage(const Extension* extension);
private:
friend class BrowserContextKeyedAPIFactory<RuntimeAPI>;
+ friend class RestartAfterDelayApiTest;
// ExtensionRegistryObserver implementation.
void OnExtensionLoaded(content::BrowserContext* browser_context,
@@ -81,6 +111,16 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
const Extension* extension,
UninstallReason reason) override;
+ // Cancels any previously scheduled restart request.
+ void MaybeCancelRunningDelayedRestartTimer();
+
+ RestartAfterDelayStatus ScheduleDelayedRestart(const base::Time& now,
+ int seconds_from_now);
+
+ // Called when the delayed restart timer times out so that it attempts to
+ // execute the restart request scheduled earlier.
+ void OnDelayedRestartTimerTimeout();
+
// BrowserContextKeyedAPI implementation:
static const char* service_name() { return "RuntimeAPI"; }
static const bool kServiceRedirectedInIncognito = true;
@@ -102,14 +142,16 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id);
void StorePendingOnInstallInfoToPref(const Extension* extension);
+ void AllowNonKioskAppsInRestartAfterDelayForTesting();
+
+ void set_min_duration_between_restarts_for_testing(base::TimeDelta delta) {
+ minimum_duration_between_restarts_ = delta;
+ }
+
std::unique_ptr<RuntimeAPIDelegate> delegate_;
content::BrowserContext* browser_context_;
- // True if we should dispatch the chrome.runtime.onInstalled event with
- // reason "chrome_update" upon loading each extension.
- bool dispatch_chrome_updated_event_;
-
content::NotificationRegistrar registrar_;
// Listen to extension notifications.
@@ -118,6 +160,30 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
ScopedObserver<ProcessManager, ProcessManagerObserver>
process_manager_observer_;
+ // The ID of the first extension to call the restartAfterDelay 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 restart_after_delay_timer_;
+
+ // The minimum allowed duration between two successive restarts caused by
+ // restartAfterDelay calls.
+ base::TimeDelta minimum_duration_between_restarts_;
+
+ // The last restart time which was a result of a successful call to
+ // chrome.runtime.restartAfterDelay().
+ base::Time last_delayed_restart_time_;
+
+ // True if we should dispatch the chrome.runtime.onInstalled event with
+ // reason "chrome_update" upon loading each extension.
+ bool dispatch_chrome_updated_event_;
+
+ bool did_read_delayed_restart_preferences_;
+ bool was_last_restart_due_to_delayed_restart_api_;
+
+ base::WeakPtrFactory<RuntimeAPI> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
};
@@ -220,6 +286,16 @@ class RuntimeRestartFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};
+class RuntimeRestartAfterDelayFunction : public UIThreadExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("runtime.restartAfterDelay",
+ RUNTIME_RESTARTAFTERDELAY)
+
+ protected:
+ ~RuntimeRestartAfterDelayFunction() override {}
+ ResponseAction Run() override;
+};
+
class RuntimeGetPlatformInfoFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo",
« no previous file with comments | « extensions/browser/api/runtime/restart_after_delay_api_unittest.cc ('k') | extensions/browser/api/runtime/runtime_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698