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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_observer.h"
15 #include "chrome/browser/services/gcm/gcm_app_handler.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/browser_context_keyed_api_factory.h"
19 #include "extensions/browser/extension_registry_observer.h"
20 #include "google_apis/gcm/gcm_client.h"
29 class GCMProfileService
;
32 namespace extensions
{
34 class ExtensionRegistry
;
35 class GcmJsEventRouter
;
37 // Defines the interface to provide handling logic for a given app.
38 class ExtensionGCMAppHandler
: public gcm::GCMAppHandler
,
39 public BrowserContextKeyedAPI
,
40 public content::NotificationObserver
,
41 public ExtensionRegistryObserver
{
43 explicit ExtensionGCMAppHandler(content::BrowserContext
* context
);
44 virtual ~ExtensionGCMAppHandler();
46 // BrowserContextKeyedAPI implementation.
47 static BrowserContextKeyedAPIFactory
<ExtensionGCMAppHandler
>*
50 // gcm::GCMAppHandler implementation.
51 virtual void ShutdownHandler() OVERRIDE
;
52 virtual void OnMessage(
53 const std::string
& app_id
,
54 const gcm::GCMClient::IncomingMessage
& message
) OVERRIDE
;
55 virtual void OnMessagesDeleted(const std::string
& app_id
) OVERRIDE
;
56 virtual void OnSendError(
57 const std::string
& app_id
,
58 const gcm::GCMClient::SendErrorDetails
& send_error_details
) OVERRIDE
;
61 virtual void OnUnregisterCompleted(const std::string
& app_id
,
62 gcm::GCMClient::Result result
);
65 friend class BrowserContextKeyedAPIFactory
<ExtensionGCMAppHandler
>;
67 // content::NotificationObserver implementation.
68 virtual void Observe(int type
,
69 const content::NotificationSource
& source
,
70 const content::NotificationDetails
& details
) OVERRIDE
;
72 // ExtensionRegistryObserver implementation.
73 virtual void OnExtensionLoaded(content::BrowserContext
* browser_context
,
74 const Extension
* extension
) OVERRIDE
;
75 virtual void OnExtensionUnloaded(
76 content::BrowserContext
* browser_context
,
77 const Extension
* extension
,
78 UnloadedExtensionInfo::Reason reason
) OVERRIDE
;
80 gcm::GCMProfileService
* GetGCMProfileService() const;
82 // BrowserContextKeyedAPI implementation.
83 static const char* service_name() { return "ExtensionGCMAppHandler"; }
84 static const bool kServiceIsNULLWhileTesting
= true;
87 content::NotificationRegistrar registrar_
;
89 // Listen to extension load, unloaded notifications.
90 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
>
91 extension_registry_observer_
;
93 #if !defined(OS_ANDROID)
94 scoped_ptr
<extensions::GcmJsEventRouter
> js_event_router_
;
97 base::WeakPtrFactory
<ExtensionGCMAppHandler
> weak_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler
);
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_