[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 | |
| 8 | #include "base/memory/scoped_ptr.h" |
| 9 | #include "base/memory/weak_ptr.h" |
| 10 | #include "chrome/browser/services/gcm/gcm_app_handler.h" |
| 11 | #include "content/public/browser/notification_observer.h" |
| 12 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 13 | #include "extensions/browser/browser_context_keyed_api_factory.h" |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 14 | #include "google_apis/gcm/gcm_client.h" |
| 15 | |
| 16 | class Profile; |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 17 | namespace content { |
| 18 | class BrowserContext; |
| 19 | } |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 20 | namespace gcm { |
| 21 | class GCMProfileService; |
| 22 | } |
| 23 | |
| 24 | namespace extensions { |
| 25 | |
| 26 | class GcmJsEventRouter; |
| 27 | |
| 28 | // Defines the interface to provide handling logic for a given app. |
| 29 | class ExtensionGCMAppHandler : public gcm::GCMAppHandler, |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 30 | public BrowserContextKeyedAPI, |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 31 | public content::NotificationObserver { |
| 32 | public: |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 33 | explicit ExtensionGCMAppHandler(content::BrowserContext* context); |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 34 | virtual ~ExtensionGCMAppHandler(); |
| 35 | |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 36 | // BrowserContextKeyedAPI implementation. |
| 37 | static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* |
| 38 | GetFactoryInstance(); |
| 39 | |
| 40 | // gcm::GCMAppHandler implementation. |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 41 | virtual void ShutdownHandler() OVERRIDE; |
| 42 | virtual void OnMessage( |
| 43 | const std::string& app_id, |
| 44 | const gcm::GCMClient::IncomingMessage& message) OVERRIDE; |
| 45 | virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| 46 | virtual void OnSendError( |
| 47 | const std::string& app_id, |
| 48 | const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; |
| 49 | |
| 50 | private: |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 51 | friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>; |
| 52 | |
| 53 | // content::NotificationObserver implementation. |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 54 | virtual void Observe(int type, |
| 55 | const content::NotificationSource& source, |
| 56 | const content::NotificationDetails& details) OVERRIDE; |
| 57 | |
| 58 | gcm::GCMProfileService* GetGCMProfileService() const; |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 59 | void OnUnregisterCompleted(const std::string& app_id, |
| 60 | gcm::GCMClient::Result result); |
| 61 | |
[email protected] | 2f361704 | 2014-03-21 22:44:36 | [diff] [blame^] | 62 | // BrowserContextKeyedAPI implementation. |
| 63 | static const char* service_name() { return "ExtensionGCMAppHandler"; } |
| 64 | static const bool kServiceIsNULLWhileTesting = true; |
| 65 | |
[email protected] | 240fc7e | 2014-03-20 06:52:20 | [diff] [blame] | 66 | Profile* profile_; |
| 67 | content::NotificationRegistrar registrar_; |
| 68 | |
| 69 | #if !defined(OS_ANDROID) |
| 70 | scoped_ptr<extensions::GcmJsEventRouter> js_event_router_; |
| 71 | #endif |
| 72 | |
| 73 | base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_; |
| 74 | |
| 75 | DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler); |
| 76 | }; |
| 77 | |
| 78 | } // namespace extensions |
| 79 | |
| 80 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ |