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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
10 #include "base/timer.h" | 10 #include "chrome/browser/invalidation/invalidation_frontend.h" |
11 #include "chrome/browser/invalidation/invalidation_service.h" | |
12 #include "chrome/browser/invalidation/invalidator_storage.h" | 11 #include "chrome/browser/invalidation/invalidator_storage.h" |
13 #include "chrome/browser/signin/oauth2_token_service.h" | 12 #include "chrome/browser/signin/signin_global_error.h" |
14 #include "chrome/browser/signin/token_service.h" | |
15 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
16 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
18 #include "net/base/backoff_entry.h" | |
19 #include "sync/notifier/invalidation_handler.h" | 16 #include "sync/notifier/invalidation_handler.h" |
20 #include "sync/notifier/invalidator_registrar.h" | 17 #include "sync/notifier/invalidator_registrar.h" |
21 | 18 |
22 class Profile; | 19 class Profile; |
23 class SigninManagerBase; | 20 class SigninManagerBase; |
| 21 class TokenService; |
24 | 22 |
25 namespace syncer { | 23 namespace syncer { |
26 class Invalidator; | 24 class Invalidator; |
27 } | 25 } |
28 | 26 |
29 // TODO: Remove this dependency. See crbug.com/243482. | |
30 namespace extensions { | |
31 class PushMessagingApiTest; | |
32 } | |
33 | |
34 namespace invalidation { | 27 namespace invalidation { |
35 | 28 |
36 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. | 29 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. |
37 // It provides invalidations for desktop platforms (Win, Mac, Linux). | 30 // It provides invalidations for desktop platforms (Win, Mac, Linux). |
38 class TiclInvalidationService | 31 class TiclInvalidationService |
39 : public base::NonThreadSafe, | 32 : public base::NonThreadSafe, |
40 public InvalidationService, | 33 public BrowserContextKeyedService, |
| 34 public InvalidationFrontend, |
41 public content::NotificationObserver, | 35 public content::NotificationObserver, |
42 public OAuth2TokenService::Consumer, | |
43 public syncer::InvalidationHandler { | 36 public syncer::InvalidationHandler { |
44 public: | 37 public: |
45 TiclInvalidationService(SigninManagerBase* signin, | 38 TiclInvalidationService(SigninManagerBase* signin, |
46 TokenService* token_service, | 39 TokenService* token_service, |
47 OAuth2TokenService* oauth2_token_service, | |
48 Profile* profile); | 40 Profile* profile); |
49 virtual ~TiclInvalidationService(); | 41 virtual ~TiclInvalidationService(); |
50 | 42 |
51 void Init(); | 43 void Init(); |
52 | 44 |
53 // InvalidationService implementation. | 45 // InvalidationFrontend implementation. |
54 // It is an error to have registered handlers when Shutdown() is called. | 46 // It is an error to have registered handlers when Shutdown() is called. |
55 virtual void RegisterInvalidationHandler( | 47 virtual void RegisterInvalidationHandler( |
56 syncer::InvalidationHandler* handler) OVERRIDE; | 48 syncer::InvalidationHandler* handler) OVERRIDE; |
57 virtual void UpdateRegisteredInvalidationIds( | 49 virtual void UpdateRegisteredInvalidationIds( |
58 syncer::InvalidationHandler* handler, | 50 syncer::InvalidationHandler* handler, |
59 const syncer::ObjectIdSet& ids) OVERRIDE; | 51 const syncer::ObjectIdSet& ids) OVERRIDE; |
60 virtual void UnregisterInvalidationHandler( | 52 virtual void UnregisterInvalidationHandler( |
61 syncer::InvalidationHandler* handler) OVERRIDE; | 53 syncer::InvalidationHandler* handler) OVERRIDE; |
62 virtual void AcknowledgeInvalidation( | 54 virtual void AcknowledgeInvalidation( |
63 const invalidation::ObjectId& id, | 55 const invalidation::ObjectId& id, |
64 const syncer::AckHandle& ack_handle) OVERRIDE; | 56 const syncer::AckHandle& ack_handle) OVERRIDE; |
65 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 57 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
66 virtual std::string GetInvalidatorClientId() const OVERRIDE; | 58 virtual std::string GetInvalidatorClientId() const; |
67 | 59 |
68 // content::NotificationObserver implementation. | 60 // content::NotificationObserver implementation. |
69 virtual void Observe(int type, | 61 virtual void Observe(int type, |
70 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
71 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
72 | 64 |
73 void RequestAccessToken(); | |
74 | |
75 // OAuth2TokenService::Consumer implementation | |
76 virtual void OnGetTokenSuccess( | |
77 const OAuth2TokenService::Request* request, | |
78 const std::string& access_token, | |
79 const base::Time& expiration_time) OVERRIDE; | |
80 virtual void OnGetTokenFailure( | |
81 const OAuth2TokenService::Request* request, | |
82 const GoogleServiceAuthError& error) OVERRIDE; | |
83 | |
84 // syncer::InvalidationHandler implementation. | 65 // syncer::InvalidationHandler implementation. |
85 virtual void OnInvalidatorStateChange( | 66 virtual void OnInvalidatorStateChange( |
86 syncer::InvalidatorState state) OVERRIDE; | 67 syncer::InvalidatorState state) OVERRIDE; |
87 virtual void OnIncomingInvalidation( | 68 virtual void OnIncomingInvalidation( |
88 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 69 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
89 | 70 |
90 // Overrides BrowserContextKeyedService method. | 71 // Overrides BrowserContextKeyedService method. |
91 virtual void Shutdown() OVERRIDE; | 72 virtual void Shutdown() OVERRIDE; |
92 | 73 |
93 protected: | 74 protected: |
94 // Initializes with an injected invalidator. | 75 // Initializes with an injected invalidator. |
95 void InitForTest(syncer::Invalidator* invalidator); | 76 void InitForTest(syncer::Invalidator* invalidator); |
96 | 77 |
97 friend class TiclInvalidationServiceTestDelegate; | 78 friend class TiclInvalidationServiceTestDelegate; |
98 friend class extensions::PushMessagingApiTest; | |
99 | 79 |
100 private: | 80 private: |
101 bool IsReadyToStart(); | 81 bool IsReadyToStart(); |
102 bool IsStarted(); | 82 bool IsStarted(); |
103 | 83 |
104 void StartInvalidator(); | 84 void Start(); |
105 void UpdateInvalidatorCredentials(); | 85 void UpdateToken(); |
106 void StopInvalidator(); | 86 void StopInvalidator(); |
107 void Logout(); | 87 void Logout(); |
108 | 88 |
109 Profile *const profile_; | 89 Profile *const profile_; |
110 SigninManagerBase *const signin_manager_; | 90 SigninManagerBase *const signin_manager_; |
111 TokenService *const token_service_; | 91 TokenService *const token_service_; |
112 OAuth2TokenService *const oauth2_token_service_; | |
113 | 92 |
114 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 93 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
115 scoped_ptr<InvalidatorStorage> invalidator_storage_; | 94 scoped_ptr<InvalidatorStorage> invalidator_storage_; |
116 scoped_ptr<syncer::Invalidator> invalidator_; | 95 scoped_ptr<syncer::Invalidator> invalidator_; |
117 | 96 |
118 content::NotificationRegistrar notification_registrar_; | 97 content::NotificationRegistrar notification_registrar_; |
119 | 98 |
120 // TiclInvalidationService needs to remember access token in order to | |
121 // invalidate it with OAuth2TokenService. | |
122 std::string access_token_; | |
123 | |
124 // TiclInvalidationService needs to hold reference to access_token_request_ | |
125 // for the duration of request in order to receive callbacks. | |
126 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | |
127 base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; | |
128 net::BackoffEntry request_access_token_backoff_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); | 99 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); |
131 }; | 100 }; |
132 | 101 |
133 } // namespace invalidation | 102 } |
134 | 103 |
135 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ | 104 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ |
OLD | NEW |