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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_dialogs.h" | 28 #include "chrome/browser/ui/browser_dialogs.h" |
29 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
30 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
32 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
33 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
35 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" | 35 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
37 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
38 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
39 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | 38 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
40 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
41 #include "components/signin/core/browser/signin_manager.h" | 40 #include "components/signin/core/browser/signin_manager.h" |
42 #include "components/signin/core/browser/signin_metrics.h" | 41 #include "components/signin/core/browser/signin_metrics.h" |
43 #include "components/signin/core/common/profile_management_switches.h" | 42 #include "components/signin/core/common/profile_management_switches.h" |
44 #include "components/sync_driver/sync_prefs.h" | 43 #include "components/sync_driver/sync_prefs.h" |
45 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
46 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
47 #include "net/url_request/url_request_context_getter.h" | 46 #include "net/url_request/url_request_context_getter.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 : content::WebContentsObserver(web_contents), | 87 : content::WebContentsObserver(web_contents), |
89 start_mode_(start_mode), | 88 start_mode_(start_mode), |
90 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 89 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
91 confirmation_required_(confirmation_required), | 90 confirmation_required_(confirmation_required), |
92 continue_url_(continue_url), | 91 continue_url_(continue_url), |
93 sync_setup_completed_callback_(sync_setup_completed_callback), | 92 sync_setup_completed_callback_(sync_setup_completed_callback), |
94 weak_pointer_factory_(this) { | 93 weak_pointer_factory_(this) { |
95 DCHECK(profile); | 94 DCHECK(profile); |
96 DCHECK(web_contents || continue_url.is_empty()); | 95 DCHECK(web_contents || continue_url.is_empty()); |
97 BrowserList::AddObserver(this); | 96 BrowserList::AddObserver(this); |
98 | 97 LoginUIServiceFactory::GetForProfile(profile)->AddObserver(this); |
99 Initialize(profile, browser); | 98 Initialize(profile, browser); |
100 | 99 |
101 // Policy is enabled, so pass in a callback to do extra policy-related UI | 100 // Policy is enabled, so pass in a callback to do extra policy-related UI |
102 // before signin completes. | 101 // before signin completes. |
103 SigninManagerFactory::GetForProfile(profile_)-> | 102 SigninManagerFactory::GetForProfile(profile_)-> |
104 StartSignInWithRefreshToken( | 103 StartSignInWithRefreshToken( |
105 refresh_token, email, password, | 104 refresh_token, email, password, |
106 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, | 105 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, |
107 weak_pointer_factory_.GetWeakPtr())); | 106 weak_pointer_factory_.GetWeakPtr())); |
108 } | 107 } |
109 | 108 |
110 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { | 109 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { |
111 if (browser == browser_) | 110 if (browser == browser_) |
112 browser_ = NULL; | 111 browser_ = NULL; |
113 } | 112 } |
114 | 113 |
115 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { | 114 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { |
116 BrowserList::RemoveObserver(this); | 115 BrowserList::RemoveObserver(this); |
116 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | |
117 } | 117 } |
118 | 118 |
119 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { | 119 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { |
120 DCHECK(profile); | 120 DCHECK(profile); |
121 profile_ = profile; | 121 profile_ = profile; |
122 browser_ = browser; | 122 browser_ = browser; |
123 | 123 |
124 // Cache the parent desktop for the browser, so we can reuse that same | 124 // Cache the parent desktop for the browser, so we can reuse that same |
125 // desktop for any UI we want to display. | 125 // desktop for any UI we want to display. |
126 if (browser) { | 126 if (browser) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 } else { | 369 } else { |
370 // If the user clicked the "Advanced" link in the confirmation dialog, then | 370 // If the user clicked the "Advanced" link in the confirmation dialog, then |
371 // override the current start_mode_ to bring up the advanced sync settings. | 371 // override the current start_mode_ to bring up the advanced sync settings. |
372 if (response == CONFIGURE_SYNC_FIRST) | 372 if (response == CONFIGURE_SYNC_FIRST) |
373 start_mode_ = response; | 373 start_mode_ = response; |
374 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 374 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
375 signin->CompletePendingSignin(); | 375 signin->CompletePendingSignin(); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 void OneClickSigninSyncStarter::OnSyncConfirmationUIClosed( | |
380 bool configure_sync_first) { | |
381 if (configure_sync_first) { | |
382 ShowSettingsPage(true); | |
383 } else { | |
384 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | |
385 if (profile_sync_service) | |
386 profile_sync_service->SetSyncSetupCompleted(); | |
387 FinishProfileSyncServiceSetup(); | |
388 } | |
389 | |
390 delete this; | |
391 } | |
Roger Tawa OOO till Jul 10th
2014/08/05 16:02:13
Are we guaranteed to get this callback?
guohui
2014/08/05 19:27:41
i think yes as long as Chrome shuts down properly.
guohui
2014/08/06 13:42:52
eh actually i missed one case =(
The callback wil
Roger Tawa OOO till Jul 10th
2014/08/06 14:09:41
You have another bug to make the bubble not auto-c
| |
392 | |
379 void OneClickSigninSyncStarter::SigninFailed( | 393 void OneClickSigninSyncStarter::SigninFailed( |
380 const GoogleServiceAuthError& error) { | 394 const GoogleServiceAuthError& error) { |
381 if (!sync_setup_completed_callback_.is_null()) | 395 if (!sync_setup_completed_callback_.is_null()) |
382 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); | 396 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); |
383 | 397 |
384 FinishProfileSyncServiceSetup(); | 398 FinishProfileSyncServiceSetup(); |
385 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { | 399 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
386 switch (error.state()) { | 400 switch (error.state()) { |
387 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | 401 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
388 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( | 402 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 base::string16 message; | 438 base::string16 message; |
425 if (!profile_sync_service) { | 439 if (!profile_sync_service) { |
426 // Sync is disabled by policy. | 440 // Sync is disabled by policy. |
427 message = l10n_util::GetStringUTF16( | 441 message = l10n_util::GetStringUTF16( |
428 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); | 442 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
429 } | 443 } |
430 DisplayFinalConfirmationBubble(message); | 444 DisplayFinalConfirmationBubble(message); |
431 } | 445 } |
432 break; | 446 break; |
433 } | 447 } |
448 case CONFIRM_SYNC_SETTINGS_FIRST: | |
449 // Blocks sync until the sync settings confirmation UI is closed. | |
450 return; | |
434 case CONFIGURE_SYNC_FIRST: | 451 case CONFIGURE_SYNC_FIRST: |
435 ShowSettingsPage(true); // Show sync config UI. | 452 ShowSettingsPage(true); // Show sync config UI. |
436 break; | 453 break; |
437 case SHOW_SETTINGS_WITHOUT_CONFIGURE: | 454 case SHOW_SETTINGS_WITHOUT_CONFIGURE: |
438 ShowSettingsPage(false); // Don't show sync config UI. | 455 ShowSettingsPage(false); // Don't show sync config UI. |
439 break; | 456 break; |
440 case UNDO_SYNC: | 457 case UNDO_SYNC: |
441 NOTREACHED(); | 458 NOTREACHED(); |
442 } | 459 } |
443 | 460 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 false /* user_gesture */); | 597 false /* user_gesture */); |
581 } | 598 } |
582 | 599 |
583 void OneClickSigninSyncStarter::LoadContinueUrl() { | 600 void OneClickSigninSyncStarter::LoadContinueUrl() { |
584 web_contents()->GetController().LoadURL( | 601 web_contents()->GetController().LoadURL( |
585 continue_url_, | 602 continue_url_, |
586 content::Referrer(), | 603 content::Referrer(), |
587 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 604 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
588 std::string()); | 605 std::string()); |
589 } | 606 } |
OLD | NEW |