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/profiles/profile_manager.h" | 5 #include "chrome/browser/profiles/profile_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 #include "extensions/browser/extension_system.h" | 75 #include "extensions/browser/extension_system.h" |
76 #endif // !defined (OS_IOS) | 76 #endif // !defined (OS_IOS) |
77 | 77 |
78 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
79 #include "base/win/metro.h" | 79 #include "base/win/metro.h" |
80 #include "chrome/installer/util/browser_distribution.h" | 80 #include "chrome/installer/util/browser_distribution.h" |
81 #endif | 81 #endif |
82 | 82 |
83 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
84 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 84 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
85 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
86 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 85 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
87 #include "chrome/browser/profiles/profiles_state.h" | 86 #include "chrome/browser/profiles/profiles_state.h" |
88 #include "chromeos/chromeos_switches.h" | 87 #include "chromeos/chromeos_switches.h" |
89 #include "chromeos/dbus/cryptohome_client.h" | 88 #include "chromeos/dbus/cryptohome_client.h" |
90 #include "chromeos/dbus/dbus_thread_manager.h" | 89 #include "chromeos/dbus/dbus_thread_manager.h" |
91 #include "components/user_manager/user.h" | 90 #include "components/user_manager/user.h" |
| 91 #include "components/user_manager/user_manager.h" |
92 #endif | 92 #endif |
93 | 93 |
94 using base::UserMetricsAction; | 94 using base::UserMetricsAction; |
95 using content::BrowserThread; | 95 using content::BrowserThread; |
96 | 96 |
97 namespace { | 97 namespace { |
98 | 98 |
99 // Profiles that should be deleted on shutdown. | 99 // Profiles that should be deleted on shutdown. |
100 std::vector<base::FilePath>& ProfilesToDelete() { | 100 std::vector<base::FilePath>& ProfilesToDelete() { |
101 CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ()); | 101 CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { | 306 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() { |
307 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 307 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
308 return profile_manager->GetLastOpenedProfiles( | 308 return profile_manager->GetLastOpenedProfiles( |
309 profile_manager->user_data_dir_); | 309 profile_manager->user_data_dir_); |
310 } | 310 } |
311 | 311 |
312 // static | 312 // static |
313 Profile* ProfileManager::GetPrimaryUserProfile() { | 313 Profile* ProfileManager::GetPrimaryUserProfile() { |
314 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 314 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
315 #if defined(OS_CHROMEOS) | 315 #if defined(OS_CHROMEOS) |
316 if (!profile_manager->IsLoggedIn() || !chromeos::UserManager::IsInitialized()) | 316 if (!profile_manager->IsLoggedIn() || |
| 317 !user_manager::UserManager::IsInitialized()) |
317 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( | 318 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
318 profile_manager->user_data_dir()); | 319 profile_manager->user_data_dir()); |
319 chromeos::UserManager* manager = chromeos::UserManager::Get(); | 320 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
320 // Note: The ProfileHelper will take care of guest profiles. | 321 // Note: The ProfileHelper will take care of guest profiles. |
321 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe( | 322 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe( |
322 manager->GetPrimaryUser()); | 323 manager->GetPrimaryUser()); |
323 #else | 324 #else |
324 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( | 325 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
325 profile_manager->user_data_dir()); | 326 profile_manager->user_data_dir()); |
326 #endif | 327 #endif |
327 } | 328 } |
328 | 329 |
329 // static | 330 // static |
330 Profile* ProfileManager::GetActiveUserProfile() { | 331 Profile* ProfileManager::GetActiveUserProfile() { |
331 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 332 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
332 #if defined(OS_CHROMEOS) | 333 #if defined(OS_CHROMEOS) |
333 if (!profile_manager->IsLoggedIn() || | 334 if (!profile_manager->IsLoggedIn() || |
334 !chromeos::UserManager::IsInitialized()) { | 335 !user_manager::UserManager::IsInitialized()) { |
335 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( | 336 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( |
336 profile_manager->user_data_dir()); | 337 profile_manager->user_data_dir()); |
337 } | 338 } |
338 | 339 |
339 chromeos::UserManager* manager = chromeos::UserManager::Get(); | 340 user_manager::UserManager* manager = user_manager::UserManager::Get(); |
340 const user_manager::User* user = manager->GetActiveUser(); | 341 const user_manager::User* user = manager->GetActiveUser(); |
341 // To avoid an endless loop (crbug.com/334098) we have to additionally check | 342 // To avoid an endless loop (crbug.com/334098) we have to additionally check |
342 // if the profile of the user was already created. If the profile was not yet | 343 // if the profile of the user was already created. If the profile was not yet |
343 // created we load the profile using the profile directly. | 344 // created we load the profile using the profile directly. |
344 // TODO: This should be cleaned up with the new profile manager. | 345 // TODO: This should be cleaned up with the new profile manager. |
345 if (user && user->is_profile_created()) | 346 if (user && user->is_profile_created()) |
346 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 347 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
347 | 348 |
348 #endif | 349 #endif |
349 Profile* profile = | 350 Profile* profile = |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 base::FilePath default_profile_dir(user_data_dir); | 1047 base::FilePath default_profile_dir(user_data_dir); |
1047 if (!logged_in_) { | 1048 if (!logged_in_) { |
1048 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); | 1049 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
1049 Profile* profile = GetProfile(default_profile_dir); | 1050 Profile* profile = GetProfile(default_profile_dir); |
1050 // For cros, return the OTR profile so we never accidentally keep | 1051 // For cros, return the OTR profile so we never accidentally keep |
1051 // user data in an unencrypted profile. But doing this makes | 1052 // user data in an unencrypted profile. But doing this makes |
1052 // many of the browser and ui tests fail. We do return the OTR profile | 1053 // many of the browser and ui tests fail. We do return the OTR profile |
1053 // if the login-profile switch is passed so that we can test this. | 1054 // if the login-profile switch is passed so that we can test this. |
1054 if (ShouldGoOffTheRecord(profile)) | 1055 if (ShouldGoOffTheRecord(profile)) |
1055 return profile->GetOffTheRecordProfile(); | 1056 return profile->GetOffTheRecordProfile(); |
1056 DCHECK(!chromeos::UserManager::Get()->IsLoggedInAsGuest()); | 1057 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); |
1057 return profile; | 1058 return profile; |
1058 } | 1059 } |
1059 | 1060 |
1060 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 1061 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
1061 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); | 1062 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); |
1062 // Fallback to default off-the-record profile, if user profile has not fully | 1063 // Fallback to default off-the-record profile, if user profile has not fully |
1063 // loaded yet. | 1064 // loaded yet. |
1064 if (profile_info && !profile_info->created) | 1065 if (profile_info && !profile_info->created) |
1065 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); | 1066 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
1066 | 1067 |
1067 Profile* profile = GetProfile(default_profile_dir); | 1068 Profile* profile = GetProfile(default_profile_dir); |
1068 // Some unit tests didn't initialize the UserManager. | 1069 // Some unit tests didn't initialize the UserManager. |
1069 if (chromeos::UserManager::IsInitialized() && | 1070 if (user_manager::UserManager::IsInitialized() && |
1070 chromeos::UserManager::Get()->IsLoggedInAsGuest()) | 1071 user_manager::UserManager::Get()->IsLoggedInAsGuest()) |
1071 return profile->GetOffTheRecordProfile(); | 1072 return profile->GetOffTheRecordProfile(); |
1072 return profile; | 1073 return profile; |
1073 #else | 1074 #else |
1074 base::FilePath default_profile_dir(user_data_dir); | 1075 base::FilePath default_profile_dir(user_data_dir); |
1075 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 1076 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
1076 return GetProfile(default_profile_dir); | 1077 return GetProfile(default_profile_dir); |
1077 #endif | 1078 #endif |
1078 } | 1079 } |
1079 | 1080 |
1080 bool ProfileManager::AddProfile(Profile* profile) { | 1081 bool ProfileManager::AddProfile(Profile* profile) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); | 1323 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); |
1323 FinishDeletingProfile(profile_to_delete_path); | 1324 FinishDeletingProfile(profile_to_delete_path); |
1324 } | 1325 } |
1325 } | 1326 } |
1326 } | 1327 } |
1327 #endif | 1328 #endif |
1328 | 1329 |
1329 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1330 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1330 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1331 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1331 } | 1332 } |
OLD | NEW |