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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 class ExtensionRegistry; | 33 class ExtensionRegistry; |
34 class GcmJsEventRouter; | 34 class GcmJsEventRouter; |
35 | 35 |
36 // Defines the interface to provide handling logic for a given app. | 36 // Defines the interface to provide handling logic for a given app. |
37 class ExtensionGCMAppHandler : public gcm::GCMAppHandler, | 37 class ExtensionGCMAppHandler : public gcm::GCMAppHandler, |
38 public BrowserContextKeyedAPI, | 38 public BrowserContextKeyedAPI, |
39 public ExtensionRegistryObserver { | 39 public ExtensionRegistryObserver { |
40 public: | 40 public: |
41 explicit ExtensionGCMAppHandler(content::BrowserContext* context); | 41 explicit ExtensionGCMAppHandler(content::BrowserContext* context); |
42 virtual ~ExtensionGCMAppHandler(); | 42 ~ExtensionGCMAppHandler() override; |
43 | 43 |
44 // BrowserContextKeyedAPI implementation. | 44 // BrowserContextKeyedAPI implementation. |
45 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* | 45 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* |
46 GetFactoryInstance(); | 46 GetFactoryInstance(); |
47 | 47 |
48 // gcm::GCMAppHandler implementation. | 48 // gcm::GCMAppHandler implementation. |
49 virtual void ShutdownHandler() override; | 49 void ShutdownHandler() override; |
50 virtual void OnMessage( | 50 void OnMessage(const std::string& app_id, |
51 const std::string& app_id, | 51 const gcm::GCMClient::IncomingMessage& message) override; |
52 const gcm::GCMClient::IncomingMessage& message) override; | 52 void OnMessagesDeleted(const std::string& app_id) override; |
53 virtual void OnMessagesDeleted(const std::string& app_id) override; | 53 void OnSendError( |
54 virtual void OnSendError( | |
55 const std::string& app_id, | 54 const std::string& app_id, |
56 const gcm::GCMClient::SendErrorDetails& send_error_details) override; | 55 const gcm::GCMClient::SendErrorDetails& send_error_details) override; |
57 virtual void OnSendAcknowledged(const std::string& app_id, | 56 void OnSendAcknowledged(const std::string& app_id, |
58 const std::string& message_id) override; | 57 const std::string& message_id) override; |
59 | 58 |
60 protected: | 59 protected: |
61 // Could be overridden by testing purpose. | 60 // Could be overridden by testing purpose. |
62 virtual void OnUnregisterCompleted(const std::string& app_id, | 61 virtual void OnUnregisterCompleted(const std::string& app_id, |
63 gcm::GCMClient::Result result); | 62 gcm::GCMClient::Result result); |
64 virtual void AddAppHandler(const std::string& app_id); | 63 virtual void AddAppHandler(const std::string& app_id); |
65 virtual void RemoveAppHandler(const std::string& app_id); | 64 virtual void RemoveAppHandler(const std::string& app_id); |
66 | 65 |
67 gcm::GCMDriver* GetGCMDriver() const; | 66 gcm::GCMDriver* GetGCMDriver() const; |
68 | 67 |
69 private: | 68 private: |
70 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>; | 69 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>; |
71 | 70 |
72 // ExtensionRegistryObserver implementation. | 71 // ExtensionRegistryObserver implementation. |
73 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 72 void OnExtensionLoaded(content::BrowserContext* browser_context, |
74 const Extension* extension) override; | 73 const Extension* extension) override; |
75 virtual void OnExtensionUnloaded( | 74 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
76 content::BrowserContext* browser_context, | 75 const Extension* extension, |
77 const Extension* extension, | 76 UnloadedExtensionInfo::Reason reason) override; |
78 UnloadedExtensionInfo::Reason reason) override; | 77 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
79 virtual void OnExtensionUninstalled( | 78 const Extension* extension, |
80 content::BrowserContext* browser_context, | 79 extensions::UninstallReason reason) override; |
81 const Extension* extension, | |
82 extensions::UninstallReason reason) override; | |
83 | 80 |
84 void AddDummyAppHandler(); | 81 void AddDummyAppHandler(); |
85 void RemoveDummyAppHandler(); | 82 void RemoveDummyAppHandler(); |
86 | 83 |
87 // BrowserContextKeyedAPI implementation. | 84 // BrowserContextKeyedAPI implementation. |
88 static const char* service_name() { return "ExtensionGCMAppHandler"; } | 85 static const char* service_name() { return "ExtensionGCMAppHandler"; } |
89 static const bool kServiceIsNULLWhileTesting = true; | 86 static const bool kServiceIsNULLWhileTesting = true; |
90 | 87 |
91 Profile* profile_; | 88 Profile* profile_; |
92 | 89 |
93 // Listen to extension load, unloaded notifications. | 90 // Listen to extension load, unloaded notifications. |
94 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 91 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
95 extension_registry_observer_; | 92 extension_registry_observer_; |
96 | 93 |
97 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_; | 94 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_; |
98 | 95 |
99 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_; | 96 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_; |
100 | 97 |
101 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler); | 98 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler); |
102 }; | 99 }; |
103 | 100 |
104 } // namespace extensions | 101 } // namespace extensions |
105 | 102 |
106 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_ |
OLD | NEW |