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

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: Added missing OVERRIDE macro 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
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_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_list.h"
27 #include "chrome/browser/ui/browser_navigator.h" 28 #include "chrome/browser/ui/browser_navigator.h"
29 #include "chrome/browser/ui/browser_tabstrip.h"
28 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/chrome_pages.h" 31 #include "chrome/browser/ui/chrome_pages.h"
30 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
31 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
32 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" 34 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
33 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
34 #include "grit/chromium_strings.h" 36 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
38 40
39 OneClickSigninSyncStarter::OneClickSigninSyncStarter( 41 OneClickSigninSyncStarter::OneClickSigninSyncStarter(
40 Profile* profile, 42 Profile* profile,
41 Browser* browser, 43 Browser* browser,
42 const std::string& session_index, 44 const std::string& session_index,
43 const std::string& email, 45 const std::string& email,
44 const std::string& password, 46 const std::string& password,
45 StartSyncMode start_mode, 47 StartSyncMode start_mode,
46 bool force_same_tab_navigation, 48 bool force_same_tab_navigation,
47 ConfirmationRequired confirmation_required) 49 ConfirmationRequired confirmation_required)
48 : start_mode_(start_mode), 50 : start_mode_(start_mode),
49 force_same_tab_navigation_(force_same_tab_navigation), 51 force_same_tab_navigation_(force_same_tab_navigation),
50 confirmation_required_(confirmation_required), 52 confirmation_required_(confirmation_required),
51 weak_pointer_factory_(this) { 53 weak_pointer_factory_(this) {
52 DCHECK(profile); 54 DCHECK(profile);
55 BrowserList::AddObserver(this);
56
53 Initialize(profile, browser); 57 Initialize(profile, browser);
54 58
55 // Start the signin process using the cookies in the cookie jar. 59 // Start the signin process using the cookies in the cookie jar.
56 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_); 60 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_);
57 SigninManager::OAuthTokenFetchedCallback callback; 61 SigninManager::OAuthTokenFetchedCallback callback;
58 // Policy is enabled, so pass in a callback to do extra policy-related UI 62 // Policy is enabled, so pass in a callback to do extra policy-related UI
59 // before signin completes. 63 // before signin completes.
60 callback = base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, 64 callback = base::Bind(&OneClickSigninSyncStarter::ConfirmSignin,
61 weak_pointer_factory_.GetWeakPtr()); 65 weak_pointer_factory_.GetWeakPtr());
62 manager->StartSignInWithCredentials(session_index, email, password, callback); 66 manager->StartSignInWithCredentials(session_index, email, password, callback);
63 } 67 }
64 68
69 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) {
70 if (browser == browser_)
71 browser_ = NULL;
72 }
73
65 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { 74 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() {
75 BrowserList::RemoveObserver(this);
66 } 76 }
67 77
68 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { 78 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) {
69 DCHECK(profile); 79 DCHECK(profile);
70 profile_ = profile; 80 profile_ = profile;
71 browser_ = browser; 81 browser_ = browser;
72 82
73 // Cache the parent desktop for the browser, so we can reuse that same 83 // Cache the parent desktop for the browser, so we can reuse that same
74 // desktop for any UI we want to display. 84 // desktop for any UI we want to display.
75 if (browser) 85 if (browser)
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 chrome::startup::IS_PROCESS_STARTUP, 250 chrome::startup::IS_PROCESS_STARTUP,
241 chrome::startup::IS_FIRST_RUN, 251 chrome::startup::IS_FIRST_RUN,
242 desktop_type, 252 desktop_type,
243 false); 253 false);
244 } 254 }
245 } 255 }
246 #endif 256 #endif
247 257
248 void OneClickSigninSyncStarter::ConfirmAndSignin() { 258 void OneClickSigninSyncStarter::ConfirmAndSignin() {
249 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); 259 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
250 // browser_ can be null for unit tests. 260 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) {
251 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { 261 EnsureBrowser();
252 // Display a confirmation dialog to the user. 262 // Display a confirmation dialog to the user.
253 browser_->window()->ShowOneClickSigninBubble( 263 browser_->window()->ShowOneClickSigninBubble(
254 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, 264 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG,
255 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), 265 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()),
256 string16(), // No error message to display. 266 string16(), // No error message to display.
257 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, 267 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed,
258 weak_pointer_factory_.GetWeakPtr())); 268 weak_pointer_factory_.GetWeakPtr()));
259 } else { 269 } else {
260 // No confirmation required - just sign in the user. 270 // No confirmation required - just sign in the user.
261 signin->CompletePendingSignin(); 271 signin->CompletePendingSignin();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 browser_->window()->ShowOneClickSigninBubble( 344 browser_->window()->ShowOneClickSigninBubble(
335 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 345 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
336 string16(), // No email required - this is not a SAML confirmation. 346 string16(), // No email required - this is not a SAML confirmation.
337 custom_message, 347 custom_message,
338 // Callback is ignored. 348 // Callback is ignored.
339 BrowserWindow::StartSyncCallback()); 349 BrowserWindow::StartSyncCallback());
340 } 350 }
341 351
342 void OneClickSigninSyncStarter::EnsureBrowser() { 352 void OneClickSigninSyncStarter::EnsureBrowser() {
343 if (!browser_) { 353 if (!browser_) {
344 // The user just created a new profile so we need to figure out what 354 // The user just created a new profile or has closed the browser that
345 // browser to use to display settings. Grab the most recently active 355 // we used previously. Grab the most recently active browser or else
346 // browser or else create a new one. 356 // create a new one.
347 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); 357 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_);
348 if (!browser_) { 358 if (!browser_) {
349 browser_ = new Browser(Browser::CreateParams(profile_, 359 browser_ = new Browser(Browser::CreateParams(profile_,
350 desktop_type_)); 360 desktop_type_));
361 chrome::AddBlankTabAt(browser_, -1, true);
351 } 362 }
352 browser_->window()->Show(); 363 browser_->window()->Show();
353 } 364 }
354 } 365 }
355 366
356 void OneClickSigninSyncStarter::ConfigureSync() { 367 void OneClickSigninSyncStarter::ConfigureSync() {
357 // Give the user a chance to configure things. We don't clear the 368 // Give the user a chance to configure things. We don't clear the
358 // ProfileSyncService::setup_in_progress flag because we don't want sync 369 // ProfileSyncService::setup_in_progress flag because we don't want sync
359 // to start up until after the configure UI is displayed (the configure UI 370 // to start up until after the configure UI is displayed (the configure UI
360 // will clear the flag when the user is done setting up sync). 371 // will clear the flag when the user is done setting up sync).
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 406
396 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { 407 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() {
397 std::string url = std::string(chrome::kChromeUISettingsURL) + 408 std::string url = std::string(chrome::kChromeUISettingsURL) +
398 chrome::kSyncSetupSubPage; 409 chrome::kSyncSetupSubPage;
399 chrome::NavigateParams params( 410 chrome::NavigateParams params(
400 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); 411 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL);
401 params.disposition = CURRENT_TAB; 412 params.disposition = CURRENT_TAB;
402 params.window_action = chrome::NavigateParams::SHOW_WINDOW; 413 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
403 chrome::Navigate(&params); 414 chrome::Navigate(&params);
404 } 415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698