| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 profile_manager->user_data_dir()); | 479 profile_manager->user_data_dir()); |
| 480 // |profile| could be null if the user doesn't have a profile yet and the path | 480 // |profile| could be null if the user doesn't have a profile yet and the path |
| 481 // is on a read-only volume (preventing Chrome from making a new one). | 481 // is on a read-only volume (preventing Chrome from making a new one). |
| 482 // However, most callers of this function immediately dereference the result | 482 // However, most callers of this function immediately dereference the result |
| 483 // which would lead to crashes in a variety of call sites. Assert here to | 483 // which would lead to crashes in a variety of call sites. Assert here to |
| 484 // figure out how common this is. http://crbug.com/383019 | 484 // figure out how common this is. http://crbug.com/383019 |
| 485 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); | 485 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); |
| 486 return profile; | 486 return profile; |
| 487 } | 487 } |
| 488 | 488 |
| 489 // static |
| 490 Profile* ProfileManager::CreateInitialProfile() { |
| 491 ProfileManager* const profile_manager = g_browser_process->profile_manager(); |
| 492 return profile_manager->GetProfile(profile_manager->user_data_dir().Append( |
| 493 profile_manager->GetInitialProfileDir())); |
| 494 } |
| 495 |
| 489 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { | 496 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { |
| 490 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); | 497 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); |
| 491 | 498 |
| 492 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 499 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
| 493 // return it. | 500 // return it. |
| 494 Profile* profile = GetProfileByPath(profile_dir); | 501 Profile* profile = GetProfileByPath(profile_dir); |
| 495 if (profile) | 502 if (profile) |
| 496 return profile; | 503 return profile; |
| 497 return CreateAndInitializeProfile(profile_dir); | 504 return CreateAndInitializeProfile(profile_dir); |
| 498 } | 505 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // since it may refer to profile that has been in use in previous session. | 632 // since it may refer to profile that has been in use in previous session. |
| 626 // That profile dir may not be mounted in this session so instead return | 633 // That profile dir may not be mounted in this session so instead return |
| 627 // active profile from current session. | 634 // active profile from current session. |
| 628 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); | 635 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); |
| 629 | 636 |
| 630 base::FilePath profile_path(user_data_dir); | 637 base::FilePath profile_path(user_data_dir); |
| 631 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir)); | 638 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir)); |
| 632 // If we get here, it means the user has logged in but the profile has not | 639 // If we get here, it means the user has logged in but the profile has not |
| 633 // finished initializing, so treat the user as not having logged in. | 640 // finished initializing, so treat the user as not having logged in. |
| 634 if (!profile) { | 641 if (!profile) { |
| 635 DLOG(WARNING) << "Calling GetLastUsedProfile() before profile " | 642 LOG(WARNING) << "Calling GetLastUsedProfile() before profile " |
| 636 << "initialization is completed. Returning login profile."; | 643 << "initialization is completed. Returning login profile."; |
| 637 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); | 644 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); |
| 638 } | 645 } |
| 639 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : | 646 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : |
| 640 profile; | 647 profile; |
| 641 } | 648 } |
| 642 #else | 649 #else |
| 643 | 650 |
| 644 return GetProfile(GetLastUsedProfileDir(user_data_dir)); | 651 return GetProfile(GetLastUsedProfileDir(user_data_dir)); |
| 645 #endif | 652 #endif |
| 646 } | 653 } |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 // many of the browser and ui tests fail. We do return the OTR profile | 1327 // many of the browser and ui tests fail. We do return the OTR profile |
| 1321 // if the login-profile switch is passed so that we can test this. | 1328 // if the login-profile switch is passed so that we can test this. |
| 1322 if (ShouldGoOffTheRecord(profile)) | 1329 if (ShouldGoOffTheRecord(profile)) |
| 1323 return profile->GetOffTheRecordProfile(); | 1330 return profile->GetOffTheRecordProfile(); |
| 1324 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); | 1331 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); |
| 1325 return profile; | 1332 return profile; |
| 1326 } | 1333 } |
| 1327 | 1334 |
| 1328 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 1335 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
| 1329 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); | 1336 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); |
| 1330 // Fallback to default off-the-record profile, if user profile has not fully | 1337 // Fallback to default off-the-record profile, if user profile has not started |
| 1331 // loaded yet. | 1338 // loading or has not fully loaded yet. |
| 1332 if (profile_info && !profile_info->created) | 1339 if (!profile_info || !profile_info->created) |
| 1333 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); | 1340 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
| 1334 | 1341 |
| 1335 Profile* profile = GetProfile(default_profile_dir); | 1342 Profile* profile = GetProfile(default_profile_dir); |
| 1336 // Some unit tests didn't initialize the UserManager. | 1343 // Some unit tests didn't initialize the UserManager. |
| 1337 if (user_manager::UserManager::IsInitialized() && | 1344 if (user_manager::UserManager::IsInitialized() && |
| 1338 user_manager::UserManager::Get()->IsLoggedInAsGuest()) | 1345 user_manager::UserManager::Get()->IsLoggedInAsGuest()) |
| 1339 return profile->GetOffTheRecordProfile(); | 1346 return profile->GetOffTheRecordProfile(); |
| 1340 return profile; | 1347 return profile; |
| 1341 #else | 1348 #else |
| 1342 base::FilePath default_profile_dir(user_data_dir); | 1349 base::FilePath default_profile_dir(user_data_dir); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 | 1787 |
| 1781 const base::FilePath new_active_profile_dir = | 1788 const base::FilePath new_active_profile_dir = |
| 1782 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); | 1789 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); |
| 1783 FinishDeletingProfile(profile_dir, new_active_profile_dir); | 1790 FinishDeletingProfile(profile_dir, new_active_profile_dir); |
| 1784 } | 1791 } |
| 1785 #endif // !defined(OS_ANDROID) | 1792 #endif // !defined(OS_ANDROID) |
| 1786 | 1793 |
| 1787 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1794 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1788 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1795 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1789 } | 1796 } |
| OLD | NEW |