| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // For testing purposes. | 39 // For testing purposes. |
| 40 void TriggerMessageForTest(const std::string& extension_id, | 40 void TriggerMessageForTest(const std::string& extension_id, |
| 41 int subchannel, | 41 int subchannel, |
| 42 const std::string& payload); | 42 const std::string& payload); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 // InvalidationHandlerDelegate implementation. | 45 // InvalidationHandlerDelegate implementation. |
| 46 virtual void OnMessage(const std::string& extension_id, | 46 virtual void OnMessage(const std::string& extension_id, |
| 47 int subchannel, | 47 int subchannel, |
| 48 const std::string& payload) OVERRIDE; | 48 const std::string& payload) override; |
| 49 | 49 |
| 50 content::BrowserContext* const browser_context_; | 50 content::BrowserContext* const browser_context_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); | 52 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class PushMessagingGetChannelIdFunction | 55 class PushMessagingGetChannelIdFunction |
| 56 : public ChromeAsyncExtensionFunction, | 56 : public ChromeAsyncExtensionFunction, |
| 57 public ObfuscatedGaiaIdFetcher::Delegate, | 57 public ObfuscatedGaiaIdFetcher::Delegate, |
| 58 public OAuth2TokenService::Observer, | 58 public OAuth2TokenService::Observer, |
| 59 public OAuth2TokenService::Consumer { | 59 public OAuth2TokenService::Consumer { |
| 60 public: | 60 public: |
| 61 PushMessagingGetChannelIdFunction(); | 61 PushMessagingGetChannelIdFunction(); |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 virtual ~PushMessagingGetChannelIdFunction(); | 64 virtual ~PushMessagingGetChannelIdFunction(); |
| 65 | 65 |
| 66 // ExtensionFunction: | 66 // ExtensionFunction: |
| 67 virtual bool RunAsync() OVERRIDE; | 67 virtual bool RunAsync() override; |
| 68 DECLARE_EXTENSION_FUNCTION("pushMessaging.getChannelId", | 68 DECLARE_EXTENSION_FUNCTION("pushMessaging.getChannelId", |
| 69 PUSHMESSAGING_GETCHANNELID) | 69 PUSHMESSAGING_GETCHANNELID) |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 void ReportResult(const std::string& gaia_id, | 72 void ReportResult(const std::string& gaia_id, |
| 73 const std::string& error_message); | 73 const std::string& error_message); |
| 74 | 74 |
| 75 void BuildAndSendResult(const std::string& gaia_id, | 75 void BuildAndSendResult(const std::string& gaia_id, |
| 76 const std::string& error_message); | 76 const std::string& error_message); |
| 77 | 77 |
| 78 // Begin the async fetch of the Gaia ID. | 78 // Begin the async fetch of the Gaia ID. |
| 79 void StartGaiaIdFetch(const std::string& access_token); | 79 void StartGaiaIdFetch(const std::string& access_token); |
| 80 | 80 |
| 81 // Begin the async fetch of the access token for Gaia ID fetcher. | 81 // Begin the async fetch of the access token for Gaia ID fetcher. |
| 82 void StartAccessTokenFetch(); | 82 void StartAccessTokenFetch(); |
| 83 | 83 |
| 84 // OAuth2TokenService::Observer implementation. | 84 // OAuth2TokenService::Observer implementation. |
| 85 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 85 virtual void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 86 | 86 |
| 87 // OAuth2TokenService::Consumer implementation. | 87 // OAuth2TokenService::Consumer implementation. |
| 88 virtual void OnGetTokenSuccess( | 88 virtual void OnGetTokenSuccess( |
| 89 const OAuth2TokenService::Request* request, | 89 const OAuth2TokenService::Request* request, |
| 90 const std::string& access_token, | 90 const std::string& access_token, |
| 91 const base::Time& expiration_time) OVERRIDE; | 91 const base::Time& expiration_time) override; |
| 92 virtual void OnGetTokenFailure( | 92 virtual void OnGetTokenFailure( |
| 93 const OAuth2TokenService::Request* request, | 93 const OAuth2TokenService::Request* request, |
| 94 const GoogleServiceAuthError& error) OVERRIDE; | 94 const GoogleServiceAuthError& error) override; |
| 95 | 95 |
| 96 // ObfuscatedGiaiaIdFetcher::Delegate implementation. | 96 // ObfuscatedGiaiaIdFetcher::Delegate implementation. |
| 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 | 101 |
| 102 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_; | 102 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_; |
| 103 bool interactive_; | 103 bool interactive_; |
| 104 scoped_ptr<OAuth2TokenService::Request> fetcher_access_token_request_; | 104 scoped_ptr<OAuth2TokenService::Request> fetcher_access_token_request_; |
| 105 | 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); | 106 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 class PushMessagingAPI : public BrowserContextKeyedAPI, | 109 class PushMessagingAPI : public BrowserContextKeyedAPI, |
| 110 public ExtensionRegistryObserver { | 110 public ExtensionRegistryObserver { |
| 111 public: | 111 public: |
| 112 explicit PushMessagingAPI(content::BrowserContext* context); | 112 explicit PushMessagingAPI(content::BrowserContext* context); |
| 113 virtual ~PushMessagingAPI(); | 113 virtual ~PushMessagingAPI(); |
| 114 | 114 |
| 115 // Convenience method to get the PushMessagingAPI for a BrowserContext. | 115 // Convenience method to get the PushMessagingAPI for a BrowserContext. |
| 116 static PushMessagingAPI* Get(content::BrowserContext* context); | 116 static PushMessagingAPI* Get(content::BrowserContext* context); |
| 117 | 117 |
| 118 // KeyedService implementation. | 118 // KeyedService implementation. |
| 119 virtual void Shutdown() OVERRIDE; | 119 virtual void Shutdown() override; |
| 120 | 120 |
| 121 // BrowserContextKeyedAPI implementation. | 121 // BrowserContextKeyedAPI implementation. |
| 122 static BrowserContextKeyedAPIFactory<PushMessagingAPI>* GetFactoryInstance(); | 122 static BrowserContextKeyedAPIFactory<PushMessagingAPI>* GetFactoryInstance(); |
| 123 | 123 |
| 124 // For testing purposes. | 124 // For testing purposes. |
| 125 PushMessagingEventRouter* GetEventRouterForTest() const { | 125 PushMessagingEventRouter* GetEventRouterForTest() const { |
| 126 return event_router_.get(); | 126 return event_router_.get(); |
| 127 } | 127 } |
| 128 PushMessagingInvalidationMapper* GetMapperForTest() const { | 128 PushMessagingInvalidationMapper* GetMapperForTest() const { |
| 129 return handler_.get(); | 129 return handler_.get(); |
| 130 } | 130 } |
| 131 void SetMapperForTest(scoped_ptr<PushMessagingInvalidationMapper> mapper); | 131 void SetMapperForTest(scoped_ptr<PushMessagingInvalidationMapper> mapper); |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 friend class BrowserContextKeyedAPIFactory<PushMessagingAPI>; | 134 friend class BrowserContextKeyedAPIFactory<PushMessagingAPI>; |
| 135 | 135 |
| 136 // BrowserContextKeyedAPI implementation. | 136 // BrowserContextKeyedAPI implementation. |
| 137 static const char* service_name() { | 137 static const char* service_name() { |
| 138 return "PushMessagingAPI"; | 138 return "PushMessagingAPI"; |
| 139 } | 139 } |
| 140 static const bool kServiceIsNULLWhileTesting = true; | 140 static const bool kServiceIsNULLWhileTesting = true; |
| 141 | 141 |
| 142 // Overridden from ExtensionRegistryObserver. | 142 // Overridden from ExtensionRegistryObserver. |
| 143 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 143 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 144 const Extension* extension) OVERRIDE; | 144 const Extension* extension) override; |
| 145 virtual void OnExtensionUnloaded( | 145 virtual void OnExtensionUnloaded( |
| 146 content::BrowserContext* browser_context, | 146 content::BrowserContext* browser_context, |
| 147 const Extension* extension, | 147 const Extension* extension, |
| 148 UnloadedExtensionInfo::Reason reason) OVERRIDE; | 148 UnloadedExtensionInfo::Reason reason) override; |
| 149 virtual void OnExtensionWillBeInstalled( | 149 virtual void OnExtensionWillBeInstalled( |
| 150 content::BrowserContext* browser_context, | 150 content::BrowserContext* browser_context, |
| 151 const Extension* extension, | 151 const Extension* extension, |
| 152 bool is_update, | 152 bool is_update, |
| 153 bool from_ephemeral, | 153 bool from_ephemeral, |
| 154 const std::string& old_name) OVERRIDE; | 154 const std::string& old_name) override; |
| 155 | 155 |
| 156 // Initialize |event_router_| and |handler_|. | 156 // Initialize |event_router_| and |handler_|. |
| 157 bool InitEventRouterAndHandler(); | 157 bool InitEventRouterAndHandler(); |
| 158 | 158 |
| 159 // Created lazily when an app or extension with the push messaging permission | 159 // Created lazily when an app or extension with the push messaging permission |
| 160 // is loaded. | 160 // is loaded. |
| 161 scoped_ptr<PushMessagingEventRouter> event_router_; | 161 scoped_ptr<PushMessagingEventRouter> event_router_; |
| 162 scoped_ptr<PushMessagingInvalidationMapper> handler_; | 162 scoped_ptr<PushMessagingInvalidationMapper> handler_; |
| 163 | 163 |
| 164 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 164 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 165 extension_registry_observer_; | 165 extension_registry_observer_; |
| 166 | 166 |
| 167 content::BrowserContext* browser_context_; | 167 content::BrowserContext* browser_context_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(PushMessagingAPI); | 169 DISALLOW_COPY_AND_ASSIGN(PushMessagingAPI); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 template <> | 172 template <> |
| 173 void BrowserContextKeyedAPIFactory< | 173 void BrowserContextKeyedAPIFactory< |
| 174 PushMessagingAPI>::DeclareFactoryDependencies(); | 174 PushMessagingAPI>::DeclareFactoryDependencies(); |
| 175 | 175 |
| 176 } // namespace extensions | 176 } // namespace extensions |
| 177 | 177 |
| 178 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 178 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| OLD | NEW |