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

Side by Side Diff: chrome/browser/chromeos/login/oauth2_token_fetcher.cc

Issue 22264004: Remove ConnectivityStateHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang errors + fix nits Created 7 years, 4 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 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h" 5 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" 9 #include "chromeos/network/network_handler.h"
10 #include "chromeos/network/network_state.h"
11 #include "chromeos/network/network_state_handler.h"
10 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
11 #include "google_apis/gaia/gaia_constants.h" 13 #include "google_apis/gaia/gaia_constants.h"
12 #include "google_apis/gaia/google_service_auth_error.h" 14 #include "google_apis/gaia/google_service_auth_error.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
13 16
14 using content::BrowserThread; 17 using content::BrowserThread;
15 18
16 namespace { 19 namespace {
17 20
18 // OAuth token request max retry count. 21 // OAuth token request max retry count.
19 const int kMaxRequestAttemptCount = 5; 22 const int kMaxRequestAttemptCount = 5;
20 // OAuth token request retry delay in milliseconds. 23 // OAuth token request retry delay in milliseconds.
21 const int kRequestRestartDelay = 3000; 24 const int kRequestRestartDelay = 3000;
22 25
(...skipping 11 matching lines...) Expand all
34 } 37 }
35 38
36 OAuth2TokenFetcher::~OAuth2TokenFetcher() { 39 OAuth2TokenFetcher::~OAuth2TokenFetcher() {
37 } 40 }
38 41
39 void OAuth2TokenFetcher::StartExchangeFromCookies() { 42 void OAuth2TokenFetcher::StartExchangeFromCookies() {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 44
42 // Delay the verification if the network is not connected or on a captive 45 // Delay the verification if the network is not connected or on a captive
43 // portal. 46 // portal.
44 ConnectivityStateHelper* csh = ConnectivityStateHelper::Get(); 47 const NetworkState* default_network =
45 if (!csh->DefaultNetworkOnline()) { 48 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
49 if (!default_network ||
50 default_network->connection_state() == flimflam::kStatePortal) {
Nikita (slow) 2013/08/08 10:47:28 Same comment about (!network->IsConnectedState()).
gauravsh 2013/08/08 16:59:20 See my previous comment. It was a redundant check
Nikita (slow) 2013/08/08 17:50:43 Why check in lines 71..73 is different then?
gauravsh 2013/08/08 18:02:41 Oops, yeah, it should be the same there as well. I
46 // If network is offline, defer the token fetching until online. 51 // If network is offline, defer the token fetching until online.
47 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch."; 52 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch.";
48 BrowserThread::PostDelayedTask( 53 BrowserThread::PostDelayedTask(
49 BrowserThread::UI, FROM_HERE, 54 BrowserThread::UI, FROM_HERE,
50 base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies, 55 base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies,
51 AsWeakPtr()), 56 AsWeakPtr()),
52 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 57 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
53 return; 58 return;
54 } 59 }
55 auth_fetcher_.StartCookieForOAuthLoginTokenExchange(EmptyString()); 60 auth_fetcher_.StartCookieForOAuthLoginTokenExchange(EmptyString());
56 } 61 }
57 62
58 void OAuth2TokenFetcher::StartExchangeFromAuthCode( 63 void OAuth2TokenFetcher::StartExchangeFromAuthCode(
59 const std::string& auth_code) { 64 const std::string& auth_code) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61 auth_code_ = auth_code; 66 auth_code_ = auth_code;
62 // Delay the verification if the network is not connected or on a captive 67 // Delay the verification if the network is not connected or on a captive
63 // portal. 68 // portal.
64 ConnectivityStateHelper* csh = ConnectivityStateHelper::Get(); 69 const NetworkState* default_network =
65 if (!csh->DefaultNetworkOnline()) { 70 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
71 if (!default_network ||
72 !default_network->IsConnectedState() ||
73 default_network->connection_state() == flimflam::kStatePortal) {
66 // If network is offline, defer the token fetching until online. 74 // If network is offline, defer the token fetching until online.
67 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch."; 75 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch.";
68 BrowserThread::PostDelayedTask( 76 BrowserThread::PostDelayedTask(
69 BrowserThread::UI, FROM_HERE, 77 BrowserThread::UI, FROM_HERE,
70 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode, 78 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode,
71 AsWeakPtr(), 79 AsWeakPtr(),
72 auth_code), 80 auth_code),
73 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 81 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
74 return; 82 return;
75 } 83 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 121 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
114 return; 122 return;
115 } 123 }
116 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: " 124 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: "
117 << error.state() << ", network error: " << error.network_error() 125 << error.state() << ", network error: " << error.network_error()
118 << ", message: " << error.error_message(); 126 << ", message: " << error.error_message();
119 error_handler.Run(); 127 error_handler.Run();
120 } 128 }
121 129
122 } // namespace chromeos 130 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698