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

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 777143003: Clean up straggler classes to use embedded signin in page in the new profiles world. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/webui/signin/inline_login_handler_impl.h" 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_window.h" 15 #include "chrome/browser/profiles/profile_window.h"
16 #include "chrome/browser/signin/about_signin_internals_factory.h" 16 #include "chrome/browser/signin/about_signin_internals_factory.h"
17 #include "chrome/browser/signin/account_tracker_service_factory.h" 17 #include "chrome/browser/signin/account_tracker_service_factory.h"
18 #include "chrome/browser/signin/chrome_signin_client_factory.h" 18 #include "chrome/browser/signin/chrome_signin_client_factory.h"
19 #include "chrome/browser/signin/local_auth.h" 19 #include "chrome/browser/signin/local_auth.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/signin_promo.h" 22 #include "chrome/browser/signin/signin_promo.h"
23 #include "chrome/browser/sync/profile_sync_service.h" 23 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 27 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
28 #include "chrome/browser/ui/sync/one_click_signin_histogram.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 29 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
31 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 30 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 31 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
33 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
34 #include "components/signin/core/browser/about_signin_internals.h" 33 #include "components/signin/core/browser/about_signin_internals.h"
35 #include "components/signin/core/browser/account_tracker_service.h" 34 #include "components/signin/core/browser/account_tracker_service.h"
36 #include "components/signin/core/browser/profile_oauth2_token_service.h" 35 #include "components/signin/core/browser/profile_oauth2_token_service.h"
37 #include "components/signin/core/browser/signin_error_controller.h" 36 #include "components/signin/core/browser/signin_error_controller.h"
37 #include "components/signin/core/browser/signin_metrics.h"
38 #include "components/signin/core/common/profile_management_switches.h" 38 #include "components/signin/core/common/profile_management_switches.h"
39 #include "content/public/browser/storage_partition.h" 39 #include "content/public/browser/storage_partition.h"
40 #include "content/public/browser/web_ui.h" 40 #include "content/public/browser/web_ui.h"
41 #include "google_apis/gaia/gaia_auth_consumer.h" 41 #include "google_apis/gaia/gaia_auth_consumer.h"
42 #include "google_apis/gaia/gaia_auth_fetcher.h" 42 #include "google_apis/gaia/gaia_auth_fetcher.h"
43 #include "google_apis/gaia/gaia_auth_util.h" 43 #include "google_apis/gaia/gaia_auth_util.h"
44 #include "google_apis/gaia/gaia_constants.h" 44 #include "google_apis/gaia/gaia_constants.h"
45 #include "google_apis/gaia/gaia_urls.h" 45 #include "google_apis/gaia/gaia_urls.h"
46 #include "net/base/url_util.h" 46 #include "net/base/url_util.h"
47 47
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 about_signin_internals->OnRefreshTokenReceived("Successful"); 123 about_signin_internals->OnRefreshTokenReceived("Successful");
124 124
125 AccountTrackerService* account_tracker = 125 AccountTrackerService* account_tracker =
126 AccountTrackerServiceFactory::GetForProfile(profile_); 126 AccountTrackerServiceFactory::GetForProfile(profile_);
127 std::string account_id = 127 std::string account_id =
128 account_tracker->PickAccountIdForAccount(gaia_id_, email_); 128 account_tracker->PickAccountIdForAccount(gaia_id_, email_);
129 129
130 // Prime the account tracker with this combination of gaia id/display email. 130 // Prime the account tracker with this combination of gaia id/display email.
131 account_tracker->SeedAccountInfo(gaia_id_, email_); 131 account_tracker->SeedAccountInfo(gaia_id_, email_);
132 132
133 signin::Source source = signin::GetSourceForPromoURL(current_url_); 133 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url_);
134 134
135 std::string primary_email = 135 std::string primary_email =
136 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); 136 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername();
137 if (gaia::AreEmailsSame(email_, primary_email) && 137 if (gaia::AreEmailsSame(email_, primary_email) &&
138 source == signin::SOURCE_REAUTH && 138 source == signin_metrics::SOURCE_REAUTH &&
139 switches::IsNewProfileManagement() && 139 switches::IsNewProfileManagement() &&
140 !password_.empty() && 140 !password_.empty() &&
141 profiles::IsLockAvailable(profile_)) { 141 profiles::IsLockAvailable(profile_)) {
142 chrome::SetLocalAuthCredentials(profile_, password_); 142 chrome::SetLocalAuthCredentials(profile_, password_);
143 } 143 }
144 144
145 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || 145 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
146 source == signin::SOURCE_REAUTH) { 146 source == signin_metrics::SOURCE_REAUTH) {
147 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 147 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
148 UpdateCredentials(account_id, result.refresh_token); 148 UpdateCredentials(account_id, result.refresh_token);
149 149
150 if (signin::IsAutoCloseEnabledInURL(current_url_)) { 150 if (signin::IsAutoCloseEnabledInURL(current_url_)) {
151 // Close the gaia sign in tab via a task to make sure we aren't in the 151 // Close the gaia sign in tab via a task to make sure we aren't in the
152 // middle of any webui handler code. 152 // middle of any webui handler code.
153 base::MessageLoop::current()->PostTask( 153 base::MessageLoop::current()->PostTask(
154 FROM_HERE, 154 FROM_HERE,
155 base::Bind(&InlineLoginHandlerImpl::CloseTab, 155 base::Bind(&InlineLoginHandlerImpl::CloseTab,
156 handler_, 156 handler_,
157 signin::ShouldShowAccountManagement(current_url_))); 157 signin::ShouldShowAccountManagement(current_url_)));
158 } 158 }
159 } else { 159 } else {
160 ProfileSyncService* sync_service = 160 ProfileSyncService* sync_service =
161 ProfileSyncServiceFactory::GetForProfile(profile_); 161 ProfileSyncServiceFactory::GetForProfile(profile_);
162 SigninErrorController* error_controller = 162 SigninErrorController* error_controller =
163 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 163 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
164 signin_error_controller(); 164 signin_error_controller();
165 165
166 bool is_new_avatar_menu = switches::IsNewAvatarMenu(); 166 bool is_new_avatar_menu = switches::IsNewAvatarMenu();
167 167
168 OneClickSigninSyncStarter::StartSyncMode start_mode; 168 OneClickSigninSyncStarter::StartSyncMode start_mode;
169 if (source == signin::SOURCE_SETTINGS || choose_what_to_sync_) { 169 if (source == signin_metrics::SOURCE_SETTINGS || choose_what_to_sync_) {
170 bool show_settings_without_configure = 170 bool show_settings_without_configure =
171 error_controller->HasError() && 171 error_controller->HasError() &&
172 sync_service && 172 sync_service &&
173 sync_service->HasSyncSetupCompleted(); 173 sync_service->HasSyncSetupCompleted();
174 start_mode = show_settings_without_configure ? 174 start_mode = show_settings_without_configure ?
175 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : 175 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE :
176 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST; 176 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST;
177 } else { 177 } else {
178 start_mode = is_new_avatar_menu ? 178 start_mode = is_new_avatar_menu ?
179 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST : 179 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST :
180 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; 180 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;
181 } 181 }
182 182
183 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; 183 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required;
184 if (confirm_untrusted_signin_) { 184 if (confirm_untrusted_signin_) {
185 confirmation_required = 185 confirmation_required =
186 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; 186 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN;
187 } else if (is_new_avatar_menu) { 187 } else if (is_new_avatar_menu) {
188 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 188 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
189 } else { 189 } else {
190 confirmation_required = 190 confirmation_required =
191 source == signin::SOURCE_SETTINGS || 191 source == signin_metrics::SOURCE_SETTINGS ||
192 choose_what_to_sync_ ? 192 choose_what_to_sync_ ?
193 OneClickSigninSyncStarter::NO_CONFIRMATION : 193 OneClickSigninSyncStarter::NO_CONFIRMATION :
194 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 194 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
195 } 195 }
196 196
197 bool start_signin = 197 bool start_signin =
198 !OneClickSigninHelper::HandleCrossAccountError( 198 !OneClickSigninHelper::HandleCrossAccountError(
199 profile_, "", 199 profile_, "",
200 email_, password_, result.refresh_token, 200 email_, password_, result.refresh_token,
201 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, 201 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { 270 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
271 params.SetString("service", "chromiumsync"); 271 params.SetString("service", "chromiumsync");
272 272
273 content::WebContents* contents = web_ui()->GetWebContents(); 273 content::WebContents* contents = web_ui()->GetWebContents();
274 const GURL& current_url = contents->GetURL(); 274 const GURL& current_url = contents->GetURL();
275 std::string is_constrained; 275 std::string is_constrained;
276 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); 276 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
277 277
278 content::WebContentsObserver::Observe(contents); 278 content::WebContentsObserver::Observe(contents);
279 279 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN);
280 signin::Source source = signin::GetSourceForPromoURL(current_url);
281 OneClickSigninHelper::LogHistogramValue(
282 source, one_click_signin::HISTOGRAM_SHOWN);
283 } 280 }
284 281
285 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 282 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
286 content::WebContents* contents = web_ui()->GetWebContents(); 283 content::WebContents* contents = web_ui()->GetWebContents();
287 const GURL& current_url = contents->GetURL(); 284 const GURL& current_url = contents->GetURL();
288 285
289 const base::DictionaryValue* dict = NULL; 286 const base::DictionaryValue* dict = NULL;
290 args->GetDictionary(0, &dict); 287 args->GetDictionary(0, &dict);
291 288
292 bool skip_for_now = false; 289 bool skip_for_now = false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 325 }
329 326
330 base::string16 session_index_string16; 327 base::string16 session_index_string16;
331 dict->GetString("sessionIndex", &session_index_string16); 328 dict->GetString("sessionIndex", &session_index_string16);
332 std::string session_index = base::UTF16ToASCII(session_index_string16); 329 std::string session_index = base::UTF16ToASCII(session_index_string16);
333 DCHECK(!session_index.empty()); 330 DCHECK(!session_index.empty());
334 331
335 bool choose_what_to_sync = false; 332 bool choose_what_to_sync = false;
336 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); 333 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync);
337 334
338 signin::Source source = signin::GetSourceForPromoURL(current_url); 335 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
336 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED);
337 bool switch_to_advanced =
338 choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS);
339 OneClickSigninHelper::LogHistogramValue( 339 OneClickSigninHelper::LogHistogramValue(
340 source, one_click_signin::HISTOGRAM_ACCEPTED); 340 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED :
341 bool switch_to_advanced = 341 signin_metrics::HISTOGRAM_WITH_DEFAULTS);
342 choose_what_to_sync && (source != signin::SOURCE_SETTINGS);
343 OneClickSigninHelper::LogHistogramValue(
344 source,
345 switch_to_advanced ? one_click_signin::HISTOGRAM_WITH_ADVANCED :
346 one_click_signin::HISTOGRAM_WITH_DEFAULTS);
347 342
348 OneClickSigninHelper::CanOfferFor can_offer_for = 343 OneClickSigninHelper::CanOfferFor can_offer_for =
349 OneClickSigninHelper::CAN_OFFER_FOR_ALL; 344 OneClickSigninHelper::CAN_OFFER_FOR_ALL;
350 switch (source) { 345 switch (source) {
351 case signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: 346 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT:
352 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; 347 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT;
353 break; 348 break;
354 case signin::SOURCE_REAUTH: { 349 case signin_metrics::SOURCE_REAUTH: {
355 std::string primary_username = 350 std::string primary_username =
356 SigninManagerFactory::GetForProfile( 351 SigninManagerFactory::GetForProfile(
357 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername(); 352 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername();
358 if (!gaia::AreEmailsSame(default_email, primary_username)) 353 if (!gaia::AreEmailsSame(default_email, primary_username))
359 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; 354 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT;
360 break; 355 break;
361 } 356 }
362 default: 357 default:
363 // No need to change |can_offer_for|. 358 // No need to change |can_offer_for|.
364 break; 359 break;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 content::WebContents* contents = web_ui()->GetWebContents(); 415 content::WebContents* contents = web_ui()->GetWebContents();
421 416
422 if (contents->GetController().GetPendingEntry()) { 417 if (contents->GetController().GetPendingEntry()) {
423 // Do nothing if a navigation is pending, since this call can be triggered 418 // Do nothing if a navigation is pending, since this call can be triggered
424 // from DidStartLoading. This avoids deleting the pending entry while we are 419 // from DidStartLoading. This avoids deleting the pending entry while we are
425 // still navigating to it. See crbug/346632. 420 // still navigating to it. See crbug/346632.
426 return; 421 return;
427 } 422 }
428 423
429 const GURL& current_url = contents->GetLastCommittedURL(); 424 const GURL& current_url = contents->GetLastCommittedURL();
430 signin::Source source = signin::GetSourceForPromoURL(current_url); 425 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
431 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); 426 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url);
432 427
433 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { 428 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) {
434 OneClickSigninHelper::RedirectToNtpOrAppsPage(contents, source); 429 OneClickSigninHelper::RedirectToNtpOrAppsPage(contents, source);
435 } else if (auto_close) { 430 } else if (auto_close) {
436 base::MessageLoop::current()->PostTask( 431 base::MessageLoop::current()->PostTask(
437 FROM_HERE, 432 FROM_HERE,
438 base::Bind(&InlineLoginHandlerImpl::CloseTab, 433 base::Bind(&InlineLoginHandlerImpl::CloseTab,
439 weak_factory_.GetWeakPtr(), 434 weak_factory_.GetWeakPtr(),
440 signin::ShouldShowAccountManagement(current_url))); 435 signin::ShouldShowAccountManagement(current_url)));
(...skipping 15 matching lines...) Expand all
456 } 451 }
457 } 452 }
458 453
459 if (show_account_management) { 454 if (show_account_management) {
460 browser->window()->ShowAvatarBubbleFromAvatarButton( 455 browser->window()->ShowAvatarBubbleFromAvatarButton(
461 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 456 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
462 signin::ManageAccountsParams()); 457 signin::ManageAccountsParams());
463 } 458 }
464 } 459 }
465 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler.cc ('k') | chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698