[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ |
| 7 | |
[email protected] | df84c53 | 2014-04-25 15:36:54 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | #include "base/compiler_specific.h" |
| 11 | #include "base/macros.h" |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "base/memory/weak_ptr.h" |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 14 | #include "base/scoped_observer.h" |
[email protected] | 446f73c2 | 2014-05-14 20:47:18 | [diff] [blame] | 15 | #include "components/gcm_driver/gcm_app_handler.h" |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 16 | #include "content/public/browser/notification_observer.h" |
| 17 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 18 | #include "extensions/browser/browser_context_keyed_api_factory.h" |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 19 | #include "extensions/browser/extension_registry_observer.h" |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 20 | #include "google_apis/gcm/gcm_client.h" |
| 21 | |
| 22 | class Profile; |
[email protected] | df84c53 | 2014-04-25 15:36:54 | [diff] [blame] | 23 | |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 24 | namespace content { |
| 25 | class BrowserContext; |
| 26 | } |
[email protected] | df84c53 | 2014-04-25 15:36:54 | [diff] [blame] | 27 | |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 28 | namespace gcm { |
[email protected] | 9d7e5c0 | 2014-05-21 03:09:03 | [diff] [blame^] | 29 | class GCMDriver; |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 30 | class GCMProfileService; |
| 31 | } |
| 32 | |
| 33 | namespace extensions { |
| 34 | |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 35 | class ExtensionRegistry; |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 36 | class GcmJsEventRouter; |
| 37 | |
| 38 | // Defines the interface to provide handling logic for a given app. |
| 39 | class ExtensionGCMAppHandler : public gcm::GCMAppHandler, |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 40 | public BrowserContextKeyedAPI, |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 41 | public content::NotificationObserver, |
| 42 | public ExtensionRegistryObserver { |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 43 | public: |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 44 | explicit ExtensionGCMAppHandler(content::BrowserContext* context); |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 45 | virtual ~ExtensionGCMAppHandler(); |
| 46 | |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 47 | // BrowserContextKeyedAPI implementation. |
| 48 | static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* |
| 49 | GetFactoryInstance(); |
| 50 | |
| 51 | // gcm::GCMAppHandler implementation. |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 52 | virtual void ShutdownHandler() OVERRIDE; |
| 53 | virtual void OnMessage( |
| 54 | const std::string& app_id, |
| 55 | const gcm::GCMClient::IncomingMessage& message) OVERRIDE; |
| 56 | virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| 57 | virtual void OnSendError( |
| 58 | const std::string& app_id, |
| 59 | const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; |
| 60 | |
[email protected] | 2ac4673 | 2014-04-03 23:14:31 | [diff] [blame] | 61 | protected: |
| 62 | virtual void OnUnregisterCompleted(const std::string& app_id, |
| 63 | gcm::GCMClient::Result result); |
| 64 | |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 65 | private: |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 66 | friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>; |
| 67 | |
| 68 | // content::NotificationObserver implementation. |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 69 | virtual void Observe(int type, |
| 70 | const content::NotificationSource& source, |
| 71 | const content::NotificationDetails& details) OVERRIDE; |
| 72 | |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 73 | // ExtensionRegistryObserver implementation. |
| 74 | virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 75 | const Extension* extension) OVERRIDE; |
| 76 | virtual void OnExtensionUnloaded( |
| 77 | content::BrowserContext* browser_context, |
| 78 | const Extension* extension, |
| 79 | UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 80 | |
[email protected] | 9d7e5c0 | 2014-05-21 03:09:03 | [diff] [blame^] | 81 | gcm::GCMDriver* GetGCMDriver() const; |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 82 | |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame] | 83 | // BrowserContextKeyedAPI implementation. |
| 84 | static const char* service_name() { return "ExtensionGCMAppHandler"; } |
| 85 | static const bool kServiceIsNULLWhileTesting = true; |
| 86 | |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 87 | Profile* profile_; |
| 88 | content::NotificationRegistrar registrar_; |
| 89 | |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 90 | // Listen to extension load, unloaded notifications. |
| 91 | ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 92 | extension_registry_observer_; |
| 93 | |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 94 | #if !defined(OS_ANDROID) |
| 95 | scoped_ptr<extensions::GcmJsEventRouter> js_event_router_; |
| 96 | #endif |
| 97 | |
| 98 | base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_; |
| 99 | |
| 100 | DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler); |
| 101 | }; |
| 102 | |
| 103 | } // namespace extensions |
| 104 | |
| 105 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ |