| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/threading/non_thread_safe.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 #include "base/values.h" | |
| 17 #include "components/invalidation/invalidation_logger.h" | |
| 18 #include "components/invalidation/invalidation_service.h" | |
| 19 #include "components/invalidation/invalidator_registrar.h" | |
| 20 #include "components/invalidation/ticl_settings_provider.h" | |
| 21 #include "components/keyed_service/core/keyed_service.h" | |
| 22 #include "google_apis/gaia/identity_provider.h" | |
| 23 #include "google_apis/gaia/oauth2_token_service.h" | |
| 24 #include "net/base/backoff_entry.h" | |
| 25 #include "sync/notifier/invalidation_handler.h" | |
| 26 | |
| 27 namespace gcm { | |
| 28 class GCMDriver; | |
| 29 } | |
| 30 | |
| 31 namespace net { | |
| 32 class URLRequestContextGetter; | |
| 33 } | |
| 34 | |
| 35 namespace syncer { | |
| 36 class InvalidationStateTracker; | |
| 37 class Invalidator; | |
| 38 } | |
| 39 | |
| 40 namespace invalidation { | |
| 41 class GCMInvalidationBridge; | |
| 42 | |
| 43 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. | |
| 44 // It provides invalidations for desktop platforms (Win, Mac, Linux). | |
| 45 class TiclInvalidationService : public base::NonThreadSafe, | |
| 46 public InvalidationService, | |
| 47 public OAuth2TokenService::Consumer, | |
| 48 public OAuth2TokenService::Observer, | |
| 49 public IdentityProvider::Observer, | |
| 50 public TiclSettingsProvider::Observer, | |
| 51 public syncer::InvalidationHandler { | |
| 52 public: | |
| 53 enum InvalidationNetworkChannel { | |
| 54 PUSH_CLIENT_CHANNEL = 0, | |
| 55 GCM_NETWORK_CHANNEL = 1, | |
| 56 | |
| 57 // This enum is used in UMA_HISTOGRAM_ENUMERATION. Insert new values above | |
| 58 // this line. | |
| 59 NETWORK_CHANNELS_COUNT = 2 | |
| 60 }; | |
| 61 | |
| 62 TiclInvalidationService( | |
| 63 scoped_ptr<IdentityProvider> identity_provider, | |
| 64 scoped_ptr<TiclSettingsProvider> settings_provider, | |
| 65 gcm::GCMDriver* gcm_driver, | |
| 66 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
| 67 virtual ~TiclInvalidationService(); | |
| 68 | |
| 69 void Init( | |
| 70 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker); | |
| 71 | |
| 72 // InvalidationService implementation. | |
| 73 // It is an error to have registered handlers when the service is destroyed. | |
| 74 virtual void RegisterInvalidationHandler( | |
| 75 syncer::InvalidationHandler* handler) OVERRIDE; | |
| 76 virtual void UpdateRegisteredInvalidationIds( | |
| 77 syncer::InvalidationHandler* handler, | |
| 78 const syncer::ObjectIdSet& ids) OVERRIDE; | |
| 79 virtual void UnregisterInvalidationHandler( | |
| 80 syncer::InvalidationHandler* handler) OVERRIDE; | |
| 81 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | |
| 82 virtual std::string GetInvalidatorClientId() const OVERRIDE; | |
| 83 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; | |
| 84 virtual void RequestDetailedStatus( | |
| 85 base::Callback<void(const base::DictionaryValue&)> caller) const OVERRIDE; | |
| 86 virtual IdentityProvider* GetIdentityProvider() OVERRIDE; | |
| 87 | |
| 88 void RequestAccessToken(); | |
| 89 | |
| 90 // OAuth2TokenService::Consumer implementation | |
| 91 virtual void OnGetTokenSuccess( | |
| 92 const OAuth2TokenService::Request* request, | |
| 93 const std::string& access_token, | |
| 94 const base::Time& expiration_time) OVERRIDE; | |
| 95 virtual void OnGetTokenFailure( | |
| 96 const OAuth2TokenService::Request* request, | |
| 97 const GoogleServiceAuthError& error) OVERRIDE; | |
| 98 | |
| 99 // OAuth2TokenService::Observer implementation | |
| 100 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | |
| 101 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | |
| 102 | |
| 103 // IdentityProvider::Observer implementation. | |
| 104 virtual void OnActiveAccountLogout() OVERRIDE; | |
| 105 | |
| 106 // TiclSettingsProvider::Observer implementation. | |
| 107 virtual void OnUseGCMChannelChanged() OVERRIDE; | |
| 108 | |
| 109 // syncer::InvalidationHandler implementation. | |
| 110 virtual void OnInvalidatorStateChange( | |
| 111 syncer::InvalidatorState state) OVERRIDE; | |
| 112 virtual void OnIncomingInvalidation( | |
| 113 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | |
| 114 virtual std::string GetOwnerName() const OVERRIDE; | |
| 115 | |
| 116 protected: | |
| 117 // Initializes with an injected invalidator. | |
| 118 void InitForTest( | |
| 119 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker, | |
| 120 syncer::Invalidator* invalidator); | |
| 121 | |
| 122 private: | |
| 123 friend class TiclInvalidationServiceTestDelegate; | |
| 124 friend class TiclProfileSettingsProviderTest; | |
| 125 | |
| 126 bool IsReadyToStart(); | |
| 127 bool IsStarted() const; | |
| 128 | |
| 129 void StartInvalidator(InvalidationNetworkChannel network_channel); | |
| 130 void UpdateInvalidationNetworkChannel(); | |
| 131 void UpdateInvalidatorCredentials(); | |
| 132 void StopInvalidator(); | |
| 133 | |
| 134 scoped_ptr<IdentityProvider> identity_provider_; | |
| 135 scoped_ptr<TiclSettingsProvider> settings_provider_; | |
| 136 | |
| 137 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | |
| 138 scoped_ptr<syncer::InvalidationStateTracker> invalidation_state_tracker_; | |
| 139 scoped_ptr<syncer::Invalidator> invalidator_; | |
| 140 | |
| 141 // TiclInvalidationService needs to remember access token in order to | |
| 142 // invalidate it with OAuth2TokenService. | |
| 143 std::string access_token_; | |
| 144 | |
| 145 // TiclInvalidationService needs to hold reference to access_token_request_ | |
| 146 // for the duration of request in order to receive callbacks. | |
| 147 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | |
| 148 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; | |
| 149 net::BackoffEntry request_access_token_backoff_; | |
| 150 | |
| 151 InvalidationNetworkChannel network_channel_type_; | |
| 152 gcm::GCMDriver* gcm_driver_; | |
| 153 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; | |
| 154 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 155 | |
| 156 // The invalidation logger object we use to record state changes | |
| 157 // and invalidations. | |
| 158 InvalidationLogger logger_; | |
| 159 | |
| 160 // Keep a copy of the important parameters used in network channel creation | |
| 161 // for debugging. | |
| 162 base::DictionaryValue network_channel_options_; | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | |
| 165 }; | |
| 166 | |
| 167 } // namespace invalidation | |
| 168 | |
| 169 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | |
| OLD | NEW |