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/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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 244 |
235 // Load policy for the just-created profile - once policy has finished | 245 // Load policy for the just-created profile - once policy has finished |
236 // loading the signin process will complete. | 246 // loading the signin process will complete. |
237 LoadPolicyWithCachedClient(); | 247 LoadPolicyWithCachedClient(); |
238 } | 248 } |
239 } | 249 } |
240 #endif | 250 #endif |
241 | 251 |
242 void OneClickSigninSyncStarter::ConfirmAndSignin() { | 252 void OneClickSigninSyncStarter::ConfirmAndSignin() { |
243 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 253 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
244 // browser_ can be null for unit tests. | 254 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { |
fdoray
2013/05/30 16:40:46
The only unit test that involves this method is On
Roger Tawa OOO till Jul 10th
2013/05/30 18:14:49
OK. Sounds like the OneClickSigninHelper unit tes
| |
245 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { | 255 EnsureBrowser(); |
246 // Display a confirmation dialog to the user. | 256 // Display a confirmation dialog to the user. |
247 browser_->window()->ShowOneClickSigninBubble( | 257 browser_->window()->ShowOneClickSigninBubble( |
248 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, | 258 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, |
249 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), | 259 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), |
250 string16(), // No error message to display. | 260 string16(), // No error message to display. |
251 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, | 261 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, |
252 weak_pointer_factory_.GetWeakPtr())); | 262 weak_pointer_factory_.GetWeakPtr())); |
253 } else { | 263 } else { |
254 // No confirmation required - just sign in the user. | 264 // No confirmation required - just sign in the user. |
255 signin->CompletePendingSignin(); | 265 signin->CompletePendingSignin(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 browser_->window()->ShowOneClickSigninBubble( | 340 browser_->window()->ShowOneClickSigninBubble( |
331 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 341 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
332 string16(), // No email required - this is not a SAML confirmation. | 342 string16(), // No email required - this is not a SAML confirmation. |
333 custom_message, | 343 custom_message, |
334 // Callback is ignored. | 344 // Callback is ignored. |
335 BrowserWindow::StartSyncCallback()); | 345 BrowserWindow::StartSyncCallback()); |
336 } | 346 } |
337 | 347 |
338 void OneClickSigninSyncStarter::EnsureBrowser() { | 348 void OneClickSigninSyncStarter::EnsureBrowser() { |
339 if (!browser_) { | 349 if (!browser_) { |
340 // The user just created a new profile so we need to figure out what | 350 // The user just created a new profile or has closed the browser that |
341 // browser to use to display settings. Grab the most recently active | 351 // we used previously. Grab the most recently active browser or else |
342 // browser or else create a new one. | 352 // create a new one. |
343 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); | 353 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); |
344 if (!browser_) { | 354 if (!browser_) { |
345 browser_ = new Browser(Browser::CreateParams(profile_, | 355 browser_ = new Browser(Browser::CreateParams(profile_, |
346 desktop_type_)); | 356 desktop_type_)); |
357 chrome::AddBlankTabAt(browser_, -1, true); | |
347 } | 358 } |
348 browser_->window()->Show(); | 359 browser_->window()->Show(); |
349 } | 360 } |
350 } | 361 } |
351 | 362 |
352 void OneClickSigninSyncStarter::ConfigureSync() { | 363 void OneClickSigninSyncStarter::ConfigureSync() { |
353 // Give the user a chance to configure things. We don't clear the | 364 // Give the user a chance to configure things. We don't clear the |
354 // ProfileSyncService::setup_in_progress flag because we don't want sync | 365 // ProfileSyncService::setup_in_progress flag because we don't want sync |
355 // to start up until after the configure UI is displayed (the configure UI | 366 // to start up until after the configure UI is displayed (the configure UI |
356 // will clear the flag when the user is done setting up sync). | 367 // will clear the flag when the user is done setting up sync). |
(...skipping 26 matching lines...) Expand all Loading... | |
383 | 394 |
384 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { | 395 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { |
385 std::string url = std::string(chrome::kChromeUISettingsURL) + | 396 std::string url = std::string(chrome::kChromeUISettingsURL) + |
386 chrome::kSyncSetupSubPage; | 397 chrome::kSyncSetupSubPage; |
387 chrome::NavigateParams params( | 398 chrome::NavigateParams params( |
388 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 399 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
389 params.disposition = CURRENT_TAB; | 400 params.disposition = CURRENT_TAB; |
390 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 401 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
391 chrome::Navigate(¶ms); | 402 chrome::Navigate(¶ms); |
392 } | 403 } |
OLD | NEW |