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/browser_context_keyed_service/browser_context_keyed_service
.h" | 17 #include "components/browser_context_keyed_service/browser_context_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 InvalidationAuthProvider* GetInvalidationAuthProvider() OVERRIDE; |
59 | 60 |
60 void RequestAccessToken(); | 61 void RequestAccessToken(); |
61 | 62 |
62 // OAuth2TokenService::Consumer implementation | 63 // OAuth2TokenService::Consumer implementation |
63 virtual void OnGetTokenSuccess( | 64 virtual void OnGetTokenSuccess( |
64 const OAuth2TokenService::Request* request, | 65 const OAuth2TokenService::Request* request, |
65 const std::string& access_token, | 66 const std::string& access_token, |
66 const base::Time& expiration_time) OVERRIDE; | 67 const base::Time& expiration_time) OVERRIDE; |
67 virtual void OnGetTokenFailure( | 68 virtual void OnGetTokenFailure( |
68 const OAuth2TokenService::Request* request, | 69 const OAuth2TokenService::Request* request, |
69 const GoogleServiceAuthError& error) OVERRIDE; | 70 const GoogleServiceAuthError& error) OVERRIDE; |
70 | 71 |
71 // OAuth2TokenService::Observer implementation | 72 // OAuth2TokenService::Observer implementation |
72 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 73 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
73 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 74 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
74 | 75 |
75 // SigninManagerBase::Observer implementation. | 76 // InvalidationAuthProvider::Observer implementation. |
76 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 77 virtual void OnInvalidationAuthLogout() OVERRIDE; |
77 | 78 |
78 // syncer::InvalidationHandler implementation. | 79 // syncer::InvalidationHandler implementation. |
79 virtual void OnInvalidatorStateChange( | 80 virtual void OnInvalidatorStateChange( |
80 syncer::InvalidatorState state) OVERRIDE; | 81 syncer::InvalidatorState state) OVERRIDE; |
81 virtual void OnIncomingInvalidation( | 82 virtual void OnIncomingInvalidation( |
82 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 83 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
83 virtual std::string GetOwnerName() const OVERRIDE; | 84 virtual std::string GetOwnerName() const OVERRIDE; |
84 | 85 |
85 // Overrides BrowserContextKeyedService method. | 86 // Overrides BrowserContextKeyedService method. |
86 virtual void Shutdown() OVERRIDE; | 87 virtual void Shutdown() OVERRIDE; |
87 | 88 |
88 protected: | 89 protected: |
89 // Initializes with an injected invalidator. | 90 // Initializes with an injected invalidator. |
90 void InitForTest(syncer::Invalidator* invalidator); | 91 void InitForTest(syncer::Invalidator* invalidator); |
91 | 92 |
92 friend class TiclInvalidationServiceTestDelegate; | 93 friend class TiclInvalidationServiceTestDelegate; |
93 | 94 |
94 private: | 95 private: |
95 enum InvalidationNetworkChannel { | 96 enum InvalidationNetworkChannel { |
96 PUSH_CLIENT_CHANNEL = 0, | 97 PUSH_CLIENT_CHANNEL = 0, |
97 GCM_NETWORK_CHANNEL = 1 | 98 GCM_NETWORK_CHANNEL = 1 |
98 }; | 99 }; |
99 | 100 |
100 bool IsReadyToStart(); | 101 bool IsReadyToStart(); |
101 bool IsStarted(); | 102 bool IsStarted(); |
102 | 103 |
103 void StartInvalidator(InvalidationNetworkChannel network_channel); | 104 void StartInvalidator(InvalidationNetworkChannel network_channel); |
104 void UpdateInvalidatorCredentials(); | 105 void UpdateInvalidatorCredentials(); |
105 void StopInvalidator(); | 106 void StopInvalidator(); |
106 void Logout(); | |
107 | 107 |
108 Profile *const profile_; | 108 Profile *const profile_; |
109 SigninManagerBase *const signin_manager_; | 109 scoped_ptr<InvalidationAuthProvider> auth_provider_; |
110 ProfileOAuth2TokenService *const oauth2_token_service_; | |
111 | 110 |
112 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 111 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
113 scoped_ptr<InvalidatorStorage> invalidator_storage_; | 112 scoped_ptr<InvalidatorStorage> invalidator_storage_; |
114 scoped_ptr<syncer::Invalidator> invalidator_; | 113 scoped_ptr<syncer::Invalidator> invalidator_; |
115 | 114 |
116 // TiclInvalidationService needs to remember access token in order to | 115 // TiclInvalidationService needs to remember access token in order to |
117 // invalidate it with OAuth2TokenService. | 116 // invalidate it with OAuth2TokenService. |
118 std::string access_token_; | 117 std::string access_token_; |
119 | 118 |
120 // TiclInvalidationService needs to hold reference to access_token_request_ | 119 // TiclInvalidationService needs to hold reference to access_token_request_ |
121 // for the duration of request in order to receive callbacks. | 120 // for the duration of request in order to receive callbacks. |
122 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 121 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
123 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; | 122 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; |
124 net::BackoffEntry request_access_token_backoff_; | 123 net::BackoffEntry request_access_token_backoff_; |
125 | 124 |
126 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; | 125 scoped_ptr<GCMInvalidationBridge> gcm_invalidation_bridge_; |
127 | 126 |
128 // The invalidation logger object we use to record state changes | 127 // The invalidation logger object we use to record state changes |
129 // and invalidations. | 128 // and invalidations. |
130 InvalidationLogger logger_; | 129 InvalidationLogger logger_; |
131 | 130 |
132 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | 131 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); |
133 }; | 132 }; |
134 | 133 |
135 } // namespace invalidation | 134 } // namespace invalidation |
136 | 135 |
137 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 136 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
OLD | NEW |