| 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> |
| 9 |
| 8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 10 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/invalidation/invalidation_auth_provider.h" |
| 11 #include "chrome/browser/invalidation/invalidation_logger.h" | 14 #include "chrome/browser/invalidation/invalidation_logger.h" |
| 12 #include "chrome/browser/invalidation/invalidation_service.h" | 15 #include "chrome/browser/invalidation/invalidation_service.h" |
| 13 #include "chrome/browser/invalidation/invalidator_storage.h" | 16 #include "chrome/browser/invalidation/invalidator_storage.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" | |
| 15 #include "chrome/browser/signin/signin_manager.h" | |
| 16 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "google_apis/gaia/oauth2_token_service.h" | 18 #include "google_apis/gaia/oauth2_token_service.h" |
| 18 #include "net/base/backoff_entry.h" | 19 #include "net/base/backoff_entry.h" |
| 19 #include "sync/notifier/invalidation_handler.h" | 20 #include "sync/notifier/invalidation_handler.h" |
| 20 #include "sync/notifier/invalidator_registrar.h" | 21 #include "sync/notifier/invalidator_registrar.h" |
| 21 | 22 |
| 22 class Profile; | 23 class Profile; |
| 23 | 24 |
| 24 namespace syncer { | 25 namespace syncer { |
| 25 class Invalidator; | 26 class Invalidator; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace invalidation { | 29 namespace invalidation { |
| 29 class GCMInvalidationBridge; | 30 class GCMInvalidationBridge; |
| 30 | 31 |
| 31 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. | 32 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. |
| 32 // It provides invalidations for desktop platforms (Win, Mac, Linux). | 33 // It provides invalidations for desktop platforms (Win, Mac, Linux). |
| 33 class TiclInvalidationService : public base::NonThreadSafe, | 34 class TiclInvalidationService : public base::NonThreadSafe, |
| 34 public InvalidationService, | 35 public InvalidationService, |
| 35 public OAuth2TokenService::Consumer, | 36 public OAuth2TokenService::Consumer, |
| 36 public OAuth2TokenService::Observer, | 37 public OAuth2TokenService::Observer, |
| 37 public SigninManagerBase::Observer, | 38 public InvalidationAuthProvider::Observer, |
| 38 public syncer::InvalidationHandler { | 39 public syncer::InvalidationHandler { |
| 39 public: | 40 public: |
| 40 TiclInvalidationService(SigninManagerBase* signin, | 41 TiclInvalidationService(scoped_ptr<InvalidationAuthProvider> auth_provider, |
| 41 ProfileOAuth2TokenService* oauth2_token_service, | |
| 42 Profile* profile); | 42 Profile* profile); |
| 43 virtual ~TiclInvalidationService(); | 43 virtual ~TiclInvalidationService(); |
| 44 | 44 |
| 45 void Init(); | 45 void Init(); |
| 46 | 46 |
| 47 // InvalidationService implementation. | 47 // InvalidationService implementation. |
| 48 // It is an error to have registered handlers when Shutdown() is called. | 48 // It is an error to have registered handlers when Shutdown() is called. |
| 49 virtual void RegisterInvalidationHandler( | 49 virtual void RegisterInvalidationHandler( |
| 50 syncer::InvalidationHandler* handler) OVERRIDE; | 50 syncer::InvalidationHandler* handler) OVERRIDE; |
| 51 virtual void UpdateRegisteredInvalidationIds( | 51 virtual void UpdateRegisteredInvalidationIds( |
| 52 syncer::InvalidationHandler* handler, | 52 syncer::InvalidationHandler* handler, |
| 53 const syncer::ObjectIdSet& ids) OVERRIDE; | 53 const syncer::ObjectIdSet& ids) OVERRIDE; |
| 54 virtual void UnregisterInvalidationHandler( | 54 virtual void UnregisterInvalidationHandler( |
| 55 syncer::InvalidationHandler* handler) OVERRIDE; | 55 syncer::InvalidationHandler* handler) OVERRIDE; |
| 56 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 56 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
| 57 virtual std::string GetInvalidatorClientId() const OVERRIDE; | 57 virtual std::string GetInvalidatorClientId() const OVERRIDE; |
| 58 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; | 58 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; |
| 59 virtual void RequestDetailedStatus( | 59 virtual void RequestDetailedStatus( |
| 60 base::Callback<void(const base::DictionaryValue&)> caller) OVERRIDE; | 60 base::Callback<void(const base::DictionaryValue&)> caller) OVERRIDE; |
| 61 virtual InvalidationAuthProvider* GetInvalidationAuthProvider() OVERRIDE; |
| 61 | 62 |
| 62 void RequestAccessToken(); | 63 void RequestAccessToken(); |
| 63 | 64 |
| 64 // OAuth2TokenService::Consumer implementation | 65 // OAuth2TokenService::Consumer implementation |
| 65 virtual void OnGetTokenSuccess( | 66 virtual void OnGetTokenSuccess( |
| 66 const OAuth2TokenService::Request* request, | 67 const OAuth2TokenService::Request* request, |
| 67 const std::string& access_token, | 68 const std::string& access_token, |
| 68 const base::Time& expiration_time) OVERRIDE; | 69 const base::Time& expiration_time) OVERRIDE; |
| 69 virtual void OnGetTokenFailure( | 70 virtual void OnGetTokenFailure( |
| 70 const OAuth2TokenService::Request* request, | 71 const OAuth2TokenService::Request* request, |
| 71 const GoogleServiceAuthError& error) OVERRIDE; | 72 const GoogleServiceAuthError& error) OVERRIDE; |
| 72 | 73 |
| 73 // OAuth2TokenService::Observer implementation | 74 // OAuth2TokenService::Observer implementation |
| 74 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 75 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 75 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 76 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
| 76 | 77 |
| 77 // SigninManagerBase::Observer implementation. | 78 // InvalidationAuthProvider::Observer implementation. |
| 78 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 79 virtual void OnInvalidationAuthLogout() OVERRIDE; |
| 79 | 80 |
| 80 // syncer::InvalidationHandler implementation. | 81 // syncer::InvalidationHandler implementation. |
| 81 virtual void OnInvalidatorStateChange( | 82 virtual void OnInvalidatorStateChange( |
| 82 syncer::InvalidatorState state) OVERRIDE; | 83 syncer::InvalidatorState state) OVERRIDE; |
| 83 virtual void OnIncomingInvalidation( | 84 virtual void OnIncomingInvalidation( |
| 84 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 85 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| 85 virtual std::string GetOwnerName() const OVERRIDE; | 86 virtual std::string GetOwnerName() const OVERRIDE; |
| 86 | 87 |
| 87 // Overrides KeyedService method. | 88 // Overrides KeyedService method. |
| 88 virtual void Shutdown() OVERRIDE; | 89 virtual void Shutdown() OVERRIDE; |
| 89 | 90 |
| 90 protected: | 91 protected: |
| 91 // Initializes with an injected invalidator. | 92 // Initializes with an injected invalidator. |
| 92 void InitForTest(syncer::Invalidator* invalidator); | 93 void InitForTest(syncer::Invalidator* invalidator); |
| 93 | 94 |
| 94 friend class TiclInvalidationServiceTestDelegate; | 95 friend class TiclInvalidationServiceTestDelegate; |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 enum InvalidationNetworkChannel { | 98 enum InvalidationNetworkChannel { |
| 98 PUSH_CLIENT_CHANNEL = 0, | 99 PUSH_CLIENT_CHANNEL = 0, |
| 99 GCM_NETWORK_CHANNEL = 1 | 100 GCM_NETWORK_CHANNEL = 1 |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 bool IsReadyToStart(); | 103 bool IsReadyToStart(); |
| 103 bool IsStarted(); | 104 bool IsStarted(); |
| 104 | 105 |
| 105 void StartInvalidator(InvalidationNetworkChannel network_channel); | 106 void StartInvalidator(InvalidationNetworkChannel network_channel); |
| 106 void UpdateInvalidatorCredentials(); | 107 void UpdateInvalidatorCredentials(); |
| 107 void StopInvalidator(); | 108 void StopInvalidator(); |
| 108 void Logout(); | |
| 109 | 109 |
| 110 Profile *const profile_; | 110 Profile *const profile_; |
| 111 SigninManagerBase *const signin_manager_; | 111 scoped_ptr<InvalidationAuthProvider> auth_provider_; |
| 112 ProfileOAuth2TokenService *const oauth2_token_service_; | |
| 113 | 112 |
| 114 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 113 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
| 115 scoped_ptr<InvalidatorStorage> invalidator_storage_; | 114 scoped_ptr<InvalidatorStorage> invalidator_storage_; |
| 116 scoped_ptr<syncer::Invalidator> invalidator_; | 115 scoped_ptr<syncer::Invalidator> invalidator_; |
| 117 | 116 |
| 118 // TiclInvalidationService needs to remember access token in order to | 117 // TiclInvalidationService needs to remember access token in order to |
| 119 // invalidate it with OAuth2TokenService. | 118 // invalidate it with OAuth2TokenService. |
| 120 std::string access_token_; | 119 std::string access_token_; |
| 121 | 120 |
| 122 // TiclInvalidationService needs to hold reference to access_token_request_ | 121 // TiclInvalidationService needs to hold reference to access_token_request_ |
| 123 // for the duration of request in order to receive callbacks. | 122 // for the duration of request in order to receive callbacks. |
| 124 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 123 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 125 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; | 124 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; |
| 126 net::BackoffEntry request_access_token_backoff_; | 125 net::BackoffEntry request_access_token_backoff_; |
| 127 | 126 |
| 128 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; | 127 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; |
| 129 | 128 |
| 130 // The invalidation logger object we use to record state changes | 129 // The invalidation logger object we use to record state changes |
| 131 // and invalidations. | 130 // and invalidations. |
| 132 InvalidationLogger logger_; | 131 InvalidationLogger logger_; |
| 133 | 132 |
| 134 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | 133 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 } // namespace invalidation | 136 } // namespace invalidation |
| 138 | 137 |
| 139 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 138 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
| OLD | NEW |