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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 return profile; | 372 return profile; |
373 } | 373 } |
374 | 374 |
375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { | 375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { |
376 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); | 376 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); |
377 SCOPED_UMA_HISTOGRAM_TIMER("Profile.GetProfile"); | 377 SCOPED_UMA_HISTOGRAM_TIMER("Profile.GetProfile"); |
378 | 378 |
379 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 379 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
380 // return it. | 380 // return it. |
381 Profile* profile = GetProfileByPath(profile_dir); | 381 Profile* profile = GetProfileByPath(profile_dir); |
382 if (NULL != profile) | 382 if (profile) |
383 return profile; | 383 return profile; |
384 | 384 |
385 // If the profile has not been found, check that we have not started loading | |
386 // it (which would mean that the profile is not fully initialized yet). | |
387 DCHECK(!GetProfileByPathInternal(profile_dir)); | |
noms (inactive)
2015/02/18 21:26:21
Hmm, so in non-debug world, if the profile has not
Bernhard Bauer
2015/02/19 10:22:37
Made it a CHECK.
| |
388 | |
385 profile = CreateProfileHelper(profile_dir); | 389 profile = CreateProfileHelper(profile_dir); |
386 DCHECK(profile); | 390 DCHECK(profile); |
387 if (profile) { | 391 if (profile) { |
388 bool result = AddProfile(profile); | 392 bool result = AddProfile(profile); |
389 DCHECK(result); | 393 DCHECK(result); |
390 } | 394 } |
391 return profile; | 395 return profile; |
392 } | 396 } |
393 | 397 |
394 size_t ProfileManager::GetNumberOfProfiles() { | 398 size_t ProfileManager::GetNumberOfProfiles() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const { | 557 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const { |
554 std::vector<Profile*> profiles; | 558 std::vector<Profile*> profiles; |
555 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin(); | 559 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin(); |
556 iter != profiles_info_.end(); ++iter) { | 560 iter != profiles_info_.end(); ++iter) { |
557 if (iter->second->created) | 561 if (iter->second->created) |
558 profiles.push_back(iter->second->profile.get()); | 562 profiles.push_back(iter->second->profile.get()); |
559 } | 563 } |
560 return profiles; | 564 return profiles; |
561 } | 565 } |
562 | 566 |
567 Profile* ProfileManager::GetProfileByPathInternal( | |
568 const base::FilePath& path) const { | |
569 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPathInternal"); | |
570 ProfileInfo* profile_info = GetProfileInfoByPath(path); | |
571 return profile_info ? profile_info->profile.get() : nullptr; | |
572 } | |
573 | |
563 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { | 574 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { |
564 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPath"); | 575 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPath"); |
565 ProfileInfo* profile_info = GetProfileInfoByPath(path); | 576 ProfileInfo* profile_info = GetProfileInfoByPath(path); |
566 return profile_info ? profile_info->profile.get() : NULL; | 577 return profile_info && profile_info->created ? profile_info->profile.get() |
578 : nullptr; | |
567 } | 579 } |
568 | 580 |
569 // static | 581 // static |
570 base::FilePath ProfileManager::CreateMultiProfileAsync( | 582 base::FilePath ProfileManager::CreateMultiProfileAsync( |
571 const base::string16& name, | 583 const base::string16& name, |
572 const base::string16& icon_url, | 584 const base::string16& icon_url, |
573 const CreateCallback& callback, | 585 const CreateCallback& callback, |
574 const std::string& supervised_user_id) { | 586 const std::string& supervised_user_id) { |
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
576 | 588 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 // If we don't have a mounted profile directory we're in trouble. | 870 // If we don't have a mounted profile directory we're in trouble. |
859 // TODO(davemoore) Once we have better api this check should ensure that | 871 // TODO(davemoore) Once we have better api this check should ensure that |
860 // our profile directory is the one that's mounted, and that it's mounted | 872 // our profile directory is the one that's mounted, and that it's mounted |
861 // as the current user. | 873 // as the current user. |
862 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( | 874 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( |
863 base::Bind(&CheckCryptohomeIsMounted)); | 875 base::Bind(&CheckCryptohomeIsMounted)); |
864 | 876 |
865 // Confirm that we hadn't loaded the new profile previously. | 877 // Confirm that we hadn't loaded the new profile previously. |
866 base::FilePath default_profile_dir = user_data_dir_.Append( | 878 base::FilePath default_profile_dir = user_data_dir_.Append( |
867 GetInitialProfileDir()); | 879 GetInitialProfileDir()); |
868 CHECK(!GetProfileByPath(default_profile_dir)) | 880 CHECK(!GetProfileByPathInternal(default_profile_dir)) |
869 << "The default profile was loaded before we mounted the cryptohome."; | 881 << "The default profile was loaded before we mounted the cryptohome."; |
870 } | 882 } |
871 return; | 883 return; |
872 } | 884 } |
873 #endif | 885 #endif |
874 bool save_active_profiles = false; | 886 bool save_active_profiles = false; |
875 switch (type) { | 887 switch (type) { |
876 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { | 888 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { |
877 // Ignore any browsers closing from now on. | 889 // Ignore any browsers closing from now on. |
878 closing_all_browsers_ = true; | 890 closing_all_browsers_ = true; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 return GetProfile(default_profile_dir); | 1134 return GetProfile(default_profile_dir); |
1123 #endif | 1135 #endif |
1124 } | 1136 } |
1125 | 1137 |
1126 bool ProfileManager::AddProfile(Profile* profile) { | 1138 bool ProfileManager::AddProfile(Profile* profile) { |
1127 TRACE_EVENT0("browser", "ProfileManager::AddProfile"); | 1139 TRACE_EVENT0("browser", "ProfileManager::AddProfile"); |
1128 DCHECK(profile); | 1140 DCHECK(profile); |
1129 | 1141 |
1130 // Make sure that we're not loading a profile with the same ID as a profile | 1142 // Make sure that we're not loading a profile with the same ID as a profile |
1131 // that's already loaded. | 1143 // that's already loaded. |
1132 if (GetProfileByPath(profile->GetPath())) { | 1144 if (GetProfileByPathInternal(profile->GetPath())) { |
1133 NOTREACHED() << "Attempted to add profile with the same path (" << | 1145 NOTREACHED() << "Attempted to add profile with the same path (" << |
1134 profile->GetPath().value() << | 1146 profile->GetPath().value() << |
1135 ") as an already-loaded profile."; | 1147 ") as an already-loaded profile."; |
1136 return false; | 1148 return false; |
1137 } | 1149 } |
1138 | 1150 |
1139 RegisterProfile(profile, true); | 1151 RegisterProfile(profile, true); |
1140 InitProfileUserPrefs(profile); | 1152 InitProfileUserPrefs(profile); |
1141 DoFinalInit(profile, ShouldGoOffTheRecord(profile)); | 1153 DoFinalInit(profile, ShouldGoOffTheRecord(profile)); |
1142 return true; | 1154 return true; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); | 1390 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); |
1379 FinishDeletingProfile(profile_to_delete_path); | 1391 FinishDeletingProfile(profile_to_delete_path); |
1380 } | 1392 } |
1381 } | 1393 } |
1382 } | 1394 } |
1383 #endif | 1395 #endif |
1384 | 1396 |
1385 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1397 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1386 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1398 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1387 } | 1399 } |
OLD | NEW |