OLD | NEW |
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/ui/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/metrics/user_metrics.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" | 13 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" |
13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" | 14 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" |
14 #include "chrome/browser/profiles/profile_attributes_entry.h" | 15 #include "chrome/browser/profiles/profile_attributes_entry.h" |
15 #include "chrome/browser/profiles/profile_attributes_storage.h" | 16 #include "chrome/browser/profiles/profile_attributes_storage.h" |
16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
17 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/profiles/profile_window.h" | 20 #include "chrome/browser/profiles/profile_window.h" |
(...skipping 12 matching lines...) Expand all Loading... |
32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "chrome/grit/chromium_strings.h" | 35 #include "chrome/grit/chromium_strings.h" |
35 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
36 #include "components/browser_sync/profile_sync_service.h" | 37 #include "components/browser_sync/profile_sync_service.h" |
37 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
38 #include "components/signin/core/browser/signin_manager.h" | 39 #include "components/signin/core/browser/signin_manager.h" |
39 #include "components/signin/core/browser/signin_metrics.h" | 40 #include "components/signin/core/browser/signin_metrics.h" |
40 #include "components/signin/core/common/profile_management_switches.h" | 41 #include "components/signin/core/common/profile_management_switches.h" |
41 #include "components/sync/base/sync_prefs.h" | 42 #include "components/sync/base/sync_prefs.h" |
42 #include "content/public/browser/user_metrics.h" | |
43 #include "net/base/url_util.h" | 43 #include "net/base/url_util.h" |
44 #include "net/url_request/url_request_context_getter.h" | 44 #include "net/url_request/url_request_context_getter.h" |
45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
46 | 46 |
47 using browser_sync::ProfileSyncService; | 47 using browser_sync::ProfileSyncService; |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 // UMA histogram for tracking what users do when presented with the signin | 51 // UMA histogram for tracking what users do when presented with the signin |
52 // screen. | 52 // screen. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 OneClickSigninSyncStarter::SigninDialogDelegate::SigninDialogDelegate( | 180 OneClickSigninSyncStarter::SigninDialogDelegate::SigninDialogDelegate( |
181 base::WeakPtr<OneClickSigninSyncStarter> sync_starter) | 181 base::WeakPtr<OneClickSigninSyncStarter> sync_starter) |
182 : sync_starter_(sync_starter) { | 182 : sync_starter_(sync_starter) { |
183 } | 183 } |
184 | 184 |
185 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { | 185 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { |
186 } | 186 } |
187 | 187 |
188 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { | 188 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { |
189 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); | 189 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); |
190 content::RecordAction( | 190 base::RecordAction( |
191 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); | 191 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); |
192 if (sync_starter_) | 192 if (sync_starter_) |
193 sync_starter_->CancelSigninAndDelete(); | 193 sync_starter_->CancelSigninAndDelete(); |
194 } | 194 } |
195 | 195 |
196 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { | 196 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { |
197 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); | 197 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); |
198 content::RecordAction( | 198 base::RecordAction( |
199 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_ImportData")); | 199 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_ImportData")); |
200 | 200 |
201 if (sync_starter_) | 201 if (sync_starter_) |
202 sync_starter_->LoadPolicyWithCachedCredentials(); | 202 sync_starter_->LoadPolicyWithCachedCredentials(); |
203 } | 203 } |
204 | 204 |
205 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { | 205 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { |
206 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); | 206 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); |
207 content::RecordAction( | 207 base::RecordAction( |
208 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_DontImportData")); | 208 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_DontImportData")); |
209 | 209 |
210 if (sync_starter_) | 210 if (sync_starter_) |
211 sync_starter_->CreateNewSignedInProfile(); | 211 sync_starter_->CreateNewSignedInProfile(); |
212 } | 212 } |
213 | 213 |
214 void OneClickSigninSyncStarter::OnRegisteredForPolicy( | 214 void OneClickSigninSyncStarter::OnRegisteredForPolicy( |
215 const std::string& dm_token, const std::string& client_id) { | 215 const std::string& dm_token, const std::string& client_id) { |
216 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 216 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
217 // If there's no token for the user (policy registration did not succeed) just | 217 // If there's no token for the user (policy registration did not succeed) just |
(...skipping 14 matching lines...) Expand all Loading... |
232 | 232 |
233 // Allow user to create a new profile before continuing with sign-in. | 233 // Allow user to create a new profile before continuing with sign-in. |
234 browser_ = EnsureBrowser(browser_, profile_); | 234 browser_ = EnsureBrowser(browser_, profile_); |
235 content::WebContents* web_contents = | 235 content::WebContents* web_contents = |
236 browser_->tab_strip_model()->GetActiveWebContents(); | 236 browser_->tab_strip_model()->GetActiveWebContents(); |
237 if (!web_contents) { | 237 if (!web_contents) { |
238 CancelSigninAndDelete(); | 238 CancelSigninAndDelete(); |
239 return; | 239 return; |
240 } | 240 } |
241 | 241 |
242 content::RecordAction( | 242 base::RecordAction( |
243 base::UserMetricsAction("Signin_Show_EnterpriseAccountPrompt")); | 243 base::UserMetricsAction("Signin_Show_EnterpriseAccountPrompt")); |
244 TabDialogs::FromWebContents(web_contents) | 244 TabDialogs::FromWebContents(web_contents) |
245 ->ShowProfileSigninConfirmation(browser_, profile_, | 245 ->ShowProfileSigninConfirmation(browser_, profile_, |
246 signin->GetUsernameForAuthInProgress(), | 246 signin->GetUsernameForAuthInProgress(), |
247 base::MakeUnique<SigninDialogDelegate>( | 247 base::MakeUnique<SigninDialogDelegate>( |
248 weak_pointer_factory_.GetWeakPtr())); | 248 weak_pointer_factory_.GetWeakPtr())); |
249 } | 249 } |
250 | 250 |
251 void OneClickSigninSyncStarter::LoadPolicyWithCachedCredentials() { | 251 void OneClickSigninSyncStarter::LoadPolicyWithCachedCredentials() { |
252 DCHECK(!dm_token_.empty()); | 252 DCHECK(!dm_token_.empty()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 signin_metrics::SignoutDelete::IGNORE_METRIC); | 371 signin_metrics::SignoutDelete::IGNORE_METRIC); |
372 // The statement above results in a call to SigninFailed() which will free | 372 // The statement above results in a call to SigninFailed() which will free |
373 // this object, so do not refer to the OneClickSigninSyncStarter object | 373 // this object, so do not refer to the OneClickSigninSyncStarter object |
374 // after this point. | 374 // after this point. |
375 } | 375 } |
376 | 376 |
377 void OneClickSigninSyncStarter::ConfirmAndSignin() { | 377 void OneClickSigninSyncStarter::ConfirmAndSignin() { |
378 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 378 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
379 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { | 379 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { |
380 browser_ = EnsureBrowser(browser_, profile_); | 380 browser_ = EnsureBrowser(browser_, profile_); |
381 content::RecordAction( | 381 base::RecordAction( |
382 base::UserMetricsAction("Signin_Show_UntrustedSigninPrompt")); | 382 base::UserMetricsAction("Signin_Show_UntrustedSigninPrompt")); |
383 // Display a confirmation dialog to the user. | 383 // Display a confirmation dialog to the user. |
384 browser_->window()->ShowOneClickSigninConfirmation( | 384 browser_->window()->ShowOneClickSigninConfirmation( |
385 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), | 385 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), |
386 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, | 386 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, |
387 weak_pointer_factory_.GetWeakPtr())); | 387 weak_pointer_factory_.GetWeakPtr())); |
388 } else { | 388 } else { |
389 // No confirmation required - just sign in the user. | 389 // No confirmation required - just sign in the user. |
390 signin->CompletePendingSignin(); | 390 signin->CompletePendingSignin(); |
391 } | 391 } |
392 } | 392 } |
393 | 393 |
394 void OneClickSigninSyncStarter::UntrustedSigninConfirmed( | 394 void OneClickSigninSyncStarter::UntrustedSigninConfirmed( |
395 StartSyncMode response) { | 395 StartSyncMode response) { |
396 if (response == UNDO_SYNC) { | 396 if (response == UNDO_SYNC) { |
397 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); | 397 base::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); |
398 CancelSigninAndDelete(); // This statement frees this object. | 398 CancelSigninAndDelete(); // This statement frees this object. |
399 } else { | 399 } else { |
400 // If the user clicked the "Advanced" link in the confirmation dialog, then | 400 // If the user clicked the "Advanced" link in the confirmation dialog, then |
401 // override the current start_mode_ to bring up the advanced sync settings. | 401 // override the current start_mode_ to bring up the advanced sync settings. |
402 | 402 |
403 // If the user signs in from the new avatar bubble, the untrusted dialog | 403 // If the user signs in from the new avatar bubble, the untrusted dialog |
404 // would dismiss the avatar bubble, thus it won't show any confirmation upon | 404 // would dismiss the avatar bubble, thus it won't show any confirmation upon |
405 // sign in completes. This dialog already has a settings link, thus we just | 405 // sign in completes. This dialog already has a settings link, thus we just |
406 // start sync immediately . | 406 // start sync immediately . |
407 | 407 |
(...skipping 11 matching lines...) Expand all Loading... |
419 LoginUIService::SyncConfirmationUIClosedResult result) { | 419 LoginUIService::SyncConfirmationUIClosedResult result) { |
420 | 420 |
421 if (switches::UsePasswordSeparatedSigninFlow()) { | 421 if (switches::UsePasswordSeparatedSigninFlow()) { |
422 // We didn't run this callback in AccountAddedToCookie so do it now. | 422 // We didn't run this callback in AccountAddedToCookie so do it now. |
423 if (!sync_setup_completed_callback_.is_null()) | 423 if (!sync_setup_completed_callback_.is_null()) |
424 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); | 424 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); |
425 } | 425 } |
426 | 426 |
427 switch (result) { | 427 switch (result) { |
428 case LoginUIService::CONFIGURE_SYNC_FIRST: | 428 case LoginUIService::CONFIGURE_SYNC_FIRST: |
429 content::RecordAction( | 429 base::RecordAction( |
430 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); | 430 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); |
431 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 431 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
432 break; | 432 break; |
433 case LoginUIService::SYNC_WITH_DEFAULT_SETTINGS: { | 433 case LoginUIService::SYNC_WITH_DEFAULT_SETTINGS: { |
434 content::RecordAction( | 434 base::RecordAction( |
435 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); | 435 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); |
436 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 436 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
437 if (profile_sync_service) | 437 if (profile_sync_service) |
438 profile_sync_service->SetFirstSetupComplete(); | 438 profile_sync_service->SetFirstSetupComplete(); |
439 FinishProfileSyncServiceSetup(); | 439 FinishProfileSyncServiceSetup(); |
440 break; | 440 break; |
441 } | 441 } |
442 case LoginUIService::ABORT_SIGNIN: | 442 case LoginUIService::ABORT_SIGNIN: |
443 FinishProfileSyncServiceSetup(); | 443 FinishProfileSyncServiceSetup(); |
444 break; | 444 break; |
(...skipping 26 matching lines...) Expand all Loading... |
471 delete this; | 471 delete this; |
472 } | 472 } |
473 | 473 |
474 void OneClickSigninSyncStarter::SigninSuccess() { | 474 void OneClickSigninSyncStarter::SigninSuccess() { |
475 if (!current_url_.is_valid()) // Could be invalid for tests. | 475 if (!current_url_.is_valid()) // Could be invalid for tests. |
476 return; | 476 return; |
477 signin_metrics::LogSigninAccessPointCompleted( | 477 signin_metrics::LogSigninAccessPointCompleted( |
478 signin::GetAccessPointForPromoURL(current_url_)); | 478 signin::GetAccessPointForPromoURL(current_url_)); |
479 signin_metrics::LogSigninReason( | 479 signin_metrics::LogSigninReason( |
480 signin::GetSigninReasonForPromoURL(current_url_)); | 480 signin::GetSigninReasonForPromoURL(current_url_)); |
481 content::RecordAction(base::UserMetricsAction("Signin_Signin_Succeed")); | 481 base::RecordAction(base::UserMetricsAction("Signin_Signin_Succeed")); |
482 } | 482 } |
483 | 483 |
484 void OneClickSigninSyncStarter::AccountAddedToCookie( | 484 void OneClickSigninSyncStarter::AccountAddedToCookie( |
485 const GoogleServiceAuthError& error) { | 485 const GoogleServiceAuthError& error) { |
486 if (first_account_added_to_cookie_) | 486 if (first_account_added_to_cookie_) |
487 return; | 487 return; |
488 | 488 |
489 first_account_added_to_cookie_ = true; | 489 first_account_added_to_cookie_ = true; |
490 | 490 |
491 // Regardless of whether the account was successfully added or not, | 491 // Regardless of whether the account was successfully added or not, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 false /* user_gesture */); | 667 false /* user_gesture */); |
668 } | 668 } |
669 | 669 |
670 void OneClickSigninSyncStarter::LoadContinueUrl() { | 670 void OneClickSigninSyncStarter::LoadContinueUrl() { |
671 web_contents()->GetController().LoadURL( | 671 web_contents()->GetController().LoadURL( |
672 continue_url_, | 672 continue_url_, |
673 content::Referrer(), | 673 content::Referrer(), |
674 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 674 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
675 std::string()); | 675 std::string()); |
676 } | 676 } |
OLD | NEW |