Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/scoped_observer.h" | |
| 9 #include "base/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
| 10 #include "chrome/browser/extensions/bookmark_app_helper.h" | 11 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 11 #include "chrome/browser/extensions/chrome_extension_function.h" | 12 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 12 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 14 #include "chrome/common/web_application_info.h" | 15 #include "chrome/common/web_application_info.h" |
| 15 #include "components/favicon_base/favicon_types.h" | 16 #include "components/favicon_base/favicon_types.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "content/public/browser/notification_observer.h" | |
| 18 #include "content/public/browser/notification_registrar.h" | |
| 19 #include "extensions/browser/browser_context_keyed_api_factory.h" | 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 20 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_registry_observer.h" | |
| 21 | 21 |
| 22 class ExtensionService; | 22 class ExtensionService; |
| 23 class ExtensionUninstallDialog; | 23 class ExtensionUninstallDialog; |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 class ExtensionRegistry; | |
| 26 | 27 |
| 27 class ManagementFunction : public ChromeSyncExtensionFunction { | 28 class ManagementFunction : public ChromeSyncExtensionFunction { |
| 28 protected: | 29 protected: |
| 29 virtual ~ManagementFunction() {} | 30 virtual ~ManagementFunction() {} |
| 30 | 31 |
| 31 ExtensionService* service(); | 32 ExtensionService* service(); |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 class AsyncManagementFunction : public ChromeAsyncExtensionFunction { | 35 class AsyncManagementFunction : public ChromeAsyncExtensionFunction { |
| 35 protected: | 36 protected: |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 212 |
| 212 ManagementGenerateAppForLinkFunction(); | 213 ManagementGenerateAppForLinkFunction(); |
| 213 | 214 |
| 214 protected: | 215 protected: |
| 215 virtual ~ManagementGenerateAppForLinkFunction(); | 216 virtual ~ManagementGenerateAppForLinkFunction(); |
| 216 | 217 |
| 217 virtual bool RunAsync() OVERRIDE; | 218 virtual bool RunAsync() OVERRIDE; |
| 218 | 219 |
| 219 private: | 220 private: |
| 220 void OnFaviconForApp(const favicon_base::FaviconImageResult& image_result); | 221 void OnFaviconForApp(const favicon_base::FaviconImageResult& image_result); |
| 221 void FinishCreateBookmarkApp(const extensions::Extension* extension, | 222 void FinishCreateBookmarkApp(const Extension* extension, |
| 222 const WebApplicationInfo& web_app_info); | 223 const WebApplicationInfo& web_app_info); |
| 223 | 224 |
| 224 std::string title_; | 225 std::string title_; |
| 225 GURL launch_url_; | 226 GURL launch_url_; |
| 226 | 227 |
| 227 scoped_ptr<BookmarkAppHelper> bookmark_app_helper_; | 228 scoped_ptr<BookmarkAppHelper> bookmark_app_helper_; |
| 228 | 229 |
| 229 // Used for favicon loading tasks. | 230 // Used for favicon loading tasks. |
| 230 base::CancelableTaskTracker cancelable_task_tracker_; | 231 base::CancelableTaskTracker cancelable_task_tracker_; |
| 231 }; | 232 }; |
| 232 | 233 |
| 233 class ManagementEventRouter : public content::NotificationObserver { | 234 class ManagementEventRouter : public ExtensionRegistryObserver { |
| 234 public: | 235 public: |
| 235 explicit ManagementEventRouter(Profile* profile); | 236 explicit ManagementEventRouter(content::BrowserContext* context); |
| 236 virtual ~ManagementEventRouter(); | 237 virtual ~ManagementEventRouter(); |
| 237 | 238 |
| 238 private: | 239 private: |
|
Devlin
2014/06/18 16:04:34
nit: // ExtensionRegistryObserver implementation.
limasdf
2014/06/19 01:48:43
Done.
| |
| 239 // content::NotificationObserver implementation. | 240 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 240 virtual void Observe(int type, | 241 const Extension* extension) OVERRIDE; |
| 241 const content::NotificationSource& source, | 242 virtual void OnExtensionUnloaded( |
| 242 const content::NotificationDetails& details) OVERRIDE; | 243 content::BrowserContext* browser_context, |
| 244 const Extension* extension, | |
| 245 UnloadedExtensionInfo::Reason reason) OVERRIDE; | |
| 246 virtual void OnExtensionInstalled(content::BrowserContext* browser_context, | |
| 247 const Extension* extension) OVERRIDE; | |
| 248 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, | |
| 249 const Extension* extension) OVERRIDE; | |
| 243 | 250 |
| 244 content::NotificationRegistrar registrar_; | 251 void BroadcastEvent(const Extension* extension, |
|
Devlin
2014/06/18 16:04:34
nit: comment to the effect of
// Dispatches manage
limasdf
2014/06/19 01:48:42
Done.
| |
| 252 content::BrowserContext* browser_context, | |
| 253 const char* event_name); | |
| 245 | 254 |
| 246 Profile* profile_; | 255 content::BrowserContext* browser_context_; |
| 256 | |
| 257 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
| 258 extension_registry_observer_; | |
| 247 | 259 |
| 248 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter); | 260 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter); |
| 249 }; | 261 }; |
| 250 | 262 |
| 251 class ManagementAPI : public BrowserContextKeyedAPI, | 263 class ManagementAPI : public BrowserContextKeyedAPI, |
| 252 public extensions::EventRouter::Observer { | 264 public EventRouter::Observer { |
| 253 public: | 265 public: |
| 254 explicit ManagementAPI(content::BrowserContext* context); | 266 explicit ManagementAPI(content::BrowserContext* context); |
| 255 virtual ~ManagementAPI(); | 267 virtual ~ManagementAPI(); |
| 256 | 268 |
| 257 // KeyedService implementation. | 269 // KeyedService implementation. |
| 258 virtual void Shutdown() OVERRIDE; | 270 virtual void Shutdown() OVERRIDE; |
| 259 | 271 |
| 260 // BrowserContextKeyedAPI implementation. | 272 // BrowserContextKeyedAPI implementation. |
| 261 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); | 273 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); |
| 262 | 274 |
| 263 // EventRouter::Observer implementation. | 275 // EventRouter::Observer implementation. |
| 264 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) | 276 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 265 OVERRIDE; | |
| 266 | 277 |
| 267 private: | 278 private: |
| 268 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; | 279 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; |
| 269 | 280 |
| 270 content::BrowserContext* browser_context_; | 281 content::BrowserContext* browser_context_; |
| 271 | 282 |
| 272 // BrowserContextKeyedAPI implementation. | 283 // BrowserContextKeyedAPI implementation. |
| 273 static const char* service_name() { | 284 static const char* service_name() { |
| 274 return "ManagementAPI"; | 285 return "ManagementAPI"; |
| 275 } | 286 } |
| 276 static const bool kServiceIsNULLWhileTesting = true; | 287 static const bool kServiceIsNULLWhileTesting = true; |
| 277 | 288 |
| 278 // Created lazily upon OnListenerAdded. | 289 // Created lazily upon OnListenerAdded. |
| 279 scoped_ptr<ManagementEventRouter> management_event_router_; | 290 scoped_ptr<ManagementEventRouter> management_event_router_; |
| 280 | 291 |
| 281 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); | 292 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); |
| 282 }; | 293 }; |
| 283 | 294 |
| 284 } // namespace extensions | 295 } // namespace extensions |
| 285 | 296 |
| 286 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 297 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
| OLD | NEW |