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" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "extensions/browser/api/runtime/runtime_api_delegate.h" | 14 #include "extensions/browser/api/runtime/runtime_api_delegate.h" |
| 15 #include "extensions/browser/browser_context_keyed_api_factory.h" | 15 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 16 #include "extensions/browser/events/lazy_event_dispatch_util.h" | |
| 16 #include "extensions/browser/extension_function.h" | 17 #include "extensions/browser/extension_function.h" |
| 17 #include "extensions/browser/extension_registry_observer.h" | 18 #include "extensions/browser/extension_registry_observer.h" |
| 18 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
| 19 #include "extensions/browser/process_manager_observer.h" | 20 #include "extensions/browser/process_manager_observer.h" |
| 20 #include "extensions/browser/update_observer.h" | 21 #include "extensions/browser/update_observer.h" |
| 21 #include "extensions/common/api/runtime.h" | 22 #include "extensions/common/api/runtime.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class Version; | 25 class Version; |
| 25 } | 26 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 41 class Extension; | 42 class Extension; |
| 42 class ExtensionHost; | 43 class ExtensionHost; |
| 43 class ExtensionRegistry; | 44 class ExtensionRegistry; |
| 44 | 45 |
| 45 // Runtime API dispatches onStartup, onInstalled, and similar events to | 46 // Runtime API dispatches onStartup, onInstalled, and similar events to |
| 46 // extensions. There is one instance shared between a browser context and | 47 // extensions. There is one instance shared between a browser context and |
| 47 // its related incognito instance. | 48 // its related incognito instance. |
| 48 class RuntimeAPI : public BrowserContextKeyedAPI, | 49 class RuntimeAPI : public BrowserContextKeyedAPI, |
| 49 public ExtensionRegistryObserver, | 50 public ExtensionRegistryObserver, |
| 50 public UpdateObserver, | 51 public UpdateObserver, |
| 51 public ProcessManagerObserver { | 52 public ProcessManagerObserver, |
| 53 public LazyEventDispatchUtil::Observer { | |
| 52 public: | 54 public: |
| 53 // The status of the restartAfterDelay request. | 55 // The status of the restartAfterDelay request. |
| 54 enum class RestartAfterDelayStatus { | 56 enum class RestartAfterDelayStatus { |
| 55 // The request was made by a different extension other than the first one to | 57 // The request was made by a different extension other than the first one to |
| 56 // invoke the restartAfterDelay runtime API. | 58 // invoke the restartAfterDelay runtime API. |
| 57 FAILED_NOT_FIRST_EXTENSION, | 59 FAILED_NOT_FIRST_EXTENSION, |
| 58 | 60 |
| 59 // The request came too soon after a previous restart induced by the | 61 // The request came too soon after a previous restart induced by the |
| 60 // restartAfterDelay API. It failed to be scheduled as requested, and was | 62 // restartAfterDelay API. It failed to be scheduled as requested, and was |
| 61 // instead throttled. | 63 // instead throttled. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 89 bool OpenOptionsPage(const Extension* extension, | 91 bool OpenOptionsPage(const Extension* extension, |
| 90 content::BrowserContext* browser_context); | 92 content::BrowserContext* browser_context); |
| 91 | 93 |
| 92 private: | 94 private: |
| 93 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; | 95 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; |
| 94 friend class RestartAfterDelayApiTest; | 96 friend class RestartAfterDelayApiTest; |
| 95 | 97 |
| 96 // ExtensionRegistryObserver implementation. | 98 // ExtensionRegistryObserver implementation. |
| 97 void OnExtensionLoaded(content::BrowserContext* browser_context, | 99 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 98 const Extension* extension) override; | 100 const Extension* extension) override; |
| 99 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | |
| 100 const Extension* extension, | |
| 101 bool is_update, | |
| 102 const std::string& old_name) override; | |
| 103 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 101 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 104 const Extension* extension, | 102 const Extension* extension, |
| 105 UninstallReason reason) override; | 103 UninstallReason reason) override; |
| 106 | 104 |
| 105 // LazyEventDispatchUtil::Observer:: | |
|
Devlin
2017/06/05 15:38:38
nit: s/Observer::/Observer:
lazyboy
2017/06/05 21:54:01
Done.
| |
| 106 void OnExtensionInstalledAndLoaded( | |
| 107 content::BrowserContext* browser_context, | |
| 108 const Extension* extension, | |
| 109 const base::Version& previous_version) override; | |
| 110 | |
| 107 // Cancels any previously scheduled restart request. | 111 // Cancels any previously scheduled restart request. |
| 108 void MaybeCancelRunningDelayedRestartTimer(); | 112 void MaybeCancelRunningDelayedRestartTimer(); |
| 109 | 113 |
| 110 // Handler for the signal from ExtensionSystem::ready(). | 114 // Handler for the signal from ExtensionSystem::ready(). |
| 111 void OnExtensionsReady(); | 115 void OnExtensionsReady(); |
| 112 | 116 |
| 113 RestartAfterDelayStatus ScheduleDelayedRestart(const base::Time& now, | 117 RestartAfterDelayStatus ScheduleDelayedRestart(const base::Time& now, |
| 114 int seconds_from_now); | 118 int seconds_from_now); |
| 115 | 119 |
| 116 // Called when the delayed restart timer times out so that it attempts to | 120 // Called when the delayed restart timer times out so that it attempts to |
| 117 // execute the restart request scheduled earlier. | 121 // execute the restart request scheduled earlier. |
| 118 void OnDelayedRestartTimerTimeout(); | 122 void OnDelayedRestartTimerTimeout(); |
| 119 | 123 |
| 120 // BrowserContextKeyedAPI implementation: | 124 // BrowserContextKeyedAPI implementation: |
| 121 static const char* service_name() { return "RuntimeAPI"; } | 125 static const char* service_name() { return "RuntimeAPI"; } |
| 122 static const bool kServiceRedirectedInIncognito = true; | 126 static const bool kServiceRedirectedInIncognito = true; |
| 123 static const bool kServiceIsNULLWhileTesting = true; | 127 static const bool kServiceIsNULLWhileTesting = true; |
| 124 void Shutdown() override; | 128 void Shutdown() override; |
| 125 | 129 |
| 126 // extensions::UpdateObserver overrides: | 130 // extensions::UpdateObserver overrides: |
| 127 void OnAppUpdateAvailable(const Extension* extension) override; | 131 void OnAppUpdateAvailable(const Extension* extension) override; |
| 128 void OnChromeUpdateAvailable() override; | 132 void OnChromeUpdateAvailable() override; |
| 129 | 133 |
| 130 // ProcessManagerObserver implementation: | 134 // ProcessManagerObserver implementation: |
| 131 void OnBackgroundHostStartup(const Extension* extension) override; | 135 void OnBackgroundHostStartup(const Extension* extension) override; |
| 132 | 136 |
| 133 // Pref related functions that deals with info about installed extensions that | |
| 134 // has not been loaded yet. | |
| 135 // Used to send chrome.runtime.onInstalled event upon loading the extensions. | |
| 136 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, | |
| 137 base::Version* previous_version); | |
| 138 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); | |
| 139 void StorePendingOnInstallInfoToPref(const Extension* extension); | |
| 140 | |
| 141 void AllowNonKioskAppsInRestartAfterDelayForTesting(); | 137 void AllowNonKioskAppsInRestartAfterDelayForTesting(); |
| 142 | 138 |
| 143 void set_min_duration_between_restarts_for_testing(base::TimeDelta delta) { | 139 void set_min_duration_between_restarts_for_testing(base::TimeDelta delta) { |
| 144 minimum_duration_between_restarts_ = delta; | 140 minimum_duration_between_restarts_ = delta; |
| 145 } | 141 } |
| 146 | 142 |
| 147 std::unique_ptr<RuntimeAPIDelegate> delegate_; | 143 std::unique_ptr<RuntimeAPIDelegate> delegate_; |
| 148 | 144 |
| 149 content::BrowserContext* browser_context_; | 145 content::BrowserContext* browser_context_; |
| 150 | 146 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 RUNTIME_GETPACKAGEDIRECTORYENTRY) | 305 RUNTIME_GETPACKAGEDIRECTORYENTRY) |
| 310 | 306 |
| 311 protected: | 307 protected: |
| 312 ~RuntimeGetPackageDirectoryEntryFunction() override {} | 308 ~RuntimeGetPackageDirectoryEntryFunction() override {} |
| 313 ResponseAction Run() override; | 309 ResponseAction Run() override; |
| 314 }; | 310 }; |
| 315 | 311 |
| 316 } // namespace extensions | 312 } // namespace extensions |
| 317 | 313 |
| 318 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ | 314 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ |
| OLD | NEW |