OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.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 "base/value_conversions.h" | 10 #include "base/value_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" | 13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" |
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
17 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
20 #include "chrome/browser/profiles/profile_window.h" | 21 #include "chrome/browser/profiles/profile_window.h" |
21 #include "chrome/browser/profiles/profiles_state.h" | 22 #include "chrome/browser/profiles/profiles_state.h" |
22 #include "chrome/browser/signin/local_auth.h" | 23 #include "chrome/browser/signin/local_auth.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 24 #include "chrome/browser/ui/browser_dialogs.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 ProfileInfoCache& info_cache = | 138 ProfileInfoCache& info_cache = |
138 g_browser_process->profile_manager()->GetProfileInfoCache(); | 139 g_browser_process->profile_manager()->GetProfileInfoCache(); |
139 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 140 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
140 info_cache, base::UTF8ToUTF16(email), base::string16()); | 141 info_cache, base::UTF8ToUTF16(email), base::string16()); |
141 Profile* profile = g_browser_process->profile_manager() | 142 Profile* profile = g_browser_process->profile_manager() |
142 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); | 143 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); |
143 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 144 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
144 profile); | 145 profile); |
145 } | 146 } |
146 | 147 |
148 bool IsGuestModeEnabled() { | |
149 PrefService* service = g_browser_process->local_state(); | |
150 DCHECK(service); | |
151 if (IncognitoModePrefs::GetAvailability(service) == | |
152 IncognitoModePrefs::DISABLED) | |
153 return false; | |
Nikita (slow)
2014/08/14 15:53:07
nit: Add {}
| |
154 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); | |
155 } | |
156 | |
147 } // namespace | 157 } // namespace |
148 | 158 |
149 // ProfileUpdateObserver ------------------------------------------------------ | 159 // ProfileUpdateObserver ------------------------------------------------------ |
150 | 160 |
151 class UserManagerScreenHandler::ProfileUpdateObserver | 161 class UserManagerScreenHandler::ProfileUpdateObserver |
152 : public ProfileInfoCacheObserver { | 162 : public ProfileInfoCacheObserver { |
153 public: | 163 public: |
154 ProfileUpdateObserver( | 164 ProfileUpdateObserver( |
155 ProfileManager* profile_manager, UserManagerScreenHandler* handler) | 165 ProfileManager* profile_manager, UserManagerScreenHandler* handler) |
156 : profile_manager_(profile_manager), | 166 : profile_manager_(profile_manager), |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 287 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
278 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 288 info_cache, base::UTF8ToUTF16(user_email), base::string16()); |
279 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 289 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
280 | 290 |
281 authenticating_profile_index_ = profile_index; | 291 authenticating_profile_index_ = profile_index; |
282 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 292 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
283 } | 293 } |
284 | 294 |
285 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 295 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
286 SendUserList(); | 296 SendUserList(); |
287 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); | 297 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
298 base::FundamentalValue(IsGuestModeEnabled())); | |
288 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 299 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
289 web_ui()->GetWebContents()->GetNativeView()); | 300 web_ui()->GetWebContents()->GetNativeView()); |
290 | 301 |
291 ScreenlockBridge::Get()->SetLockHandler(this); | 302 ScreenlockBridge::Get()->SetLockHandler(this); |
292 } | 303 } |
293 | 304 |
294 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 305 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
295 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 306 profiles::CreateAndSwitchToNewProfile(desktop_type_, |
296 base::Bind(&OnSwitchToProfileComplete), | 307 base::Bind(&OnSwitchToProfileComplete), |
297 ProfileMetrics::ADD_NEW_USER_MANAGER); | 308 ProfileMetrics::ADD_NEW_USER_MANAGER); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 return; | 376 return; |
366 | 377 |
367 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 378 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
368 profile_path, | 379 profile_path, |
369 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 380 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
370 ProfileMetrics::LogProfileDeleteUser( | 381 ProfileMetrics::LogProfileDeleteUser( |
371 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 382 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
372 } | 383 } |
373 | 384 |
374 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 385 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
375 profiles::SwitchToGuestProfile(desktop_type_, | 386 if (IsGuestModeEnabled()) { |
376 base::Bind(&OnSwitchToProfileComplete)); | 387 profiles::SwitchToGuestProfile(desktop_type_, |
377 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 388 base::Bind(&OnSwitchToProfileComplete)); |
389 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | |
390 } else { | |
391 // The UI should have prevented the user from allowing the selection of | |
392 // guest mode. | |
393 NOTREACHED(); | |
394 } | |
378 } | 395 } |
379 | 396 |
380 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 397 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
381 base::string16 email_address; | 398 base::string16 email_address; |
382 base::string16 display_name; | 399 base::string16 display_name; |
383 | 400 |
384 if (!args->GetString(0, &email_address) || | 401 if (!args->GetString(0, &email_address) || |
385 !args->GetString(1, &display_name)) { | 402 !args->GetString(1, &display_name)) { |
386 NOTREACHED(); | 403 NOTREACHED(); |
387 return; | 404 return; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 638 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
622 | 639 |
623 // The row of user pods should display the active user first. | 640 // The row of user pods should display the active user first. |
624 if (is_active_user) | 641 if (is_active_user) |
625 users_list.Insert(0, profile_value); | 642 users_list.Insert(0, profile_value); |
626 else | 643 else |
627 users_list.Append(profile_value); | 644 users_list.Append(profile_value); |
628 } | 645 } |
629 | 646 |
630 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 647 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
631 users_list, base::FundamentalValue(true)); | 648 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
632 } | 649 } |
633 | 650 |
634 void UserManagerScreenHandler::ReportAuthenticationResult( | 651 void UserManagerScreenHandler::ReportAuthenticationResult( |
635 bool success, | 652 bool success, |
636 ProfileMetrics::ProfileAuth auth) { | 653 ProfileMetrics::ProfileAuth auth) { |
637 ProfileMetrics::LogProfileAuthResult(auth); | 654 ProfileMetrics::LogProfileAuthResult(auth); |
638 password_attempt_.clear(); | 655 password_attempt_.clear(); |
639 | 656 |
640 if (success) { | 657 if (success) { |
641 ProfileInfoCache& info_cache = | 658 ProfileInfoCache& info_cache = |
642 g_browser_process->profile_manager()->GetProfileInfoCache(); | 659 g_browser_process->profile_manager()->GetProfileInfoCache(); |
643 info_cache.SetProfileSigninRequiredAtIndex( | 660 info_cache.SetProfileSigninRequiredAtIndex( |
644 authenticating_profile_index_, false); | 661 authenticating_profile_index_, false); |
645 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 662 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
646 authenticating_profile_index_); | 663 authenticating_profile_index_); |
647 profiles::SwitchToProfile(path, desktop_type_, true, | 664 profiles::SwitchToProfile(path, desktop_type_, true, |
648 base::Bind(&OnSwitchToProfileComplete), | 665 base::Bind(&OnSwitchToProfileComplete), |
649 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 666 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
650 } else { | 667 } else { |
651 web_ui()->CallJavascriptFunction( | 668 web_ui()->CallJavascriptFunction( |
652 "cr.ui.Oobe.showSignInError", | 669 "cr.ui.Oobe.showSignInError", |
653 base::FundamentalValue(0), | 670 base::FundamentalValue(0), |
654 base::StringValue( | 671 base::StringValue( |
655 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 672 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
656 base::StringValue(""), | 673 base::StringValue(""), |
657 base::FundamentalValue(0)); | 674 base::FundamentalValue(0)); |
658 } | 675 } |
659 } | 676 } |
OLD | NEW |