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

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: rebase 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->IsConnectedState() ||
stevenjb 2013/08/07 01:43:27 Default network is always connected, same below.
gauravsh 2013/08/07 17:28:19 Done.
51 default_network->connection_state() == flimflam::kStatePortal) {
46 // If network is offline, defer the token fetching until online. 52 // If network is offline, defer the token fetching until online.
47 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch."; 53 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch.";
48 BrowserThread::PostDelayedTask( 54 BrowserThread::PostDelayedTask(
49 BrowserThread::UI, FROM_HERE, 55 BrowserThread::UI, FROM_HERE,
50 base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies, 56 base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies,
51 AsWeakPtr()), 57 AsWeakPtr()),
52 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 58 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
53 return; 59 return;
54 } 60 }
55 auth_fetcher_.StartCookieForOAuthLoginTokenExchange(EmptyString()); 61 auth_fetcher_.StartCookieForOAuthLoginTokenExchange(EmptyString());
56 } 62 }
57 63
58 void OAuth2TokenFetcher::StartExchangeFromAuthCode( 64 void OAuth2TokenFetcher::StartExchangeFromAuthCode(
59 const std::string& auth_code) { 65 const std::string& auth_code) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61 auth_code_ = auth_code; 67 auth_code_ = auth_code;
62 // Delay the verification if the network is not connected or on a captive 68 // Delay the verification if the network is not connected or on a captive
63 // portal. 69 // portal.
64 ConnectivityStateHelper* csh = ConnectivityStateHelper::Get(); 70 const NetworkState* default_network =
65 if (!csh->DefaultNetworkOnline()) { 71 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
72 if (!default_network ||
73 !default_network->IsConnectedState() ||
74 default_network->connection_state() == flimflam::kStatePortal) {
66 // If network is offline, defer the token fetching until online. 75 // If network is offline, defer the token fetching until online.
67 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch."; 76 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch.";
68 BrowserThread::PostDelayedTask( 77 BrowserThread::PostDelayedTask(
69 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
70 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode, 79 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode,
71 AsWeakPtr(), 80 AsWeakPtr(),
72 auth_code), 81 auth_code),
73 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 82 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
74 return; 83 return;
75 } 84 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 122 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
114 return; 123 return;
115 } 124 }
116 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: " 125 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: "
117 << error.state() << ", network error: " << error.network_error() 126 << error.state() << ", network error: " << error.network_error()
118 << ", message: " << error.error_message(); 127 << ", message: " << error.error_message();
119 error_handler.Run(); 128 error_handler.Run();
120 } 129 }
121 130
122 } // namespace chromeos 131 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698