Chromium Code Reviews| 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 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h" | 5 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chromeos/network/network_handler.h" | |
| 17 #include "chromeos/network/network_state.h" | |
| 18 #include "chromeos/network/network_state_handler.h" | |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "google_apis/gaia/gaia_constants.h" | 20 #include "google_apis/gaia/gaia_constants.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" | 21 #include "google_apis/gaia/gaia_urls.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 20 | 23 |
| 21 using content::BrowserThread; | 24 using content::BrowserThread; |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 // OAuth token request max retry count. | 28 // OAuth token request max retry count. |
| 26 const int kMaxRequestAttemptCount = 5; | 29 const int kMaxRequestAttemptCount = 5; |
| 27 // OAuth token request retry delay in milliseconds. | 30 // OAuth token request retry delay in milliseconds. |
| 28 const int kRequestRestartDelay = 3000; | 31 const int kRequestRestartDelay = 3000; |
| 29 | 32 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 43 } | 46 } |
| 44 | 47 |
| 45 OAuth2LoginVerifier::~OAuth2LoginVerifier() { | 48 OAuth2LoginVerifier::~OAuth2LoginVerifier() { |
| 46 } | 49 } |
| 47 | 50 |
| 48 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) { | 51 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 50 | 53 |
| 51 // Delay the verification if the network is not connected or on a captive | 54 // Delay the verification if the network is not connected or on a captive |
| 52 // portal. | 55 // portal. |
| 53 ConnectivityStateHelper* csh = ConnectivityStateHelper::Get(); | 56 const NetworkState* default_network = |
| 54 if (!csh->DefaultNetworkOnline()) { | 57 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
| 58 if (!default_network || | |
| 59 !default_network->IsConnectedState() || | |
|
stevenjb
2013/08/07 01:43:27
The Default network is always connected.
gauravsh
2013/08/07 17:28:19
Done.
| |
| 60 default_network->connection_state() == flimflam::kStatePortal) { | |
| 55 // If network is offline, defer the token fetching until online. | 61 // If network is offline, defer the token fetching until online. |
| 56 VLOG(1) << "Network is offline. Deferring OAuth2 access token fetch."; | 62 VLOG(1) << "Network is offline. Deferring OAuth2 access token fetch."; |
| 57 BrowserThread::PostDelayedTask( | 63 BrowserThread::PostDelayedTask( |
| 58 BrowserThread::UI, | 64 BrowserThread::UI, |
| 59 FROM_HERE, | 65 FROM_HERE, |
| 60 base::Bind( | 66 base::Bind( |
| 61 &OAuth2LoginVerifier::VerifyProfileTokens, AsWeakPtr(), profile), | 67 &OAuth2LoginVerifier::VerifyProfileTokens, AsWeakPtr(), profile), |
| 62 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); | 68 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); |
| 63 return; | 69 return; |
| 64 } | 70 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 LOG(ERROR) << "Unrecoverable error or retry count max reached for " | 224 LOG(ERROR) << "Unrecoverable error or retry count max reached for " |
| 219 << operation_id; | 225 << operation_id; |
| 220 UMA_HISTOGRAM_ENUMERATION( | 226 UMA_HISTOGRAM_ENUMERATION( |
| 221 base::StringPrintf("OAuth2Login.%sFailure", operation_id), | 227 base::StringPrintf("OAuth2Login.%sFailure", operation_id), |
| 222 error.state(), | 228 error.state(), |
| 223 GoogleServiceAuthError::NUM_STATES); | 229 GoogleServiceAuthError::NUM_STATES); |
| 224 error_handler.Run(); | 230 error_handler.Run(); |
| 225 } | 231 } |
| 226 | 232 |
| 227 } // namespace chromeos | 233 } // namespace chromeos |
| OLD | NEW |