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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_starter.cc

Issue 471023003: Make sure the new confirmation bubble is always shown upon signin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 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 | Annotate | Revision Log
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/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Browser* browser, 77 Browser* browser,
78 const std::string& email, 78 const std::string& email,
79 const std::string& password, 79 const std::string& password,
80 const std::string& refresh_token, 80 const std::string& refresh_token,
81 StartSyncMode start_mode, 81 StartSyncMode start_mode,
82 content::WebContents* web_contents, 82 content::WebContents* web_contents,
83 ConfirmationRequired confirmation_required, 83 ConfirmationRequired confirmation_required,
84 const GURL& continue_url, 84 const GURL& continue_url,
85 Callback sync_setup_completed_callback) 85 Callback sync_setup_completed_callback)
86 : content::WebContentsObserver(web_contents), 86 : content::WebContentsObserver(web_contents),
87 profile_(NULL),
87 start_mode_(start_mode), 88 start_mode_(start_mode),
88 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), 89 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE),
89 confirmation_required_(confirmation_required), 90 confirmation_required_(confirmation_required),
90 continue_url_(continue_url), 91 continue_url_(continue_url),
91 sync_setup_completed_callback_(sync_setup_completed_callback), 92 sync_setup_completed_callback_(sync_setup_completed_callback),
92 weak_pointer_factory_(this) { 93 weak_pointer_factory_(this) {
93 DCHECK(profile); 94 DCHECK(profile);
94 DCHECK(web_contents || continue_url.is_empty()); 95 DCHECK(web_contents || continue_url.is_empty());
95 BrowserList::AddObserver(this); 96 BrowserList::AddObserver(this);
96 LoginUIServiceFactory::GetForProfile(profile)->AddObserver(this);
97 Initialize(profile, browser); 97 Initialize(profile, browser);
98 98
99 // Policy is enabled, so pass in a callback to do extra policy-related UI 99 // Policy is enabled, so pass in a callback to do extra policy-related UI
100 // before signin completes. 100 // before signin completes.
101 SigninManagerFactory::GetForProfile(profile_)-> 101 SigninManagerFactory::GetForProfile(profile_)->
102 StartSignInWithRefreshToken( 102 StartSignInWithRefreshToken(
103 refresh_token, email, password, 103 refresh_token, email, password,
104 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, 104 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin,
105 weak_pointer_factory_.GetWeakPtr())); 105 weak_pointer_factory_.GetWeakPtr()));
106 } 106 }
107 107
108 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { 108 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) {
109 if (browser == browser_) 109 if (browser == browser_)
110 browser_ = NULL; 110 browser_ = NULL;
111 } 111 }
112 112
113 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { 113 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() {
114 BrowserList::RemoveObserver(this); 114 BrowserList::RemoveObserver(this);
115 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); 115 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
116 } 116 }
117 117
118 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { 118 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) {
119 DCHECK(profile); 119 DCHECK(profile);
120
121 if (profile_)
122 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
123
120 profile_ = profile; 124 profile_ = profile;
121 browser_ = browser; 125 browser_ = browser;
122 126
127 LoginUIServiceFactory::GetForProfile(profile_)->AddObserver(this);
128
123 // Cache the parent desktop for the browser, so we can reuse that same 129 // Cache the parent desktop for the browser, so we can reuse that same
124 // desktop for any UI we want to display. 130 // desktop for any UI we want to display.
125 if (browser) { 131 if (browser) {
126 desktop_type_ = browser->host_desktop_type(); 132 desktop_type_ = browser->host_desktop_type();
127 } else { 133 } else {
128 desktop_type_ = chrome::GetActiveDesktop(); 134 desktop_type_ = chrome::GetActiveDesktop();
129 } 135 }
130 136
131 signin_tracker_ = SigninTrackerFactory::CreateForProfile(profile_, this); 137 signin_tracker_ = SigninTrackerFactory::CreateForProfile(profile_, this);
132 138
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 184
179 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { 185 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() {
180 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); 186 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL);
181 if (sync_starter_ != NULL) 187 if (sync_starter_ != NULL)
182 sync_starter_->CancelSigninAndDelete(); 188 sync_starter_->CancelSigninAndDelete();
183 } 189 }
184 190
185 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { 191 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() {
186 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); 192 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE);
187 193
188 if (sync_starter_ != NULL) { 194 if (sync_starter_ != NULL)
189 // If the user signs in from the new avatar bubble, the enterprise
190 // confirmation dialog would dismiss the avatar bubble, thus it won't show
191 // any confirmation upon sign in completes. This cofirmation dialog already
192 // mentions that user data would be synced, thus we just start sync
193 // immediately.
194
195 // TODO(guohui): add a sync settings link to allow user to configure sync
196 // settings before sync starts.
197 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST)
198 sync_starter_->SetStartSyncMode(SYNC_WITH_DEFAULT_SETTINGS);
199 sync_starter_->LoadPolicyWithCachedCredentials(); 195 sync_starter_->LoadPolicyWithCachedCredentials();
200 }
201 } 196 }
202 197
203 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { 198 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() {
204 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); 199 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE);
205 200
206 if (sync_starter_ != NULL) { 201 if (sync_starter_ != NULL)
207 // TODO(guohui): add a sync settings link to allow user to configure sync
208 // settings before sync starts.
209 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST)
210 sync_starter_->SetStartSyncMode(SYNC_WITH_DEFAULT_SETTINGS);
211 sync_starter_->CreateNewSignedInProfile(); 202 sync_starter_->CreateNewSignedInProfile();
212 }
213 }
214
215 void OneClickSigninSyncStarter::SetStartSyncMode(StartSyncMode start_mode) {
216 start_mode_ = start_mode;
217 }
218
219 OneClickSigninSyncStarter::StartSyncMode
220 OneClickSigninSyncStarter::GetStartSyncMode() {
221 return start_mode_;
222 } 203 }
223 204
224 void OneClickSigninSyncStarter::OnRegisteredForPolicy( 205 void OneClickSigninSyncStarter::OnRegisteredForPolicy(
225 const std::string& dm_token, const std::string& client_id) { 206 const std::string& dm_token, const std::string& client_id) {
226 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); 207 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
227 // If there's no token for the user (policy registration did not succeed) just 208 // If there's no token for the user (policy registration did not succeed) just
228 // finish signing in. 209 // finish signing in.
229 if (dm_token.empty()) { 210 if (dm_token.empty()) {
230 DVLOG(1) << "Policy registration failed"; 211 DVLOG(1) << "Policy registration failed";
231 ConfirmAndSignin(); 212 ConfirmAndSignin();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // Sync is disabled by policy. 456 // Sync is disabled by policy.
476 message = l10n_util::GetStringUTF16( 457 message = l10n_util::GetStringUTF16(
477 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); 458 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE);
478 } 459 }
479 DisplayFinalConfirmationBubble(message); 460 DisplayFinalConfirmationBubble(message);
480 } 461 }
481 break; 462 break;
482 } 463 }
483 case CONFIRM_SYNC_SETTINGS_FIRST: 464 case CONFIRM_SYNC_SETTINGS_FIRST:
484 // Blocks sync until the sync settings confirmation UI is closed. 465 // Blocks sync until the sync settings confirmation UI is closed.
466 DisplayFinalConfirmationBubble(base::string16());
485 return; 467 return;
486 case CONFIGURE_SYNC_FIRST: 468 case CONFIGURE_SYNC_FIRST:
487 ShowSettingsPage(true); // Show sync config UI. 469 ShowSettingsPage(true); // Show sync config UI.
488 break; 470 break;
489 case SHOW_SETTINGS_WITHOUT_CONFIGURE: 471 case SHOW_SETTINGS_WITHOUT_CONFIGURE:
490 ShowSettingsPage(false); // Don't show sync config UI. 472 ShowSettingsPage(false); // Don't show sync config UI.
491 break; 473 break;
492 case UNDO_SYNC: 474 case UNDO_SYNC:
493 NOTREACHED(); 475 NOTREACHED();
494 } 476 }
495 477
496 // Navigate to the |continue_url_| if one is set, unless the user first needs 478 // Navigate to the |continue_url_| if one is set, unless the user first needs
497 // to configure Sync. 479 // to configure Sync.
498 if (web_contents() && !continue_url_.is_empty() && 480 if (web_contents() && !continue_url_.is_empty() &&
499 start_mode_ != CONFIGURE_SYNC_FIRST) { 481 start_mode_ != CONFIGURE_SYNC_FIRST) {
500 LoadContinueUrl(); 482 LoadContinueUrl();
501 } 483 }
502 484
503 delete this; 485 delete this;
504 } 486 }
505 487
506 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( 488 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble(
507 const base::string16& custom_message) { 489 const base::string16& custom_message) {
508 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); 490 browser_ = EnsureBrowser(browser_, profile_, desktop_type_);
491 // Show the success confirmation message in the new avatar menu if it is
492 // enabled.
493 // TODO(guohui): needs to handle custom messages.
494 if (custom_message.empty() && switches::IsNewAvatarMenu()) {
495 browser_->window()->ShowAvatarBubbleFromAvatarButton(
496 BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN,
497 signin::ManageAccountsParams());
498 return;
499 }
500
509 browser_->window()->ShowOneClickSigninBubble( 501 browser_->window()->ShowOneClickSigninBubble(
510 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 502 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
511 base::string16(), // No email required - this is not a SAML confirmation. 503 base::string16(), // No email required - this is not a SAML confirmation.
512 custom_message, 504 custom_message,
513 // Callback is ignored. 505 // Callback is ignored.
514 BrowserWindow::StartSyncCallback()); 506 BrowserWindow::StartSyncCallback());
515 } 507 }
516 508
517 // static 509 // static
518 Browser* OneClickSigninSyncStarter::EnsureBrowser( 510 Browser* OneClickSigninSyncStarter::EnsureBrowser(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 false /* user_gesture */); 624 false /* user_gesture */);
633 } 625 }
634 626
635 void OneClickSigninSyncStarter::LoadContinueUrl() { 627 void OneClickSigninSyncStarter::LoadContinueUrl() {
636 web_contents()->GetController().LoadURL( 628 web_contents()->GetController().LoadURL(
637 continue_url_, 629 continue_url_,
638 content::Referrer(), 630 content::Referrer(),
639 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 631 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
640 std::string()); 632 std::string());
641 } 633 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_sync_starter.h ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698