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

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

Issue 11618024: [signin] Support for CrOS and OAuth2AccessTokenConsumer services. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor fixes Created 8 years 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) 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/chromeos/login/online_attempt.h" 5 #include "chrome/browser/chromeos/login/online_attempt.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/login/auth_attempt_state.h" 14 #include "chrome/browser/chromeos/login/auth_attempt_state.h"
15 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h" 15 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h"
16 #include "chrome/browser/chromeos/login/user.h" 16 #include "chrome/browser/chromeos/login/user.h"
17 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/signin/about_signin_internals.h"
21 #include "chrome/browser/signin/about_signin_internals_factory.h"
19 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
20 #include "google_apis/gaia/gaia_auth_consumer.h" 23 #include "google_apis/gaia/gaia_auth_consumer.h"
21 #include "google_apis/gaia/gaia_auth_fetcher.h" 24 #include "google_apis/gaia/gaia_auth_fetcher.h"
22 #include "google_apis/gaia/gaia_constants.h" 25 #include "google_apis/gaia/gaia_constants.h"
23 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
24 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
25 #include "net/url_request/url_request_status.h" 28 #include "net/url_request/url_request_status.h"
26 #include "third_party/libjingle/source/talk/base/urlencode.h" 29 #include "third_party/libjingle/source/talk/base/urlencode.h"
27 30
28 using content::BrowserThread; 31 using content::BrowserThread;
32 using namespace signin_internals_util;
29 33
30 namespace { 34 namespace {
31 35
32 // The service scope of the OAuth v2 token that ChromeOS login will be 36 // The service scope of the OAuth v2 token that ChromeOS login will be
33 // requesting. 37 // requesting.
34 const char kServiceScopeChromeOS[] = 38 const char kServiceScopeChromeOS[] =
35 "https://www.googleapis.com/auth/chromesync"; 39 "https://www.googleapis.com/auth/chromesync";
36 40
41 #define FOR_DIAGNOSTICS_OBSERVERS(func) \
42 do { \
43 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, \
44 signin_diagnostics_observers_, \
45 func); \
46 } while (0) \
47
37 } 48 }
38 49
39 namespace chromeos { 50 namespace chromeos {
40 51
41 // static 52 // static
42 const int OnlineAttempt::kClientLoginTimeoutMs = 10000; 53 const int OnlineAttempt::kClientLoginTimeoutMs = 10000;
43 54
44 OnlineAttempt::OnlineAttempt(bool using_oauth, 55 OnlineAttempt::OnlineAttempt(bool using_oauth,
45 AuthAttemptState* current_attempt, 56 AuthAttemptState* current_attempt,
46 AuthAttemptStateResolver* callback) 57 AuthAttemptStateResolver* callback)
(...skipping 25 matching lines...) Expand all
72 client_fetcher_.reset( 83 client_fetcher_.reset(
73 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, 84 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource,
74 auth_profile->GetRequestContext())); 85 auth_profile->GetRequestContext()));
75 } 86 }
76 BrowserThread::PostTask( 87 BrowserThread::PostTask(
77 BrowserThread::UI, FROM_HERE, 88 BrowserThread::UI, FROM_HERE,
78 base::Bind(&OnlineAttempt::TryClientLogin, weak_factory_.GetWeakPtr())); 89 base::Bind(&OnlineAttempt::TryClientLogin, weak_factory_.GetWeakPtr()));
79 } 90 }
80 91
81 void OnlineAttempt::OnClientLoginSuccess( 92 void OnlineAttempt::OnClientLoginSuccess(
82 const GaiaAuthConsumer::ClientLoginResult& unused) { 93 const GaiaAuthConsumer::ClientLoginResult& result) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 VLOG(1) << "Online login successful!"; 95 VLOG(1) << "Online login successful!";
85 96
86 weak_factory_.InvalidateWeakPtrs(); 97 weak_factory_.InvalidateWeakPtrs();
87 98
88 if (attempt_->hosted_policy() == GaiaAuthFetcher::HostedAccountsAllowed && 99 if (attempt_->hosted_policy() == GaiaAuthFetcher::HostedAccountsAllowed &&
89 attempt_->is_first_time_user()) { 100 attempt_->is_first_time_user()) {
90 // First time user, and we don't know if the account is HOSTED or not. 101 // First time user, and we don't know if the account is HOSTED or not.
91 // Since we don't allow HOSTED accounts to log in, we need to try 102 // Since we don't allow HOSTED accounts to log in, we need to try
92 // again, without allowing HOSTED accounts. 103 // again, without allowing HOSTED accounts.
93 // 104 //
94 // NOTE: we used to do this in the opposite order, so that we'd only 105 // NOTE: we used to do this in the opposite order, so that we'd only
95 // try the HOSTED pathway if GOOGLE-only failed. This breaks CAPTCHA 106 // try the HOSTED pathway if GOOGLE-only failed. This breaks CAPTCHA
96 // handling, though. 107 // handling, though.
97 attempt_->DisableHosted(); 108 attempt_->DisableHosted();
98 TryClientLogin(); 109 TryClientLogin();
99 return; 110 return;
100 } 111 }
112
113 // Inform all signin diagnostics observers about the login.
114 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
115 USERNAME, UserManager::Get()->GetLoggedInUser()->email()));
116 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
117 SIGNIN_TYPE, "Client Login"));
118 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
119 LSID, result.lsid));
120 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
121 SID, result.sid));
122
101 TriggerResolve(LoginFailure::None()); 123 TriggerResolve(LoginFailure::None());
102 } 124 }
103 125
104 void OnlineAttempt::OnClientLoginFailure( 126 void OnlineAttempt::OnClientLoginFailure(
105 const GoogleServiceAuthError& error) { 127 const GoogleServiceAuthError& error) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 129
108 weak_factory_.InvalidateWeakPtrs(); 130 weak_factory_.InvalidateWeakPtrs();
109 131
110 if (error.state() == GoogleServiceAuthError::REQUEST_CANCELED) { 132 if (error.state() == GoogleServiceAuthError::REQUEST_CANCELED) {
111 if (try_again_) { 133 if (try_again_) {
112 try_again_ = false; 134 try_again_ = false;
113 // TODO(cmasone): add UMA tracking for this to see if we can remove it. 135 // TODO(cmasone): add UMA tracking for this to see if we can remove it.
114 LOG(ERROR) << "Login attempt canceled!?!? Trying again."; 136 LOG(ERROR) << "Login attempt canceled!?!? Trying again.";
137
138 // Inform all signin diagnostics observers about the retry
139 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
140 CLIENT_LOGIN_STATUS, "Login Canceled. Retrying."));
141
115 TryClientLogin(); 142 TryClientLogin();
116 return; 143 return;
117 } 144 }
145 // Inform all signin diagnostics observers about the cancellation.
146 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
147 CLIENT_LOGIN_STATUS, "Login Canceled (after retry)"));
148
118 LOG(ERROR) << "Login attempt canceled again? Already retried..."; 149 LOG(ERROR) << "Login attempt canceled again? Already retried...";
119 } 150 }
120 151
121 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS && 152 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS &&
122 attempt_->is_first_time_user() && 153 attempt_->is_first_time_user() &&
123 attempt_->hosted_policy() != GaiaAuthFetcher::HostedAccountsAllowed) { 154 attempt_->hosted_policy() != GaiaAuthFetcher::HostedAccountsAllowed) {
124 // This was a first-time login, we already tried allowing HOSTED accounts 155 // This was a first-time login, we already tried allowing HOSTED accounts
125 // and succeeded. That we've failed with INVALID_GAIA_CREDENTIALS now 156 // and succeeded. That we've failed with INVALID_GAIA_CREDENTIALS now
126 // indicates that the account is HOSTED. 157 // indicates that the account is HOSTED.
127 LOG(WARNING) << "Rejecting valid HOSTED account."; 158 LOG(WARNING) << "Rejecting valid HOSTED account.";
159
160 // Inform all signin diagnostics observers about the login.
161 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
162 CLIENT_LOGIN_STATUS, "Rejecting valid HOSTED account"));
163
128 TriggerResolve(LoginFailure::FromNetworkAuthFailure( 164 TriggerResolve(LoginFailure::FromNetworkAuthFailure(
129 GoogleServiceAuthError( 165 GoogleServiceAuthError(
130 GoogleServiceAuthError::HOSTED_NOT_ALLOWED))); 166 GoogleServiceAuthError::HOSTED_NOT_ALLOWED)));
131 return; 167 return;
132 } 168 }
133 169
134 if (error.state() == GoogleServiceAuthError::TWO_FACTOR) { 170 if (error.state() == GoogleServiceAuthError::TWO_FACTOR) {
135 LOG(WARNING) << "Two factor authenticated. Sync will not work."; 171 LOG(WARNING) << "Two factor authenticated. Sync will not work.";
172
173 // Inform all signin diagnostics observers about the login.
174 // TODO(vishwath): Is this really a successful login?
175 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
176 SIGNIN_TYPE, "Client Login (with two factor authentication)"));
177 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
178 CLIENT_LOGIN_STATUS, "Successful"));
179
180
136 TriggerResolve(LoginFailure::None()); 181 TriggerResolve(LoginFailure::None());
137
138 return; 182 return;
139 } 183 }
184
185
186 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(
187 SIGNIN_TYPE, "Client Login"));
188
140 VLOG(2) << "ClientLogin attempt failed with " << error.state(); 189 VLOG(2) << "ClientLogin attempt failed with " << error.state();
141 TriggerResolve(LoginFailure::FromNetworkAuthFailure(error)); 190 TriggerResolve(LoginFailure::FromNetworkAuthFailure(error));
142 } 191 }
143 192
144 void OnlineAttempt::OnOAuthLoginSuccess(const std::string& sid, 193 void OnlineAttempt::OnOAuthLoginSuccess(const std::string& sid,
145 const std::string& lsid, 194 const std::string& lsid,
146 const std::string& auth) { 195 const std::string& auth) {
147 GaiaAuthConsumer::ClientLoginResult credentials(sid, 196 GaiaAuthConsumer::ClientLoginResult credentials(sid,
148 lsid, auth, std::string()); 197 lsid, auth, std::string());
149 OnClientLoginSuccess(credentials); 198 OnClientLoginSuccess(credentials);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 256
208 void OnlineAttempt::TriggerResolve( 257 void OnlineAttempt::TriggerResolve(
209 const LoginFailure& outcome) { 258 const LoginFailure& outcome) {
210 attempt_->RecordOnlineLoginStatus(outcome); 259 attempt_->RecordOnlineLoginStatus(outcome);
211 client_fetcher_.reset(NULL); 260 client_fetcher_.reset(NULL);
212 oauth_fetcher_.reset(NULL); 261 oauth_fetcher_.reset(NULL);
213 resolver_->Resolve(); 262 resolver_->Resolve();
214 } 263 }
215 264
216 } // namespace chromeos 265 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/online_attempt.h ('k') | chrome/browser/extensions/app_notify_channel_setup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698