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

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

Issue 116533006: Control invalidations network channel from TiclInvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 11 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 #include "chrome/browser/invalidation/ticl_invalidation_service.h" 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/invalidation/invalidation_service_util.h" 10 #include "chrome/browser/invalidation/invalidation_service_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 DCHECK(CalledOnValidThread()); 74 DCHECK(CalledOnValidThread());
75 75
76 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); 76 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
77 if (invalidator_storage_->GetInvalidatorClientId().empty()) { 77 if (invalidator_storage_->GetInvalidatorClientId().empty()) {
78 // This also clears any existing state. We can't reuse old invalidator 78 // This also clears any existing state. We can't reuse old invalidator
79 // state with the new ID anyway. 79 // state with the new ID anyway.
80 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); 80 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
81 } 81 }
82 82
83 if (IsReadyToStart()) { 83 if (IsReadyToStart()) {
84 StartInvalidator(); 84 StartInvalidator(PUSH_CLIENT_CHANNEL);
85 } 85 }
86 86
87 notification_registrar_.Add(this, 87 notification_registrar_.Add(this,
88 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 88 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
89 content::Source<Profile>(profile_)); 89 content::Source<Profile>(profile_));
90 oauth2_token_service_->AddObserver(this); 90 oauth2_token_service_->AddObserver(this);
91 } 91 }
92 92
93 void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) { 93 void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) {
94 // Here we perform the equivalent of Init() and StartInvalidator(), but with 94 // Here we perform the equivalent of Init() and StartInvalidator(), but with
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void TiclInvalidationService::OnGetTokenSuccess( 183 void TiclInvalidationService::OnGetTokenSuccess(
184 const OAuth2TokenService::Request* request, 184 const OAuth2TokenService::Request* request,
185 const std::string& access_token, 185 const std::string& access_token,
186 const base::Time& expiration_time) { 186 const base::Time& expiration_time) {
187 DCHECK_EQ(access_token_request_, request); 187 DCHECK_EQ(access_token_request_, request);
188 access_token_request_.reset(); 188 access_token_request_.reset();
189 // Reset backoff time after successful response. 189 // Reset backoff time after successful response.
190 request_access_token_backoff_.Reset(); 190 request_access_token_backoff_.Reset();
191 access_token_ = access_token; 191 access_token_ = access_token;
192 if (!IsStarted() && IsReadyToStart()) { 192 if (!IsStarted() && IsReadyToStart()) {
193 StartInvalidator(); 193 StartInvalidator(PUSH_CLIENT_CHANNEL);
194 } else { 194 } else {
195 UpdateInvalidatorCredentials(); 195 UpdateInvalidatorCredentials();
196 } 196 }
197 } 197 }
198 198
199 void TiclInvalidationService::OnGetTokenFailure( 199 void TiclInvalidationService::OnGetTokenFailure(
200 const OAuth2TokenService::Request* request, 200 const OAuth2TokenService::Request* request,
201 const GoogleServiceAuthError& error) { 201 const GoogleServiceAuthError& error) {
202 DCHECK_EQ(access_token_request_, request); 202 DCHECK_EQ(access_token_request_, request);
203 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); 203 DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
(...skipping 19 matching lines...) Expand all
223 default: { 223 default: {
224 // We have no way to notify the user of this. Do nothing. 224 // We have no way to notify the user of this. Do nothing.
225 } 225 }
226 } 226 }
227 } 227 }
228 228
229 void TiclInvalidationService::OnRefreshTokenAvailable( 229 void TiclInvalidationService::OnRefreshTokenAvailable(
230 const std::string& account_id) { 230 const std::string& account_id) {
231 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { 231 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) {
232 if (!IsStarted() && IsReadyToStart()) { 232 if (!IsStarted() && IsReadyToStart()) {
233 StartInvalidator(); 233 StartInvalidator(PUSH_CLIENT_CHANNEL);
234 } 234 }
235 } 235 }
236 } 236 }
237 237
238 void TiclInvalidationService::OnRefreshTokenRevoked( 238 void TiclInvalidationService::OnRefreshTokenRevoked(
239 const std::string& account_id) { 239 const std::string& account_id) {
240 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { 240 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) {
241 access_token_.clear(); 241 access_token_.clear();
242 if (IsStarted()) { 242 if (IsStarted()) {
243 UpdateInvalidatorCredentials(); 243 UpdateInvalidatorCredentials();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return false; 306 return false;
307 } 307 }
308 308
309 return true; 309 return true;
310 } 310 }
311 311
312 bool TiclInvalidationService::IsStarted() { 312 bool TiclInvalidationService::IsStarted() {
313 return invalidator_.get() != NULL; 313 return invalidator_.get() != NULL;
314 } 314 }
315 315
316 void TiclInvalidationService::StartInvalidator() { 316 void TiclInvalidationService::StartInvalidator(
317 InvalidationNetworkChannel network_channel) {
317 DCHECK(CalledOnValidThread()); 318 DCHECK(CalledOnValidThread());
318 DCHECK(!invalidator_); 319 DCHECK(!invalidator_);
319 DCHECK(invalidator_storage_); 320 DCHECK(invalidator_storage_);
320 DCHECK(!invalidator_storage_->GetInvalidatorClientId().empty()); 321 DCHECK(!invalidator_storage_->GetInvalidatorClientId().empty());
321 322
322 if (access_token_.empty()) { 323 if (access_token_.empty()) {
323 DVLOG(1) 324 DVLOG(1)
324 << "TiclInvalidationService: " 325 << "TiclInvalidationService: "
325 << "Deferring start until we have an access token."; 326 << "Deferring start until we have an access token.";
326 RequestAccessToken(); 327 RequestAccessToken();
327 return; 328 return;
328 } 329 }
329 330
330 notifier::NotifierOptions options = 331 syncer::NetworkChannelCreator network_channel_creator;
331 ParseNotifierOptions(*CommandLine::ForCurrentProcess()); 332
332 options.request_context_getter = profile_->GetRequestContext(); 333 switch (network_channel) {
333 options.auth_mechanism = "X-OAUTH2"; 334 case PUSH_CLIENT_CHANNEL: {
335 notifier::NotifierOptions options =
336 ParseNotifierOptions(*CommandLine::ForCurrentProcess());
337 options.request_context_getter = profile_->GetRequestContext();
338 options.auth_mechanism = "X-OAUTH2";
339 DCHECK_EQ(notifier::NOTIFICATION_SERVER, options.notification_method);
340 network_channel_creator =
341 syncer::NonBlockingInvalidator::MakePushClientChannelCreator(options);
342 break;
343 }
344 case GCM_NETWORK_CHANNEL: {
345 network_channel_creator =
346 syncer::NonBlockingInvalidator::MakeGCMNetworkChannelCreator();
347 break;
348 }
349 default: {
350 NOTREACHED();
351 return;
352 }
353 }
334 invalidator_.reset(new syncer::NonBlockingInvalidator( 354 invalidator_.reset(new syncer::NonBlockingInvalidator(
335 options, 355 network_channel_creator,
336 invalidator_storage_->GetInvalidatorClientId(), 356 invalidator_storage_->GetInvalidatorClientId(),
337 invalidator_storage_->GetSavedInvalidations(), 357 invalidator_storage_->GetSavedInvalidations(),
338 invalidator_storage_->GetBootstrapData(), 358 invalidator_storage_->GetBootstrapData(),
339 syncer::WeakHandle<syncer::InvalidationStateTracker>( 359 syncer::WeakHandle<syncer::InvalidationStateTracker>(
340 invalidator_storage_->AsWeakPtr()), 360 invalidator_storage_->AsWeakPtr()),
341 content::GetUserAgent(GURL()))); 361 content::GetUserAgent(GURL()),
362 profile_->GetRequestContext()));
342 363
343 UpdateInvalidatorCredentials(); 364 UpdateInvalidatorCredentials();
344 365
345 invalidator_->RegisterHandler(this); 366 invalidator_->RegisterHandler(this);
346 invalidator_->UpdateRegisteredIds( 367 invalidator_->UpdateRegisteredIds(
347 this, 368 this,
348 invalidator_registrar_->GetAllRegisteredIds()); 369 invalidator_registrar_->GetAllRegisteredIds());
349 } 370 }
350 371
351 void TiclInvalidationService::UpdateInvalidatorCredentials() { 372 void TiclInvalidationService::UpdateInvalidatorCredentials() {
(...skipping 20 matching lines...) Expand all
372 } 393 }
373 394
374 // This service always expects to have a valid invalidator storage. 395 // This service always expects to have a valid invalidator storage.
375 // So we must not only clear the old one, but also start a new one. 396 // So we must not only clear the old one, but also start a new one.
376 invalidator_storage_->Clear(); 397 invalidator_storage_->Clear();
377 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); 398 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
378 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); 399 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
379 } 400 }
380 401
381 } // namespace invalidation 402 } // namespace invalidation
OLDNEW
« no previous file with comments | « chrome/browser/invalidation/ticl_invalidation_service.h ('k') | sync/notifier/gcm_network_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698