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