| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| 6 #define CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 6 #define CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | |
| 13 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/invalidation/invalidation_logger.h" | 17 #include "chrome/browser/invalidation/invalidation_logger.h" |
| 17 #include "chrome/browser/invalidation/invalidation_service.h" | 18 #include "chrome/browser/invalidation/invalidation_service.h" |
| 19 #include "chrome/browser/invalidation/ticl_invalidation_service_settings_provide
r.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" | |
| 20 #include "google_apis/gaia/identity_provider.h" | 21 #include "google_apis/gaia/identity_provider.h" |
| 21 #include "google_apis/gaia/oauth2_token_service.h" | 22 #include "google_apis/gaia/oauth2_token_service.h" |
| 22 #include "net/base/backoff_entry.h" | 23 #include "net/base/backoff_entry.h" |
| 23 #include "sync/notifier/invalidation_handler.h" | 24 #include "sync/notifier/invalidation_handler.h" |
| 24 #include "sync/notifier/invalidator_registrar.h" | 25 #include "sync/notifier/invalidator_registrar.h" |
| 25 | 26 |
| 26 class Profile; | |
| 27 | |
| 28 namespace gcm { | 27 namespace gcm { |
| 29 class GCMService; | 28 class GCMService; |
| 30 } | 29 } |
| 31 | 30 |
| 32 namespace net { | 31 namespace net { |
| 33 class URLRequestContextGetter; | 32 class URLRequestContextGetter; |
| 34 } | 33 } |
| 35 | 34 |
| 36 namespace syncer { | 35 namespace syncer { |
| 37 class InvalidationStateTracker; | 36 class InvalidationStateTracker; |
| 38 class Invalidator; | 37 class Invalidator; |
| 39 } | 38 } |
| 40 | 39 |
| 41 namespace invalidation { | 40 namespace invalidation { |
| 42 class GCMInvalidationBridge; | 41 class GCMInvalidationBridge; |
| 43 | 42 |
| 44 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. | 43 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. |
| 45 // It provides invalidations for desktop platforms (Win, Mac, Linux). | 44 // It provides invalidations for desktop platforms (Win, Mac, Linux). |
| 46 class TiclInvalidationService : public base::NonThreadSafe, | 45 class TiclInvalidationService |
| 47 public InvalidationService, | 46 : public base::NonThreadSafe, |
| 48 public OAuth2TokenService::Consumer, | 47 public InvalidationService, |
| 49 public OAuth2TokenService::Observer, | 48 public OAuth2TokenService::Consumer, |
| 50 public IdentityProvider::Observer, | 49 public OAuth2TokenService::Observer, |
| 51 public syncer::InvalidationHandler { | 50 public IdentityProvider::Observer, |
| 51 public TiclInvalidationServiceSettingsProvider::Observer, |
| 52 public syncer::InvalidationHandler { |
| 52 public: | 53 public: |
| 53 enum InvalidationNetworkChannel { | 54 enum InvalidationNetworkChannel { |
| 54 PUSH_CLIENT_CHANNEL = 0, | 55 PUSH_CLIENT_CHANNEL = 0, |
| 55 GCM_NETWORK_CHANNEL = 1, | 56 GCM_NETWORK_CHANNEL = 1, |
| 56 | 57 |
| 57 // This enum is used in UMA_HISTOGRAM_ENUMERATION. Insert new values above | 58 // This enum is used in UMA_HISTOGRAM_ENUMERATION. Insert new values above |
| 58 // this line. | 59 // this line. |
| 59 NETWORK_CHANNELS_COUNT = 2 | 60 NETWORK_CHANNELS_COUNT = 2 |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 TiclInvalidationService( | 63 TiclInvalidationService( |
| 63 scoped_ptr<IdentityProvider> identity_provider, | 64 scoped_ptr<IdentityProvider> identity_provider, |
| 65 scoped_ptr<TiclInvalidationServiceSettingsProvider> settings_provider, |
| 64 gcm::GCMService* gcm_service, | 66 gcm::GCMService* gcm_service, |
| 65 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 67 const scoped_refptr<net::URLRequestContextGetter>& request_context); |
| 66 Profile* profile); | |
| 67 virtual ~TiclInvalidationService(); | 68 virtual ~TiclInvalidationService(); |
| 68 | 69 |
| 69 void Init( | 70 void Init( |
| 70 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker); | 71 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker); |
| 71 | 72 |
| 72 // InvalidationService implementation. | 73 // InvalidationService implementation. |
| 73 // It is an error to have registered handlers when Shutdown() is called. | 74 // It is an error to have registered handlers when Shutdown() is called. |
| 74 virtual void RegisterInvalidationHandler( | 75 virtual void RegisterInvalidationHandler( |
| 75 syncer::InvalidationHandler* handler) OVERRIDE; | 76 syncer::InvalidationHandler* handler) OVERRIDE; |
| 76 virtual void UpdateRegisteredInvalidationIds( | 77 virtual void UpdateRegisteredInvalidationIds( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 96 const OAuth2TokenService::Request* request, | 97 const OAuth2TokenService::Request* request, |
| 97 const GoogleServiceAuthError& error) OVERRIDE; | 98 const GoogleServiceAuthError& error) OVERRIDE; |
| 98 | 99 |
| 99 // OAuth2TokenService::Observer implementation | 100 // OAuth2TokenService::Observer implementation |
| 100 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 101 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 101 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 102 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
| 102 | 103 |
| 103 // IdentityProvider::Observer implementation. | 104 // IdentityProvider::Observer implementation. |
| 104 virtual void OnActiveAccountLogout() OVERRIDE; | 105 virtual void OnActiveAccountLogout() OVERRIDE; |
| 105 | 106 |
| 107 // TiclInvalidationServiceSettingsProvider::Observer implementation. |
| 108 virtual void OnUseGCMChannelChanged() OVERRIDE; |
| 109 |
| 106 // syncer::InvalidationHandler implementation. | 110 // syncer::InvalidationHandler implementation. |
| 107 virtual void OnInvalidatorStateChange( | 111 virtual void OnInvalidatorStateChange( |
| 108 syncer::InvalidatorState state) OVERRIDE; | 112 syncer::InvalidatorState state) OVERRIDE; |
| 109 virtual void OnIncomingInvalidation( | 113 virtual void OnIncomingInvalidation( |
| 110 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 114 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| 111 virtual std::string GetOwnerName() const OVERRIDE; | 115 virtual std::string GetOwnerName() const OVERRIDE; |
| 112 | 116 |
| 113 // Overrides KeyedService method. | 117 // Overrides KeyedService method. |
| 114 virtual void Shutdown() OVERRIDE; | 118 virtual void Shutdown() OVERRIDE; |
| 115 | 119 |
| 116 protected: | 120 protected: |
| 117 // Initializes with an injected invalidator. | 121 // Initializes with an injected invalidator. |
| 118 void InitForTest( | 122 void InitForTest( |
| 119 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker, | 123 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker, |
| 120 syncer::Invalidator* invalidator); | 124 syncer::Invalidator* invalidator); |
| 121 | 125 |
| 126 private: |
| 122 friend class TiclInvalidationServiceTestDelegate; | 127 friend class TiclInvalidationServiceTestDelegate; |
| 123 friend class TiclInvalidationServiceChannelTest; | 128 friend class TiclInvalidationServiceProfileSettingsProviderTest; |
| 124 | 129 |
| 125 private: | |
| 126 bool IsReadyToStart(); | 130 bool IsReadyToStart(); |
| 127 bool IsStarted() const; | 131 bool IsStarted() const; |
| 128 | 132 |
| 129 void StartInvalidator(InvalidationNetworkChannel network_channel); | 133 void StartInvalidator(InvalidationNetworkChannel network_channel); |
| 130 void UpdateInvalidationNetworkChannel(); | 134 void UpdateInvalidationNetworkChannel(); |
| 131 void UpdateInvalidatorCredentials(); | 135 void UpdateInvalidatorCredentials(); |
| 132 void StopInvalidator(); | 136 void StopInvalidator(); |
| 133 | 137 |
| 134 Profile *const profile_; | |
| 135 scoped_ptr<IdentityProvider> identity_provider_; | 138 scoped_ptr<IdentityProvider> identity_provider_; |
| 139 scoped_ptr<TiclInvalidationServiceSettingsProvider> settings_provider_; |
| 136 | 140 |
| 137 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 141 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
| 138 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker_; | 142 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker_; |
| 139 scoped_ptr<syncer::Invalidator> invalidator_; | 143 scoped_ptr<syncer::Invalidator> invalidator_; |
| 140 | 144 |
| 141 // TiclInvalidationService needs to remember access token in order to | 145 // TiclInvalidationService needs to remember access token in order to |
| 142 // invalidate it with OAuth2TokenService. | 146 // invalidate it with OAuth2TokenService. |
| 143 std::string access_token_; | 147 std::string access_token_; |
| 144 | 148 |
| 145 // TiclInvalidationService needs to hold reference to access_token_request_ | 149 // TiclInvalidationService needs to hold reference to access_token_request_ |
| 146 // for the duration of request in order to receive callbacks. | 150 // for the duration of request in order to receive callbacks. |
| 147 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 151 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 148 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; | 152 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; |
| 149 net::BackoffEntry request_access_token_backoff_; | 153 net::BackoffEntry request_access_token_backoff_; |
| 150 | 154 |
| 151 PrefChangeRegistrar pref_change_registrar_; | |
| 152 InvalidationNetworkChannel network_channel_type_; | 155 InvalidationNetworkChannel network_channel_type_; |
| 153 gcm::GCMService* gcm_service_; | 156 gcm::GCMService* gcm_service_; |
| 154 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; | 157 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; |
| 155 scoped_refptr<net::URLRequestContextGetter> request_context_; | 158 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 156 | 159 |
| 157 // The invalidation logger object we use to record state changes | 160 // The invalidation logger object we use to record state changes |
| 158 // and invalidations. | 161 // and invalidations. |
| 159 InvalidationLogger logger_; | 162 InvalidationLogger logger_; |
| 160 | 163 |
| 161 // Keep a copy of the important parameters used in network channel creation | 164 // Keep a copy of the important parameters used in network channel creation |
| 162 // for debugging. | 165 // for debugging. |
| 163 base::DictionaryValue network_channel_options_; | 166 base::DictionaryValue network_channel_options_; |
| 164 | 167 |
| 165 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | 168 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); |
| 166 }; | 169 }; |
| 167 | 170 |
| 168 } // namespace invalidation | 171 } // namespace invalidation |
| 169 | 172 |
| 170 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 173 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| OLD | NEW |