| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_to_mobile_service.h" | 5 #include "chrome/browser/chrome_to_mobile_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/chrome_to_mobile_service_factory.h" | 16 #include "chrome/browser/chrome_to_mobile_service_factory.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/about_signin_internals.h" |
| 21 #include "chrome/browser/signin/about_signin_internals_factory.h" |
| 22 #include "chrome/browser/signin/signin_manager.h" |
| 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/signin/token_service.h" | 24 #include "chrome/browser/signin/token_service.h" |
| 21 #include "chrome/browser/signin/token_service_factory.h" | 25 #include "chrome/browser/signin/token_service_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 24 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_command_controller.h" | 29 #include "chrome/browser/ui/browser_command_controller.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
| 28 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 428 |
| 425 // Post a delayed task to invalidate the access token at its expiration time. | 429 // Post a delayed task to invalidate the access token at its expiration time. |
| 426 if (!content::BrowserThread::PostDelayedTask( | 430 if (!content::BrowserThread::PostDelayedTask( |
| 427 content::BrowserThread::UI, FROM_HERE, | 431 content::BrowserThread::UI, FROM_HERE, |
| 428 base::Bind(&ChromeToMobileService::ClearAccessToken, | 432 base::Bind(&ChromeToMobileService::ClearAccessToken, |
| 429 weak_ptr_factory_.GetWeakPtr()), | 433 weak_ptr_factory_.GetWeakPtr()), |
| 430 expiration_time - base::Time::Now())) { | 434 expiration_time - base::Time::Now())) { |
| 431 NOTREACHED(); | 435 NOTREACHED(); |
| 432 } | 436 } |
| 433 | 437 |
| 438 // Let SigninInternals know about the token fetch. |
| 439 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 440 DCHECK(profile_); |
| 441 // TODO(vishwath): This can be removed when refactoring this class to use |
| 442 // OAuth2TokenService instead. |
| 443 AboutSigninInternalsFactory::GetForProfile(profile_)-> |
| 444 NotifyTokenReceivedSuccess(signin_internals_util::kChromeToMobileToken, |
| 445 access_token, |
| 446 true); |
| 447 |
| 434 while (!task_queue_.empty()) { | 448 while (!task_queue_.empty()) { |
| 435 // Post all tasks that were queued and waiting on a valid access token. | 449 // Post all tasks that were queued and waiting on a valid access token. |
| 436 if (!content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 450 if (!content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 437 task_queue_.front())) { | 451 task_queue_.front())) { |
| 438 NOTREACHED(); | 452 NOTREACHED(); |
| 439 } | 453 } |
| 440 task_queue_.pop(); | 454 task_queue_.pop(); |
| 441 } | 455 } |
| 442 } | 456 } |
| 443 | 457 |
| 444 void ChromeToMobileService::OnGetTokenFailure( | 458 void ChromeToMobileService::OnGetTokenFailure( |
| 445 const GoogleServiceAuthError& error) { | 459 const GoogleServiceAuthError& error) { |
| 446 // Log a general auth error metric for the "ChromeToMobile.Service" histogram. | 460 // Log a general auth error metric for the "ChromeToMobile.Service" histogram. |
| 447 LogMetric(BAD_TOKEN); | 461 LogMetric(BAD_TOKEN); |
| 448 // Log a more detailed metric for the "ChromeToMobile.AuthError" histogram. | 462 // Log a more detailed metric for the "ChromeToMobile.AuthError" histogram. |
| 449 UMA_HISTOGRAM_ENUMERATION("ChromeToMobile.AuthError", error.state(), | 463 UMA_HISTOGRAM_ENUMERATION("ChromeToMobile.AuthError", error.state(), |
| 450 GoogleServiceAuthError::NUM_STATES); | 464 GoogleServiceAuthError::NUM_STATES); |
| 451 VLOG(0) << "ChromeToMobile auth failed: " << error.ToString(); | 465 VLOG(0) << "ChromeToMobile auth failed: " << error.ToString(); |
| 452 | 466 |
| 453 access_token_.clear(); | 467 access_token_.clear(); |
| 454 access_token_fetcher_.reset(); | 468 access_token_fetcher_.reset(); |
| 455 auth_retry_timer_.Stop(); | 469 auth_retry_timer_.Stop(); |
| 456 | 470 |
| 457 base::TimeDelta delay = std::max(base::TimeDelta::FromHours(kDelayHours), | 471 base::TimeDelta delay = std::max(base::TimeDelta::FromHours(kDelayHours), |
| 458 auth_retry_timer_.GetCurrentDelay() * 2); | 472 auth_retry_timer_.GetCurrentDelay() * 2); |
| 459 auth_retry_timer_.Start(FROM_HERE, delay, this, | 473 auth_retry_timer_.Start(FROM_HERE, delay, this, |
| 460 &ChromeToMobileService::RequestAccessToken); | 474 &ChromeToMobileService::RequestAccessToken); |
| 461 | 475 |
| 476 // Let SigninInternals know about the failed token fetch. |
| 477 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 478 DCHECK(profile_); |
| 479 // TODO(vishwath): This can be removed when refactoring this class to use |
| 480 // OAuth2TokenService instead. |
| 481 AboutSigninInternalsFactory::GetForProfile(profile_)-> |
| 482 NotifyTokenReceivedFailure(signin_internals_util::kChromeToMobileToken, |
| 483 error.ToString()); |
| 484 |
| 485 |
| 462 // Clear the mobile list, which may be (or become) out of date. | 486 // Clear the mobile list, which may be (or become) out of date. |
| 463 ListValue empty; | 487 ListValue empty; |
| 464 profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, empty); | 488 profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, empty); |
| 465 } | 489 } |
| 466 | 490 |
| 467 void ChromeToMobileService::OnInvalidatorStateChange( | 491 void ChromeToMobileService::OnInvalidatorStateChange( |
| 468 syncer::InvalidatorState state) { | 492 syncer::InvalidatorState state) { |
| 469 sync_invalidation_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); | 493 sync_invalidation_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); |
| 470 } | 494 } |
| 471 | 495 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 762 |
| 739 // Report failure below and ignore the second response. | 763 // Report failure below and ignore the second response. |
| 740 request_observer_map_.erase(other); | 764 request_observer_map_.erase(other); |
| 741 break; | 765 break; |
| 742 } | 766 } |
| 743 } | 767 } |
| 744 | 768 |
| 745 if (observer.get()) | 769 if (observer.get()) |
| 746 observer->OnSendComplete(success); | 770 observer->OnSendComplete(success); |
| 747 } | 771 } |
| OLD | NEW |