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

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

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

Powered by Google App Engine
This is Rietveld 408576698