| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/profile_helper.h" | 5 #include "chrome/browser/ui/webui/profile_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/lifetime/keep_alive_types.h" | 11 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 11 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 12 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profile_metrics.h" | 14 #include "chrome/browser/profiles/profile_metrics.h" |
| 14 #include "chrome/browser/profiles/profile_window.h" | 15 #include "chrome/browser/profiles/profile_window.h" |
| 15 #include "chrome/browser/profiles/profiles_state.h" | 16 #include "chrome/browser/profiles/profiles_state.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/user_manager.h" | 18 #include "chrome/browser/ui/user_manager.h" |
| 18 #include "chrome/browser/ui/webui/signin/signin_utils.h" | 19 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
| 21 #include "extensions/browser/app_window/app_window.h" | 22 #include "extensions/browser/app_window/app_window.h" |
| 22 #include "extensions/browser/app_window/app_window_registry.h" | 23 #include "extensions/browser/app_window/app_window_registry.h" |
| 23 | 24 |
| 24 namespace webui { | 25 namespace webui { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 void ShowUserManager(const ProfileManager::CreateCallback& callback) { |
| 29 if (!UserManager::IsShowing()) { |
| 30 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, |
| 31 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 32 } |
| 33 |
| 34 g_browser_process->profile_manager()->CreateProfileAsync( |
| 35 ProfileManager::GetSystemProfilePath(), callback, base::string16(), |
| 36 std::string(), std::string()); |
| 37 } |
| 38 |
| 39 std::string GetProfileUserName(Profile* profile) { |
| 40 ProfileAttributesEntry* entry; |
| 41 if (!g_browser_process->profile_manager() |
| 42 ->GetProfileAttributesStorage() |
| 43 .GetProfileAttributesWithPath(profile->GetPath(), &entry)) |
| 44 return std::string(); |
| 45 return base::UTF16ToUTF8(entry->GetUserName()); |
| 46 } |
| 47 |
| 27 void ShowSigninDialog(base::FilePath signin_profile_path, | 48 void ShowSigninDialog(base::FilePath signin_profile_path, |
| 28 Profile* system_profile, | 49 Profile* system_profile, |
| 29 Profile::CreateStatus status) { | 50 Profile::CreateStatus status) { |
| 30 UserManagerProfileDialog::ShowSigninDialog(system_profile, | 51 UserManagerProfileDialog::ShowSigninDialog(system_profile, |
| 31 signin_profile_path); | 52 signin_profile_path); |
| 32 } | 53 } |
| 33 | 54 |
| 55 void ShowReauthDialog(const std::string& user_name, |
| 56 Profile* system_profile, |
| 57 Profile::CreateStatus status) { |
| 58 UserManagerProfileDialog::ShowReauthDialog( |
| 59 system_profile, user_name, signin_metrics::Reason::REASON_UNLOCK); |
| 60 } |
| 61 |
| 34 void DeleteProfileCallback(std::unique_ptr<ScopedKeepAlive> keep_alive, | 62 void DeleteProfileCallback(std::unique_ptr<ScopedKeepAlive> keep_alive, |
| 35 Profile* profile, | 63 Profile* profile, |
| 36 Profile::CreateStatus status) { | 64 Profile::CreateStatus status) { |
| 37 if (status != Profile::CREATE_STATUS_INITIALIZED) | 65 if (status != Profile::CREATE_STATUS_INITIALIZED) |
| 38 return; | 66 return; |
| 39 | 67 |
| 40 OpenNewWindowForProfile(profile); | 68 OpenNewWindowForProfile(profile); |
| 41 } | 69 } |
| 42 | 70 |
| 43 } // namespace | 71 } // namespace |
| 44 | 72 |
| 45 void OpenNewWindowForProfile(Profile* profile) { | 73 void OpenNewWindowForProfile(Profile* profile) { |
| 46 if (signin::IsForceSigninEnabled() || | 74 if (signin::IsForceSigninEnabled()) { |
| 47 profiles::IsProfileLocked(profile->GetPath())) { | 75 ShowUserManager(base::Bind(&ShowSigninDialog, profile->GetPath())); |
| 48 if (!UserManager::IsShowing()) { | 76 } else if (profiles::IsProfileLocked(profile->GetPath())) { |
| 49 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, | 77 ShowUserManager(base::Bind(&ShowReauthDialog, GetProfileUserName(profile))); |
| 50 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | |
| 51 } | |
| 52 | |
| 53 g_browser_process->profile_manager()->CreateProfileAsync( | |
| 54 ProfileManager::GetSystemProfilePath(), | |
| 55 base::Bind(&ShowSigninDialog, profile->GetPath()), base::string16(), | |
| 56 std::string(), std::string()); | |
| 57 | |
| 58 } else { | 78 } else { |
| 59 profiles::FindOrCreateNewWindowForProfile( | 79 profiles::FindOrCreateNewWindowForProfile( |
| 60 profile, chrome::startup::IS_PROCESS_STARTUP, | 80 profile, chrome::startup::IS_PROCESS_STARTUP, |
| 61 chrome::startup::IS_FIRST_RUN, false); | 81 chrome::startup::IS_FIRST_RUN, false); |
| 62 } | 82 } |
| 63 } | 83 } |
| 64 | 84 |
| 65 void DeleteProfileAtPath(base::FilePath file_path, | 85 void DeleteProfileAtPath(base::FilePath file_path, |
| 66 content::WebUI* web_ui, | 86 content::WebUI* web_ui, |
| 67 ProfileMetrics::ProfileDelete deletion_source) { | 87 ProfileMetrics::ProfileDelete deletion_source) { |
| 68 DCHECK(web_ui); | 88 DCHECK(web_ui); |
| 69 | 89 |
| 70 if (!profiles::IsMultipleProfilesEnabled()) | 90 if (!profiles::IsMultipleProfilesEnabled()) |
| 71 return; | 91 return; |
| 72 g_browser_process->profile_manager()->MaybeScheduleProfileForDeletion( | 92 g_browser_process->profile_manager()->MaybeScheduleProfileForDeletion( |
| 73 file_path, base::Bind(&DeleteProfileCallback, | 93 file_path, base::Bind(&DeleteProfileCallback, |
| 74 base::Passed(base::MakeUnique<ScopedKeepAlive>( | 94 base::Passed(base::MakeUnique<ScopedKeepAlive>( |
| 75 KeepAliveOrigin::PROFILE_HELPER, | 95 KeepAliveOrigin::PROFILE_HELPER, |
| 76 KeepAliveRestartOption::DISABLED))), | 96 KeepAliveRestartOption::DISABLED))), |
| 77 deletion_source); | 97 deletion_source); |
| 78 } | 98 } |
| 79 | 99 |
| 80 } // namespace webui | 100 } // namespace webui |
| OLD | NEW |