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