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

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

Issue 914363003: Remove OneClickSigninHelper since it is no longer used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ocl
Patch Set: rebased Created 5 years, 9 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
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/callback_helpers.h"
11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_window.h" 19 #include "chrome/browser/profiles/profile_window.h"
16 #include "chrome/browser/signin/about_signin_internals_factory.h" 20 #include "chrome/browser/signin/about_signin_internals_factory.h"
17 #include "chrome/browser/signin/account_tracker_service_factory.h" 21 #include "chrome/browser/signin/account_tracker_service_factory.h"
18 #include "chrome/browser/signin/chrome_signin_client_factory.h" 22 #include "chrome/browser/signin/chrome_signin_client_factory.h"
19 #include "chrome/browser/signin/local_auth.h" 23 #include "chrome/browser/signin/local_auth.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_error_controller_factory.h" 25 #include "chrome/browser/signin/signin_error_controller_factory.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/browser/signin/signin_promo.h" 27 #include "chrome/browser/signin/signin_promo.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 28 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/sync/profile_sync_service_factory.h" 29 #include "chrome/browser/sync/profile_sync_service_factory.h"
26 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 32 #include "chrome/browser/ui/chrome_pages.h"
33 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
34 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 35 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 36 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
31 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 37 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 38 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
33 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
40 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h"
34 #include "components/signin/core/browser/about_signin_internals.h" 42 #include "components/signin/core/browser/about_signin_internals.h"
35 #include "components/signin/core/browser/account_tracker_service.h" 43 #include "components/signin/core/browser/account_tracker_service.h"
36 #include "components/signin/core/browser/profile_oauth2_token_service.h" 44 #include "components/signin/core/browser/profile_oauth2_token_service.h"
37 #include "components/signin/core/browser/signin_error_controller.h" 45 #include "components/signin/core/browser/signin_error_controller.h"
38 #include "components/signin/core/browser/signin_metrics.h" 46 #include "components/signin/core/browser/signin_metrics.h"
39 #include "components/signin/core/common/profile_management_switches.h" 47 #include "components/signin/core/common/profile_management_switches.h"
48 #include "components/signin/core/common/signin_pref_names.h"
40 #include "content/public/browser/storage_partition.h" 49 #include "content/public/browser/storage_partition.h"
41 #include "content/public/browser/web_ui.h" 50 #include "content/public/browser/web_ui.h"
42 #include "google_apis/gaia/gaia_auth_consumer.h" 51 #include "google_apis/gaia/gaia_auth_consumer.h"
43 #include "google_apis/gaia/gaia_auth_fetcher.h" 52 #include "google_apis/gaia/gaia_auth_fetcher.h"
44 #include "google_apis/gaia/gaia_auth_util.h" 53 #include "google_apis/gaia/gaia_auth_util.h"
45 #include "google_apis/gaia/gaia_constants.h" 54 #include "google_apis/gaia/gaia_constants.h"
46 #include "google_apis/gaia/gaia_urls.h" 55 #include "google_apis/gaia/gaia_urls.h"
56 #include "grit/components_strings.h"
47 #include "net/base/url_util.h" 57 #include "net/base/url_util.h"
58 #include "ui/base/l10n/l10n_util.h"
48 59
49 namespace { 60 namespace {
50 61
62 void LogHistogramValue(int action) {
63 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action,
64 signin_metrics::HISTOGRAM_MAX);
65 }
66
67 void RedirectToNtpOrAppsPage(content::WebContents* contents,
68 signin_metrics::Source source) {
69 // Do nothing if a navigation is pending, since this call can be triggered
70 // from DidStartLoading. This avoids deleting the pending entry while we are
71 // still navigating to it. See crbug/346632.
72 if (contents->GetController().GetPendingEntry())
73 return;
74
75 VLOG(1) << "RedirectToNtpOrAppsPage";
76 // Redirect to NTP/Apps page and display a confirmation bubble
77 GURL url(source == signin_metrics::SOURCE_APPS_PAGE_LINK ?
78 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
79 content::OpenURLParams params(url,
80 content::Referrer(),
81 CURRENT_TAB,
82 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
83 false);
84 contents->OpenURL(params);
85 }
86
87 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents,
88 signin_metrics::Source source) {
89 if (source != signin_metrics::SOURCE_SETTINGS)
90 RedirectToNtpOrAppsPage(contents, source);
91 }
92
93 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate {
94 public:
95 enum Action {
96 CREATE_NEW_USER,
97 START_SYNC,
98 CLOSE
99 };
100
101 // Callback indicating action performed by the user.
102 typedef base::Callback<void(Action)> Callback;
103
104 // Ask the user for confirmation before starting to sync.
105 static void AskForConfirmation(content::WebContents* contents,
106 const std::string& last_email,
107 const std::string& email,
108 Callback callback);
109
110 private:
111 ConfirmEmailDialogDelegate(content::WebContents* contents,
112 const std::string& last_email,
113 const std::string& email,
114 Callback callback);
115 ~ConfirmEmailDialogDelegate() override;
116
117 // TabModalConfirmDialogDelegate:
118 base::string16 GetTitle() override;
119 base::string16 GetDialogMessage() override;
120 base::string16 GetAcceptButtonTitle() override;
121 base::string16 GetCancelButtonTitle() override;
122 base::string16 GetLinkText() const override;
123 void OnAccepted() override;
124 void OnCanceled() override;
125 void OnClosed() override;
126 void OnLinkClicked(WindowOpenDisposition disposition) override;
127
128 std::string last_email_;
129 std::string email_;
130 Callback callback_;
131
132 // Web contents from which the "Learn more" link should be opened.
133 content::WebContents* web_contents_;
134
135 DISALLOW_COPY_AND_ASSIGN(ConfirmEmailDialogDelegate);
136 };
137
138 // static
139 void ConfirmEmailDialogDelegate::AskForConfirmation(
140 content::WebContents* contents,
141 const std::string& last_email,
142 const std::string& email,
143 Callback callback) {
144 TabModalConfirmDialog::Create(
145 new ConfirmEmailDialogDelegate(contents, last_email, email, callback),
146 contents);
147 }
148
149 ConfirmEmailDialogDelegate::ConfirmEmailDialogDelegate(
150 content::WebContents* contents,
151 const std::string& last_email,
152 const std::string& email,
153 Callback callback)
154 : TabModalConfirmDialogDelegate(contents),
155 last_email_(last_email),
156 email_(email),
157 callback_(callback),
158 web_contents_(contents) {
159 }
160
161 ConfirmEmailDialogDelegate::~ConfirmEmailDialogDelegate() {
162 }
163
164 base::string16 ConfirmEmailDialogDelegate::GetTitle() {
165 return l10n_util::GetStringUTF16(
166 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_TITLE);
167 }
168
169 base::string16 ConfirmEmailDialogDelegate::GetDialogMessage() {
170 return l10n_util::GetStringFUTF16(
171 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_MESSAGE,
172 base::UTF8ToUTF16(last_email_), base::UTF8ToUTF16(email_));
173 }
174
175 base::string16 ConfirmEmailDialogDelegate::GetAcceptButtonTitle() {
176 return l10n_util::GetStringUTF16(
177 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON);
178 }
179
180 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() {
181 return l10n_util::GetStringUTF16(
182 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON);
183 }
184
185 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const {
186 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
187 }
188
189 void ConfirmEmailDialogDelegate::OnAccepted() {
190 base::ResetAndReturn(&callback_).Run(CREATE_NEW_USER);
191 }
192
193 void ConfirmEmailDialogDelegate::OnCanceled() {
194 base::ResetAndReturn(&callback_).Run(START_SYNC);
195 }
196
197 void ConfirmEmailDialogDelegate::OnClosed() {
198 base::ResetAndReturn(&callback_).Run(CLOSE);
199 }
200
201 void ConfirmEmailDialogDelegate::OnLinkClicked(
202 WindowOpenDisposition disposition) {
203 content::OpenURLParams params(
204 GURL(chrome::kChromeSyncMergeTroubleshootingURL),
205 content::Referrer(),
206 NEW_POPUP,
207 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
208 false);
209 // It is guaranteed that |web_contents_| is valid here because when it's
210 // deleted, the dialog is immediately closed and no further action can be
211 // performed.
212 web_contents_->OpenURL(params);
213 }
214
51 class InlineSigninHelper : public GaiaAuthConsumer { 215 class InlineSigninHelper : public GaiaAuthConsumer {
52 public: 216 public:
53 InlineSigninHelper( 217 InlineSigninHelper(
54 base::WeakPtr<InlineLoginHandlerImpl> handler, 218 base::WeakPtr<InlineLoginHandlerImpl> handler,
55 net::URLRequestContextGetter* getter, 219 net::URLRequestContextGetter* getter,
56 Profile* profile, 220 Profile* profile,
57 const GURL& current_url, 221 const GURL& current_url,
58 const std::string& email, 222 const std::string& email,
59 const std::string& gaia_id, 223 const std::string& gaia_id,
60 const std::string& password, 224 const std::string& password,
61 const std::string& session_index, 225 const std::string& session_index,
62 const std::string& signin_scoped_device_id, 226 const std::string& signin_scoped_device_id,
63 bool choose_what_to_sync, 227 bool choose_what_to_sync,
64 bool confirm_untrusted_signin); 228 bool confirm_untrusted_signin);
65 229
66 private: 230 private:
231 // Handles cross account sign in error. If the supplied |email| does not match
232 // the last signed in email of the current profile, then Chrome will show a
233 // confirmation dialog before starting sync. It returns true if there is a
234 // cross account error, and false otherwise.
235 bool HandleCrossAccountError(
236 const std::string& refresh_token,
237 signin_metrics::Source source,
238 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
239 OneClickSigninSyncStarter::StartSyncMode start_mode);
240
241 // Callback used with ConfirmEmailDialogDelegate.
242 void ConfirmEmailAction(
243 content::WebContents* web_contents,
244 const std::string& refresh_token,
245 signin_metrics::Source source,
246 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
247 OneClickSigninSyncStarter::StartSyncMode start_mode,
248 ConfirmEmailDialogDelegate::Action action);
249
67 // Overridden from GaiaAuthConsumer. 250 // Overridden from GaiaAuthConsumer.
68 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; 251 void OnClientOAuthSuccess(const ClientOAuthResult& result) override;
69 void OnClientOAuthFailure(const GoogleServiceAuthError& error) 252 void OnClientOAuthFailure(const GoogleServiceAuthError& error)
70 override; 253 override;
71 254
72 GaiaAuthFetcher gaia_auth_fetcher_; 255 GaiaAuthFetcher gaia_auth_fetcher_;
73 base::WeakPtr<InlineLoginHandlerImpl> handler_; 256 base::WeakPtr<InlineLoginHandlerImpl> handler_;
74 Profile* profile_; 257 Profile* profile_;
75 GURL current_url_; 258 GURL current_url_;
76 std::string email_; 259 std::string email_;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } else if (is_new_avatar_menu) { 373 } else if (is_new_avatar_menu) {
191 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 374 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
192 } else { 375 } else {
193 confirmation_required = 376 confirmation_required =
194 source == signin_metrics::SOURCE_SETTINGS || 377 source == signin_metrics::SOURCE_SETTINGS ||
195 choose_what_to_sync_ ? 378 choose_what_to_sync_ ?
196 OneClickSigninSyncStarter::NO_CONFIRMATION : 379 OneClickSigninSyncStarter::NO_CONFIRMATION :
197 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 380 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
198 } 381 }
199 382
200 bool start_signin = 383 bool start_signin = !HandleCrossAccountError(result.refresh_token, source,
201 !OneClickSigninHelper::HandleCrossAccountError( 384 confirmation_required, start_mode);
202 profile_, "",
203 email_, password_, result.refresh_token,
204 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
205 source, start_mode,
206 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback,
207 handler_));
208 if (start_signin) { 385 if (start_signin) {
209 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. 386 // Call OneClickSigninSyncStarter to exchange oauth code for tokens.
210 // OneClickSigninSyncStarter will delete itself once the job is done. 387 // OneClickSigninSyncStarter will delete itself once the job is done.
211 new OneClickSigninSyncStarter( 388 new OneClickSigninSyncStarter(
212 profile_, browser, 389 profile_, browser,
213 email_, password_, result.refresh_token, 390 email_, password_, result.refresh_token,
214 start_mode, 391 start_mode,
215 contents, 392 contents,
216 confirmation_required, 393 confirmation_required,
217 signin::GetNextPageURLForPromoURL(current_url_), 394 signin::GetNextPageURLForPromoURL(current_url_),
218 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); 395 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
396 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
219 } 397 }
220 } 398 }
399 }
221 400
401 bool InlineSigninHelper::HandleCrossAccountError(
402 const std::string& refresh_token,
403 signin_metrics::Source source,
404 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
405 OneClickSigninSyncStarter::StartSyncMode start_mode) {
406 std::string last_email =
407 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);
408
409 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_))
410 return false;
411
412 Browser* browser = chrome::FindLastActiveWithProfile(
413 profile_, chrome::GetActiveDesktop());
414 content::WebContents* web_contents =
415 browser->tab_strip_model()->GetActiveWebContents();
416
417 ConfirmEmailDialogDelegate::AskForConfirmation(
418 web_contents,
419 last_email,
420 email_,
421 base::Bind(&InlineSigninHelper::ConfirmEmailAction,
422 base::Unretained(this),
423 web_contents,
424 refresh_token,
425 source,
426 confirmation_required,
427 start_mode));
428 return true;
429 }
430
431 void InlineSigninHelper::ConfirmEmailAction(
432 content::WebContents* web_contents,
433 const std::string& refresh_token,
434 signin_metrics::Source source,
435 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
436 OneClickSigninSyncStarter::StartSyncMode start_mode,
437 ConfirmEmailDialogDelegate::Action action) {
438 Browser* browser = chrome::FindLastActiveWithProfile(
439 profile_, chrome::GetActiveDesktop());
440 switch (action) {
441 case ConfirmEmailDialogDelegate::CREATE_NEW_USER:
442 if (handler_) {
443 handler_->SyncStarterCallback(
444 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
445 }
446 chrome::ShowSettingsSubPage(browser,
447 std::string(chrome::kCreateProfileSubPage));
448 break;
449 case ConfirmEmailDialogDelegate::START_SYNC:
450 new OneClickSigninSyncStarter(
451 profile_, browser, email_, password_, refresh_token,
452 start_mode, web_contents, confirmation_required, GURL(),
453 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
454 break;
455 case ConfirmEmailDialogDelegate::CLOSE:
456 if (handler_) {
457 handler_->SyncStarterCallback(
458 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
459 }
460 break;
461 default:
462 DCHECK(false) << "Invalid action";
463 }
222 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 464 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
223 } 465 }
224 466
225 void InlineSigninHelper::OnClientOAuthFailure( 467 void InlineSigninHelper::OnClientOAuthFailure(
226 const GoogleServiceAuthError& error) { 468 const GoogleServiceAuthError& error) {
227 if (handler_) 469 if (handler_)
228 handler_->HandleLoginError(error.ToString()); 470 handler_->HandleLoginError(error.ToString());
229 471
230 AboutSigninInternals* about_signin_internals = 472 AboutSigninInternals* about_signin_internals =
231 AboutSigninInternalsFactory::GetForProfile(profile_); 473 AboutSigninInternalsFactory::GetForProfile(profile_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (!url.is_empty()) { 506 if (!url.is_empty()) {
265 GURL origin(url.GetOrigin()); 507 GURL origin(url.GetOrigin());
266 if (url.spec() != url::kAboutBlankURL && 508 if (url.spec() != url::kAboutBlankURL &&
267 origin != kGaiaExtOrigin && 509 origin != kGaiaExtOrigin &&
268 !gaia::IsGaiaSignonRealm(origin)) { 510 !gaia::IsGaiaSignonRealm(origin)) {
269 confirm_untrusted_signin_ = true; 511 confirm_untrusted_signin_ = true;
270 } 512 }
271 } 513 }
272 } 514 }
273 515
516 // static
517 bool InlineLoginHandlerImpl::CanOffer(Profile* profile,
518 CanOfferFor can_offer_for,
519 const std::string& email,
520 std::string* error_message) {
521 if (error_message)
522 error_message->clear();
523
524 if (!profile)
525 return false;
526
527 SigninManager* manager = SigninManagerFactory::GetForProfile(profile);
528 if (manager && !manager->IsSigninAllowed())
529 return false;
530
531 if (!ChromeSigninClient::ProfileAllowsSigninCookies(profile))
532 return false;
533
534 if (!email.empty()) {
535 if (!manager)
536 return false;
537
538 // Make sure this username is not prohibited by policy.
539 if (!manager->IsAllowedUsername(email)) {
540 if (error_message) {
541 error_message->assign(
542 l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED));
543 }
544 return false;
545 }
546
547 if (can_offer_for == CAN_OFFER_FOR_SECONDARY_ACCOUNT)
548 return true;
549
550 // If the signin manager already has an authenticated name, then this is a
551 // re-auth scenario. Make sure the email just signed in corresponds to
552 // the one sign in manager expects.
553 std::string current_email = manager->GetAuthenticatedUsername();
554 const bool same_email = gaia::AreEmailsSame(current_email, email);
555 if (!current_email.empty() && !same_email) {
556 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth",
557 signin_metrics::HISTOGRAM_ACCOUNT_MISSMATCH,
558 signin_metrics::HISTOGRAM_MAX);
559 if (error_message) {
560 error_message->assign(
561 l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL,
562 base::UTF8ToUTF16(current_email)));
563 }
564 return false;
565 }
566
567 // If some profile, not just the current one, is already connected to this
568 // account, don't show the infobar.
569 if (g_browser_process && !same_email) {
570 ProfileManager* manager = g_browser_process->profile_manager();
brucedawson 2015/03/13 18:43:48 The use of a manager variable here shadows the man
Roger Tawa OOO till Jul 10th 2015/03/13 21:24:54 Yes worth fixing. I'll do so in a new CL. Thanks
571 if (manager) {
572 ProfileInfoCache& cache = manager->GetProfileInfoCache();
573 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
574 std::string current_email =
brucedawson 2015/03/13 18:43:48 Ditto for this variable. In this case the type is
Roger Tawa OOO till Jul 10th 2015/03/13 21:24:54 Ditto.
575 base::UTF16ToUTF8(cache.GetUserNameOfProfileAtIndex(i));
576 if (gaia::AreEmailsSame(email, current_email)) {
577 if (error_message) {
578 error_message->assign(
579 l10n_util::GetStringUTF8(IDS_SYNC_USER_NAME_IN_USE_ERROR));
580 }
581 return false;
582 }
583 }
584 }
585 }
586 }
587
588 return true;
589 }
590
274 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { 591 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
275 params.SetString("service", "chromiumsync"); 592 params.SetString("service", "chromiumsync");
276 593
277 content::WebContents* contents = web_ui()->GetWebContents(); 594 content::WebContents* contents = web_ui()->GetWebContents();
278 const GURL& current_url = contents->GetURL(); 595 const GURL& current_url = contents->GetURL();
279 std::string is_constrained; 596 std::string is_constrained;
280 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); 597 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
281 598
282 content::WebContentsObserver::Observe(contents); 599 content::WebContentsObserver::Observe(contents);
283 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); 600 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN);
284 } 601 }
285 602
286 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 603 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
287 content::WebContents* contents = web_ui()->GetWebContents(); 604 content::WebContents* contents = web_ui()->GetWebContents();
288 const GURL& current_url = contents->GetURL(); 605 const GURL& current_url = contents->GetURL();
289 606
290 const base::DictionaryValue* dict = NULL; 607 const base::DictionaryValue* dict = NULL;
291 args->GetDictionary(0, &dict); 608 args->GetDictionary(0, &dict);
292 609
293 bool skip_for_now = false; 610 bool skip_for_now = false;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 652
336 base::string16 session_index_string16; 653 base::string16 session_index_string16;
337 dict->GetString("sessionIndex", &session_index_string16); 654 dict->GetString("sessionIndex", &session_index_string16);
338 std::string session_index = base::UTF16ToASCII(session_index_string16); 655 std::string session_index = base::UTF16ToASCII(session_index_string16);
339 DCHECK(!session_index.empty()); 656 DCHECK(!session_index.empty());
340 657
341 bool choose_what_to_sync = false; 658 bool choose_what_to_sync = false;
342 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); 659 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync);
343 660
344 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); 661 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
345 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); 662 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED);
346 bool switch_to_advanced = 663 bool switch_to_advanced =
347 choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); 664 choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS);
348 OneClickSigninHelper::LogHistogramValue( 665 LogHistogramValue(
349 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : 666 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED :
350 signin_metrics::HISTOGRAM_WITH_DEFAULTS); 667 signin_metrics::HISTOGRAM_WITH_DEFAULTS);
351 668
352 OneClickSigninHelper::CanOfferFor can_offer_for = 669 CanOfferFor can_offer_for = CAN_OFFER_FOR_ALL;
353 OneClickSigninHelper::CAN_OFFER_FOR_ALL;
354 switch (source) { 670 switch (source) {
355 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: 671 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT:
356 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; 672 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT;
357 break; 673 break;
358 case signin_metrics::SOURCE_REAUTH: { 674 case signin_metrics::SOURCE_REAUTH: {
359 std::string primary_username = 675 std::string primary_username =
360 SigninManagerFactory::GetForProfile( 676 SigninManagerFactory::GetForProfile(
361 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername(); 677 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername();
362 if (!gaia::AreEmailsSame(default_email, primary_username)) 678 if (!gaia::AreEmailsSame(default_email, primary_username))
363 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; 679 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT;
364 break; 680 break;
365 } 681 }
366 default: 682 default:
367 // No need to change |can_offer_for|. 683 // No need to change |can_offer_for|.
368 break; 684 break;
369 } 685 }
370 686
371 std::string error_msg; 687 std::string error_msg;
372 bool can_offer = OneClickSigninHelper::CanOffer( 688 bool can_offer = CanOffer(Profile::FromWebUI(web_ui()), can_offer_for,
373 contents, can_offer_for, email, &error_msg); 689 email, &error_msg);
374 if (!can_offer) { 690 if (!can_offer) {
375 HandleLoginError(error_msg); 691 HandleLoginError(error_msg);
376 return; 692 return;
377 } 693 }
378 694
379 AboutSigninInternals* about_signin_internals = 695 AboutSigninInternals* about_signin_internals =
380 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); 696 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui()));
381 about_signin_internals->OnAuthenticationResultReceived( 697 about_signin_internals->OnAuthenticationResultReceived(
382 "GAIA Auth Successful"); 698 "GAIA Auth Successful");
383 699
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // from DidStartLoading. This avoids deleting the pending entry while we are 744 // from DidStartLoading. This avoids deleting the pending entry while we are
429 // still navigating to it. See crbug/346632. 745 // still navigating to it. See crbug/346632.
430 return; 746 return;
431 } 747 }
432 748
433 const GURL& current_url = contents->GetLastCommittedURL(); 749 const GURL& current_url = contents->GetLastCommittedURL();
434 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); 750 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
435 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); 751 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url);
436 752
437 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { 753 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) {
438 OneClickSigninHelper::RedirectToNtpOrAppsPage(contents, source); 754 RedirectToNtpOrAppsPage(contents, source);
439 } else if (auto_close) { 755 } else if (auto_close) {
440 base::MessageLoop::current()->PostTask( 756 base::MessageLoop::current()->PostTask(
441 FROM_HERE, 757 FROM_HERE,
442 base::Bind(&InlineLoginHandlerImpl::CloseTab, 758 base::Bind(&InlineLoginHandlerImpl::CloseTab,
443 weak_factory_.GetWeakPtr(), 759 weak_factory_.GetWeakPtr(),
444 signin::ShouldShowAccountManagement(current_url))); 760 signin::ShouldShowAccountManagement(current_url)));
445 } else { 761 } else {
446 OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(contents, source); 762 RedirectToNtpOrAppsPageIfNecessary(contents, source);
447 } 763 }
448 } 764 }
449 765
450 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { 766 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) {
451 content::WebContents* tab = web_ui()->GetWebContents(); 767 content::WebContents* tab = web_ui()->GetWebContents();
452 Browser* browser = chrome::FindBrowserWithWebContents(tab); 768 Browser* browser = chrome::FindBrowserWithWebContents(tab);
453 if (browser) { 769 if (browser) {
454 TabStripModel* tab_strip_model = browser->tab_strip_model(); 770 TabStripModel* tab_strip_model = browser->tab_strip_model();
455 if (tab_strip_model) { 771 if (tab_strip_model) {
456 int index = tab_strip_model->GetIndexOfWebContents(tab); 772 int index = tab_strip_model->GetIndexOfWebContents(tab);
457 if (index != TabStripModel::kNoTab) { 773 if (index != TabStripModel::kNoTab) {
458 tab_strip_model->ExecuteContextMenuCommand( 774 tab_strip_model->ExecuteContextMenuCommand(
459 index, TabStripModel::CommandCloseTab); 775 index, TabStripModel::CommandCloseTab);
460 } 776 }
461 } 777 }
462 778
463 if (show_account_management) { 779 if (show_account_management) {
464 browser->window()->ShowAvatarBubbleFromAvatarButton( 780 browser->window()->ShowAvatarBubbleFromAvatarButton(
465 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 781 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
466 signin::ManageAccountsParams()); 782 signin::ManageAccountsParams());
467 } 783 }
468 } 784 }
469 } 785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698