Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/invalidation/ticl_invalidation_service.h

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/invalidation/invalidation_frontend.h" 10 #include "base/timer.h"
11 #include "chrome/browser/invalidation/invalidation_service.h"
11 #include "chrome/browser/invalidation/invalidator_storage.h" 12 #include "chrome/browser/invalidation/invalidator_storage.h"
12 #include "chrome/browser/signin/signin_global_error.h" 13 #include "chrome/browser/signin/oauth2_token_service.h"
14 #include "chrome/browser/signin/token_service.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
14 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "net/base/backoff_entry.h"
16 #include "sync/notifier/invalidation_handler.h" 19 #include "sync/notifier/invalidation_handler.h"
17 #include "sync/notifier/invalidator_registrar.h" 20 #include "sync/notifier/invalidator_registrar.h"
18 21
19 class Profile; 22 class Profile;
20 class SigninManagerBase; 23 class SigninManagerBase;
21 class TokenService;
22 24
23 namespace syncer { 25 namespace syncer {
24 class Invalidator; 26 class Invalidator;
25 } 27 }
26 28
29 // TODO: Remove this dependency. See crbug.com/243482.
30 namespace extensions {
31 class PushMessagingApiTest;
32 }
33
27 namespace invalidation { 34 namespace invalidation {
28 35
29 // This InvalidationService wraps the C++ Invalidation Client (TICL) library. 36 // This InvalidationService wraps the C++ Invalidation Client (TICL) library.
30 // It provides invalidations for desktop platforms (Win, Mac, Linux). 37 // It provides invalidations for desktop platforms (Win, Mac, Linux).
31 class TiclInvalidationService 38 class TiclInvalidationService
32 : public base::NonThreadSafe, 39 : public base::NonThreadSafe,
33 public BrowserContextKeyedService, 40 public InvalidationService,
34 public InvalidationFrontend,
35 public content::NotificationObserver, 41 public content::NotificationObserver,
42 public OAuth2TokenService::Consumer,
36 public syncer::InvalidationHandler { 43 public syncer::InvalidationHandler {
37 public: 44 public:
38 TiclInvalidationService(SigninManagerBase* signin, 45 TiclInvalidationService(SigninManagerBase* signin,
39 TokenService* token_service, 46 TokenService* token_service,
47 OAuth2TokenService* oauth2_token_service,
40 Profile* profile); 48 Profile* profile);
41 virtual ~TiclInvalidationService(); 49 virtual ~TiclInvalidationService();
42 50
43 void Init(); 51 void Init();
44 52
45 // InvalidationFrontend implementation. 53 // InvalidationService implementation.
46 // It is an error to have registered handlers when Shutdown() is called. 54 // It is an error to have registered handlers when Shutdown() is called.
47 virtual void RegisterInvalidationHandler( 55 virtual void RegisterInvalidationHandler(
48 syncer::InvalidationHandler* handler) OVERRIDE; 56 syncer::InvalidationHandler* handler) OVERRIDE;
49 virtual void UpdateRegisteredInvalidationIds( 57 virtual void UpdateRegisteredInvalidationIds(
50 syncer::InvalidationHandler* handler, 58 syncer::InvalidationHandler* handler,
51 const syncer::ObjectIdSet& ids) OVERRIDE; 59 const syncer::ObjectIdSet& ids) OVERRIDE;
52 virtual void UnregisterInvalidationHandler( 60 virtual void UnregisterInvalidationHandler(
53 syncer::InvalidationHandler* handler) OVERRIDE; 61 syncer::InvalidationHandler* handler) OVERRIDE;
54 virtual void AcknowledgeInvalidation( 62 virtual void AcknowledgeInvalidation(
55 const invalidation::ObjectId& id, 63 const invalidation::ObjectId& id,
56 const syncer::AckHandle& ack_handle) OVERRIDE; 64 const syncer::AckHandle& ack_handle) OVERRIDE;
57 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; 65 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE;
58 virtual std::string GetInvalidatorClientId() const; 66 virtual std::string GetInvalidatorClientId() const OVERRIDE;
59 67
60 // content::NotificationObserver implementation. 68 // content::NotificationObserver implementation.
61 virtual void Observe(int type, 69 virtual void Observe(int type,
62 const content::NotificationSource& source, 70 const content::NotificationSource& source,
63 const content::NotificationDetails& details) OVERRIDE; 71 const content::NotificationDetails& details) OVERRIDE;
64 72
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
65 // syncer::InvalidationHandler implementation. 84 // syncer::InvalidationHandler implementation.
66 virtual void OnInvalidatorStateChange( 85 virtual void OnInvalidatorStateChange(
67 syncer::InvalidatorState state) OVERRIDE; 86 syncer::InvalidatorState state) OVERRIDE;
68 virtual void OnIncomingInvalidation( 87 virtual void OnIncomingInvalidation(
69 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; 88 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
70 89
71 // Overrides BrowserContextKeyedService method. 90 // Overrides BrowserContextKeyedService method.
72 virtual void Shutdown() OVERRIDE; 91 virtual void Shutdown() OVERRIDE;
73 92
74 protected: 93 protected:
75 // Initializes with an injected invalidator. 94 // Initializes with an injected invalidator.
76 void InitForTest(syncer::Invalidator* invalidator); 95 void InitForTest(syncer::Invalidator* invalidator);
77 96
78 friend class TiclInvalidationServiceTestDelegate; 97 friend class TiclInvalidationServiceTestDelegate;
98 friend class extensions::PushMessagingApiTest;
79 99
80 private: 100 private:
81 bool IsReadyToStart(); 101 bool IsReadyToStart();
82 bool IsStarted(); 102 bool IsStarted();
83 103
84 void Start(); 104 void StartInvalidator();
85 void UpdateToken(); 105 void UpdateInvalidatorCredentials();
86 void StopInvalidator(); 106 void StopInvalidator();
87 void Logout(); 107 void Logout();
88 108
89 Profile *const profile_; 109 Profile *const profile_;
90 SigninManagerBase *const signin_manager_; 110 SigninManagerBase *const signin_manager_;
91 TokenService *const token_service_; 111 TokenService *const token_service_;
112 OAuth2TokenService *const oauth2_token_service_;
92 113
93 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; 114 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_;
94 scoped_ptr<InvalidatorStorage> invalidator_storage_; 115 scoped_ptr<InvalidatorStorage> invalidator_storage_;
95 scoped_ptr<syncer::Invalidator> invalidator_; 116 scoped_ptr<syncer::Invalidator> invalidator_;
96 117
97 content::NotificationRegistrar notification_registrar_; 118 content::NotificationRegistrar notification_registrar_;
98 119
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
99 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); 130 DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService);
100 }; 131 };
101 132
102 } 133 } // namespace invalidation
103 134
104 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ 135 #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/invalidation/p2p_invalidation_service.h ('k') | chrome/browser/invalidation/ticl_invalidation_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698