Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h" | 14 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h" |
| 15 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler_delegate.h" | 15 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler_delegate.h" |
| 16 #include "chrome/browser/extensions/event_router.h" | |
| 16 #include "chrome/browser/extensions/extension_function.h" | 17 #include "chrome/browser/extensions/extension_function.h" |
| 18 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 17 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 18 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 20 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
| 21 | 23 |
| 22 class Profile; | 24 class Profile; |
| 23 | 25 |
| 24 namespace extensions { | 26 namespace extensions { |
| 25 | 27 |
| 26 class PushMessagingInvalidationMapper; | 28 class PushMessagingInvalidationMapper; |
| 27 class ObfuscatedGaiaIdFetcher; | 29 class ObfuscatedGaiaIdFetcher; |
| 28 | 30 |
| 29 // Observes a single InvalidationHandler and generates onMessage events. | 31 // Observes a single InvalidationHandler and generates onMessage events. |
| 30 class PushMessagingEventRouter | 32 class PushMessagingEventRouter |
| 31 : public PushMessagingInvalidationHandlerDelegate, | 33 : public PushMessagingInvalidationHandlerDelegate, |
| 32 public content::NotificationObserver { | 34 public content::NotificationObserver { |
| 33 public: | 35 public: |
| 34 explicit PushMessagingEventRouter(Profile* profile); | 36 explicit PushMessagingEventRouter(Profile* profile); |
| 35 virtual ~PushMessagingEventRouter(); | 37 virtual ~PushMessagingEventRouter(); |
| 36 | 38 |
| 37 void Shutdown(); | |
| 38 | |
| 39 PushMessagingInvalidationMapper* GetMapperForTest() const { | 39 PushMessagingInvalidationMapper* GetMapperForTest() const { |
| 40 return handler_.get(); | 40 return handler_.get(); |
| 41 } | 41 } |
| 42 void SetMapperForTest(scoped_ptr<PushMessagingInvalidationMapper> mapper); | 42 void SetMapperForTest(scoped_ptr<PushMessagingInvalidationMapper> mapper); |
| 43 void TriggerMessageForTest(const std::string& extension_id, | 43 void TriggerMessageForTest(const std::string& extension_id, |
| 44 int subchannel, | 44 int subchannel, |
| 45 const std::string& payload); | 45 const std::string& payload); |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 // InvalidationHandlerDelegate implementation. | 48 // InvalidationHandlerDelegate implementation. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 virtual void OnObfuscatedGaiaIdFetchSuccess(const std::string& gaia_id) | 97 virtual void OnObfuscatedGaiaIdFetchSuccess(const std::string& gaia_id) |
| 98 OVERRIDE; | 98 OVERRIDE; |
| 99 virtual void OnObfuscatedGaiaIdFetchFailure( | 99 virtual void OnObfuscatedGaiaIdFetchFailure( |
| 100 const GoogleServiceAuthError& error) OVERRIDE; | 100 const GoogleServiceAuthError& error) OVERRIDE; |
| 101 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_; | 101 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_; |
| 102 bool interactive_; | 102 bool interactive_; |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); | 104 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class PushMessagingAPI : public ProfileKeyedService, | |
| 108 public extensions::EventRouter::Observer { | |
| 109 public: | |
| 110 explicit PushMessagingAPI(Profile* profile); | |
| 111 virtual ~PushMessagingAPI(); | |
| 112 | |
| 113 // Convenience method to get the PushMessagingAPI for a profile. | |
| 114 static PushMessagingAPI* Get(Profile* profile); | |
| 115 | |
| 116 // ProfileKeyedService implementation. | |
| 117 virtual void Shutdown() OVERRIDE; | |
| 118 | |
| 119 // EventRouter::Observer implementation. | |
| 120 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) | |
| 121 OVERRIDE; | |
| 122 | |
| 123 // For testing purpose. | |
|
Yoyo Zhou
2012/12/11 22:07:27
nit: purposes
Joe Thomas
2012/12/12 02:39:27
Done.
| |
| 124 void InitializePushMessagingEventRouterForTest(); | |
| 125 PushMessagingEventRouter* GetPushMessagingEventRouterForTest(); | |
| 126 private: | |
| 127 Profile* profile_; | |
| 128 | |
| 129 // Created lazily upon OnListenerAdded. | |
| 130 scoped_ptr<PushMessagingEventRouter> push_messaging_event_router_; | |
| 131 }; | |
| 132 | |
| 107 } // namespace extension | 133 } // namespace extension |
| 108 | 134 |
| 109 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 135 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| OLD | NEW |