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

Side by Side Diff: extensions/browser/api/runtime/runtime_api.h

Issue 406063002: Hook up runtime API to implement ExtensionRegistryObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback. Created 6 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | extensions/browser/api/runtime/runtime_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/public/browser/notification_observer.h" 11 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h" 12 #include "content/public/browser/notification_registrar.h"
12 #include "extensions/browser/api/runtime/runtime_api_delegate.h" 13 #include "extensions/browser/api/runtime/runtime_api_delegate.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h" 14 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h" 15 #include "extensions/browser/extension_function.h"
16 #include "extensions/browser/extension_registry_observer.h"
15 #include "extensions/browser/process_manager_observer.h" 17 #include "extensions/browser/process_manager_observer.h"
16 #include "extensions/browser/update_observer.h" 18 #include "extensions/browser/update_observer.h"
17 #include "extensions/common/api/runtime.h" 19 #include "extensions/common/api/runtime.h"
18 20
19 namespace base { 21 namespace base {
20 class Version; 22 class Version;
21 } 23 }
22 24
23 namespace content { 25 namespace content {
24 class BrowserContext; 26 class BrowserContext;
25 } 27 }
26 28
27 namespace extensions { 29 namespace extensions {
28 30
29 namespace core_api { 31 namespace core_api {
30 namespace runtime { 32 namespace runtime {
31 struct PlatformInfo; 33 struct PlatformInfo;
32 } 34 }
33 } 35 }
34 36
35 class Extension; 37 class Extension;
36 class ExtensionHost; 38 class ExtensionHost;
37 39
38 // Runtime API dispatches onStartup, onInstalled, and similar events to 40 // Runtime API dispatches onStartup, onInstalled, and similar events to
39 // extensions. There is one instance shared between a browser context and 41 // extensions. There is one instance shared between a browser context and
40 // its related incognito instance. 42 // its related incognito instance.
41 class RuntimeAPI : public BrowserContextKeyedAPI, 43 class RuntimeAPI : public BrowserContextKeyedAPI,
42 public content::NotificationObserver, 44 public content::NotificationObserver,
45 public ExtensionRegistryObserver,
43 public UpdateObserver, 46 public UpdateObserver,
44 public ProcessManagerObserver { 47 public ProcessManagerObserver {
45 public: 48 public:
46 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance(); 49 static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance();
47 50
48 explicit RuntimeAPI(content::BrowserContext* context); 51 explicit RuntimeAPI(content::BrowserContext* context);
49 virtual ~RuntimeAPI(); 52 virtual ~RuntimeAPI();
50 53
51 // content::NotificationObserver overrides: 54 // content::NotificationObserver overrides:
52 virtual void Observe(int type, 55 virtual void Observe(int type,
53 const content::NotificationSource& source, 56 const content::NotificationSource& source,
54 const content::NotificationDetails& details) OVERRIDE; 57 const content::NotificationDetails& details) OVERRIDE;
55 58
56 void ReloadExtension(const std::string& extension_id); 59 void ReloadExtension(const std::string& extension_id);
57 bool CheckForUpdates(const std::string& extension_id, 60 bool CheckForUpdates(const std::string& extension_id,
58 const RuntimeAPIDelegate::UpdateCheckCallback& callback); 61 const RuntimeAPIDelegate::UpdateCheckCallback& callback);
59 void OpenURL(const GURL& uninstall_url); 62 void OpenURL(const GURL& uninstall_url);
60 bool GetPlatformInfo(core_api::runtime::PlatformInfo* info); 63 bool GetPlatformInfo(core_api::runtime::PlatformInfo* info);
61 bool RestartDevice(std::string* error_message); 64 bool RestartDevice(std::string* error_message);
62 65
63 private: 66 private:
64 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>; 67 friend class BrowserContextKeyedAPIFactory<RuntimeAPI>;
65 68
66 void OnExtensionsReady(); 69 void OnExtensionsReady();
67 void OnExtensionLoaded(const Extension* extension);
68 void OnExtensionInstalled(const Extension* extension);
69 void OnExtensionUninstalled(const Extension* extension);
70 70
71 // BrowserContextKeyedAPI implementation: 71 // BrowserContextKeyedAPI implementation:
72 static const char* service_name() { return "RuntimeAPI"; } 72 static const char* service_name() { return "RuntimeAPI"; }
73 static const bool kServiceRedirectedInIncognito = true; 73 static const bool kServiceRedirectedInIncognito = true;
74 static const bool kServiceIsNULLWhileTesting = true; 74 static const bool kServiceIsNULLWhileTesting = true;
75 virtual void Shutdown() OVERRIDE; 75 virtual void Shutdown() OVERRIDE;
76 76
77 // ExtensionRegistryObserver implementation.
78 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
79 const Extension* extension) OVERRIDE;
80 virtual void OnExtensionWillBeInstalled(
81 content::BrowserContext* browser_context,
Devlin 2014/07/22 22:21:12 let's move this above the BCKAPI impl methods so t
rpaquay 2014/07/23 00:03:59 Done.
82 const Extension* extension,
83 bool is_update,
84 bool from_ephemeral,
85 const std::string& old_name) OVERRIDE;
86 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
87 const Extension* extension,
88 UninstallReason reason) OVERRIDE;
89
77 // extensions::UpdateObserver overrides: 90 // extensions::UpdateObserver overrides:
78 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE; 91 virtual void OnAppUpdateAvailable(const Extension* extension) OVERRIDE;
79 virtual void OnChromeUpdateAvailable() OVERRIDE; 92 virtual void OnChromeUpdateAvailable() OVERRIDE;
80 93
81 // ProcessManagerObserver implementation: 94 // ProcessManagerObserver implementation:
82 virtual void OnBackgroundHostStartup(const Extension* extension) OVERRIDE; 95 virtual void OnBackgroundHostStartup(const Extension* extension) OVERRIDE;
83 96
84 scoped_ptr<RuntimeAPIDelegate> delegate_; 97 scoped_ptr<RuntimeAPIDelegate> delegate_;
85 98
86 content::BrowserContext* browser_context_; 99 content::BrowserContext* browser_context_;
87 100
88 // True if we should dispatch the chrome.runtime.onInstalled event with 101 // True if we should dispatch the chrome.runtime.onInstalled event with
89 // reason "chrome_update" upon loading each extension. 102 // reason "chrome_update" upon loading each extension.
90 bool dispatch_chrome_updated_event_; 103 bool dispatch_chrome_updated_event_;
91 104
92 content::NotificationRegistrar registrar_; 105 content::NotificationRegistrar registrar_;
93 106
107 // Listen to extension notifications.
108 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
109 extension_registry_observer_;
110
94 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI); 111 DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
95 }; 112 };
96 113
97 class RuntimeEventRouter { 114 class RuntimeEventRouter {
98 public: 115 public:
99 // Dispatches the onStartup event to all currently-loaded extensions. 116 // Dispatches the onStartup event to all currently-loaded extensions.
100 static void DispatchOnStartupEvent(content::BrowserContext* context, 117 static void DispatchOnStartupEvent(content::BrowserContext* context,
101 const std::string& extension_id); 118 const std::string& extension_id);
102 119
103 // Dispatches the onInstalled event to the given extension. 120 // Dispatches the onInstalled event to the given extension.
(...skipping 13 matching lines...) Expand all
117 content::BrowserContext* context); 134 content::BrowserContext* context);
118 135
119 // Dispatches the onRestartRequired event to the given app. 136 // Dispatches the onRestartRequired event to the given app.
120 static void DispatchOnRestartRequiredEvent( 137 static void DispatchOnRestartRequiredEvent(
121 content::BrowserContext* context, 138 content::BrowserContext* context,
122 const std::string& app_id, 139 const std::string& app_id,
123 core_api::runtime::OnRestartRequired::Reason reason); 140 core_api::runtime::OnRestartRequired::Reason reason);
124 141
125 // Does any work needed at extension uninstall (e.g. load uninstall url). 142 // Does any work needed at extension uninstall (e.g. load uninstall url).
126 static void OnExtensionUninstalled(content::BrowserContext* context, 143 static void OnExtensionUninstalled(content::BrowserContext* context,
127 const std::string& extension_id); 144 const std::string& extension_id,
145 UninstallReason reason);
128 }; 146 };
129 147
130 class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction { 148 class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction {
131 public: 149 public:
132 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage", 150 DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage",
133 RUNTIME_GETBACKGROUNDPAGE) 151 RUNTIME_GETBACKGROUNDPAGE)
134 152
135 protected: 153 protected:
136 virtual ~RuntimeGetBackgroundPageFunction() {} 154 virtual ~RuntimeGetBackgroundPageFunction() {}
137 virtual ResponseAction Run() OVERRIDE; 155 virtual ResponseAction Run() OVERRIDE;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 RUNTIME_GETPACKAGEDIRECTORYENTRY) 215 RUNTIME_GETPACKAGEDIRECTORYENTRY)
198 216
199 protected: 217 protected:
200 virtual ~RuntimeGetPackageDirectoryEntryFunction() {} 218 virtual ~RuntimeGetPackageDirectoryEntryFunction() {}
201 virtual ResponseAction Run() OVERRIDE; 219 virtual ResponseAction Run() OVERRIDE;
202 }; 220 };
203 221
204 } // namespace extensions 222 } // namespace extensions
205 223
206 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_ 224 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/runtime/runtime_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698