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

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

Issue 16092009: Make sure OneClickSigninSyncStarter detects Browser object being closed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch before 2nd commit Created 7 years, 6 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
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_sync_starter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 10
11 #if defined(ENABLE_CONFIGURATION_POLICY) 11 #if defined(ENABLE_CONFIGURATION_POLICY)
12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" 12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h"
13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
14 #endif 14 #endif
15 15
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
18 #include "chrome/browser/profiles/profile_io_data.h" 18 #include "chrome/browser/profiles/profile_io_data.h"
19 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/signin/signin_manager.h" 20 #include "chrome/browser/signin/signin_manager.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync/sync_prefs.h" 24 #include "chrome/browser/sync/sync_prefs.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_dialogs.h" 26 #include "chrome/browser/ui/browser_dialogs.h"
27 #include "chrome/browser/ui/browser_finder.h" 27 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_navigator.h" 29 #include "chrome/browser/ui/browser_navigator.h"
30 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/chrome_pages.h" 32 #include "chrome/browser/ui/chrome_pages.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 33 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 34 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
34 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" 36 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
35 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
36 #include "grit/chromium_strings.h" 38 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 39 #include "grit/generated_resources.h"
38 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h" 41 #include "ui/base/resource/resource_bundle.h"
40 42
41 OneClickSigninSyncStarter::OneClickSigninSyncStarter( 43 OneClickSigninSyncStarter::OneClickSigninSyncStarter(
42 Profile* profile, 44 Profile* profile,
43 Browser* browser, 45 Browser* browser,
44 const std::string& session_index, 46 const std::string& session_index,
45 const std::string& email, 47 const std::string& email,
46 const std::string& password, 48 const std::string& password,
47 StartSyncMode start_mode, 49 StartSyncMode start_mode,
48 bool force_same_tab_navigation, 50 bool force_same_tab_navigation,
49 ConfirmationRequired confirmation_required) 51 ConfirmationRequired confirmation_required)
50 : start_mode_(start_mode), 52 : start_mode_(start_mode),
51 force_same_tab_navigation_(force_same_tab_navigation), 53 force_same_tab_navigation_(force_same_tab_navigation),
52 confirmation_required_(confirmation_required), 54 confirmation_required_(confirmation_required),
53 weak_pointer_factory_(this) { 55 weak_pointer_factory_(this) {
54 DCHECK(profile); 56 DCHECK(profile);
57 BrowserList::AddObserver(this);
58
55 Initialize(profile, browser); 59 Initialize(profile, browser);
56 60
57 // Start the signin process using the cookies in the cookie jar. 61 // Start the signin process using the cookies in the cookie jar.
58 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_); 62 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_);
59 SigninManager::OAuthTokenFetchedCallback callback; 63 SigninManager::OAuthTokenFetchedCallback callback;
60 // Policy is enabled, so pass in a callback to do extra policy-related UI 64 // Policy is enabled, so pass in a callback to do extra policy-related UI
61 // before signin completes. 65 // before signin completes.
62 callback = base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, 66 callback = base::Bind(&OneClickSigninSyncStarter::ConfirmSignin,
63 weak_pointer_factory_.GetWeakPtr()); 67 weak_pointer_factory_.GetWeakPtr());
64 manager->StartSignInWithCredentials(session_index, email, password, callback); 68 manager->StartSignInWithCredentials(session_index, email, password, callback);
65 } 69 }
66 70
71 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) {
72 if (browser == browser_)
73 browser_ = NULL;
74 }
75
67 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { 76 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() {
77 BrowserList::RemoveObserver(this);
68 } 78 }
69 79
70 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { 80 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) {
71 DCHECK(profile); 81 DCHECK(profile);
72 profile_ = profile; 82 profile_ = profile;
73 browser_ = browser; 83 browser_ = browser;
74 84
75 // Cache the parent desktop for the browser, so we can reuse that same 85 // Cache the parent desktop for the browser, so we can reuse that same
76 // desktop for any UI we want to display. 86 // desktop for any UI we want to display.
77 if (browser) 87 if (browser)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 chrome::startup::IS_PROCESS_STARTUP, 266 chrome::startup::IS_PROCESS_STARTUP,
257 chrome::startup::IS_FIRST_RUN, 267 chrome::startup::IS_FIRST_RUN,
258 desktop_type, 268 desktop_type,
259 false); 269 false);
260 } 270 }
261 } 271 }
262 #endif 272 #endif
263 273
264 void OneClickSigninSyncStarter::ConfirmAndSignin() { 274 void OneClickSigninSyncStarter::ConfirmAndSignin() {
265 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); 275 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
266 // browser_ can be null for unit tests. 276 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) {
267 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { 277 EnsureBrowser();
268 // Display a confirmation dialog to the user. 278 // Display a confirmation dialog to the user.
269 browser_->window()->ShowOneClickSigninBubble( 279 browser_->window()->ShowOneClickSigninBubble(
270 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, 280 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG,
271 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), 281 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()),
272 string16(), // No error message to display. 282 string16(), // No error message to display.
273 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, 283 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed,
274 weak_pointer_factory_.GetWeakPtr())); 284 weak_pointer_factory_.GetWeakPtr()));
275 } else { 285 } else {
276 // No confirmation required - just sign in the user. 286 // No confirmation required - just sign in the user.
277 signin->CompletePendingSignin(); 287 signin->CompletePendingSignin();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 browser_->window()->ShowOneClickSigninBubble( 360 browser_->window()->ShowOneClickSigninBubble(
351 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 361 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
352 string16(), // No email required - this is not a SAML confirmation. 362 string16(), // No email required - this is not a SAML confirmation.
353 custom_message, 363 custom_message,
354 // Callback is ignored. 364 // Callback is ignored.
355 BrowserWindow::StartSyncCallback()); 365 BrowserWindow::StartSyncCallback());
356 } 366 }
357 367
358 void OneClickSigninSyncStarter::EnsureBrowser() { 368 void OneClickSigninSyncStarter::EnsureBrowser() {
359 if (!browser_) { 369 if (!browser_) {
360 // The user just created a new profile so we need to figure out what 370 // The user just created a new profile or has closed the browser that
361 // browser to use to display settings. Grab the most recently active 371 // we used previously. Grab the most recently active browser or else
362 // browser or else create a new one. 372 // create a new one.
363 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); 373 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_);
364 if (!browser_) { 374 if (!browser_) {
365 browser_ = new Browser(Browser::CreateParams(profile_, 375 browser_ = new Browser(Browser::CreateParams(profile_,
366 desktop_type_)); 376 desktop_type_));
377 chrome::AddBlankTabAt(browser_, -1, true);
Andrew T Wilson (Slow) 2013/06/05 08:43:51 Why is this necessary? This code was working prope
(NOT FOR CODE REVIEWS) 2013/06/05 14:11:34 Maybe something changed since the time you looked
fdoray 2013/06/05 15:09:04 When you create a new profile as part of the sign
367 } 378 }
368 browser_->window()->Show(); 379 browser_->window()->Show();
369 } 380 }
370 } 381 }
371 382
372 void OneClickSigninSyncStarter::ConfigureSync() { 383 void OneClickSigninSyncStarter::ConfigureSync() {
373 // Give the user a chance to configure things. We don't clear the 384 // Give the user a chance to configure things. We don't clear the
374 // ProfileSyncService::setup_in_progress flag because we don't want sync 385 // ProfileSyncService::setup_in_progress flag because we don't want sync
375 // to start up until after the configure UI is displayed (the configure UI 386 // to start up until after the configure UI is displayed (the configure UI
376 // will clear the flag when the user is done setting up sync). 387 // will clear the flag when the user is done setting up sync).
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 422
412 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { 423 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() {
413 std::string url = std::string(chrome::kChromeUISettingsURL) + 424 std::string url = std::string(chrome::kChromeUISettingsURL) +
414 chrome::kSyncSetupSubPage; 425 chrome::kSyncSetupSubPage;
415 chrome::NavigateParams params( 426 chrome::NavigateParams params(
416 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); 427 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL);
417 params.disposition = CURRENT_TAB; 428 params.disposition = CURRENT_TAB;
418 params.window_action = chrome::NavigateParams::SHOW_WINDOW; 429 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
419 chrome::Navigate(&params); 430 chrome::Navigate(&params);
420 } 431 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_sync_starter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698