Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4713)

Unified Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 445353004: GetProfileByUser deprecated and renamed to GetProfileByUserUnsafe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/profiles/profile_helper.cc
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc
index 155084ef1dd5f58c9bb98c48c47e59a3adc97c51..f96063042191ae88a86c597cda73bdcd28e2cbdc 100644
--- a/chrome/browser/chromeos/profiles/profile_helper.cc
+++ b/chrome/browser/chromeos/profiles/profile_helper.cc
@@ -177,7 +177,7 @@ bool ProfileHelper::IsOwnerProfile(Profile* profile) {
return user->email() == chromeos::UserManager::Get()->GetOwnerEmail();
}
-//static
+// static
bool ProfileHelper::IsPrimaryProfile(Profile* profile) {
if (!profile)
return false;
@@ -242,11 +242,37 @@ Profile* ProfileHelper::GetProfileByUser(const user_manager::User* user) {
return it == user_to_profile_for_testing_.end() ? NULL : it->second;
}
+ if (!user->is_profile_created())
+ return NULL;
+ Profile* profile =
+ ProfileHelper::GetProfileByUserIdHash(user->username_hash());
+
+ // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
+ // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
+ if (UserManager::Get()->IsLoggedInAsGuest())
+ profile = profile->GetOffTheRecordProfile();
+
+ return profile;
+}
+
+Profile* ProfileHelper::GetProfileByUserUnsafe(const user_manager::User* user) {
+ // This map is non-empty only in tests.
+ if (!user_to_profile_for_testing_.empty()) {
+ std::map<const user_manager::User*, Profile*>::const_iterator it =
+ user_to_profile_for_testing_.find(user);
+ return it == user_to_profile_for_testing_.end() ? NULL : it->second;
+ }
+
Profile* profile = NULL;
- if (user->is_profile_created())
+ if (user->is_profile_created()) {
profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
- else
+ } else {
+ LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when "
+ "|user|'s profile is not created. It probably means that "
+ "something is wrong with a calling code. Please report in "
+ "http://crbug.com/361528 if you see this message.";
profile = ProfileManager::GetActiveUserProfile();
+ }
// GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
// of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/browser/extensions/extension_assets_manager_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698