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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chromeos/profiles/profile_helper.h" 5 #include "chrome/browser/chromeos/profiles/profile_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" 10 #include "chrome/browser/browsing_data/browsing_data_helper.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool ProfileHelper::IsOwnerProfile(Profile* profile) { 170 bool ProfileHelper::IsOwnerProfile(Profile* profile) {
171 if (!profile) 171 if (!profile)
172 return false; 172 return false;
173 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 173 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
174 if (!user) 174 if (!user)
175 return false; 175 return false;
176 176
177 return user->email() == chromeos::UserManager::Get()->GetOwnerEmail(); 177 return user->email() == chromeos::UserManager::Get()->GetOwnerEmail();
178 } 178 }
179 179
180 //static 180 // static
181 bool ProfileHelper::IsPrimaryProfile(Profile* profile) { 181 bool ProfileHelper::IsPrimaryProfile(Profile* profile) {
182 if (!profile) 182 if (!profile)
183 return false; 183 return false;
184 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 184 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
185 if (!user) 185 if (!user)
186 return false; 186 return false;
187 return user == chromeos::UserManager::Get()->GetPrimaryUser(); 187 return user == chromeos::UserManager::Get()->GetPrimaryUser();
188 } 188 }
189 189
190 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 190 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 Profile* ProfileHelper::GetProfileByUser(const user_manager::User* user) { 237 Profile* ProfileHelper::GetProfileByUser(const user_manager::User* user) {
238 // This map is non-empty only in tests. 238 // This map is non-empty only in tests.
239 if (!user_to_profile_for_testing_.empty()) { 239 if (!user_to_profile_for_testing_.empty()) {
240 std::map<const user_manager::User*, Profile*>::const_iterator it = 240 std::map<const user_manager::User*, Profile*>::const_iterator it =
241 user_to_profile_for_testing_.find(user); 241 user_to_profile_for_testing_.find(user);
242 return it == user_to_profile_for_testing_.end() ? NULL : it->second; 242 return it == user_to_profile_for_testing_.end() ? NULL : it->second;
243 } 243 }
244 244
245 if (!user->is_profile_created())
246 return NULL;
247 Profile* profile =
248 ProfileHelper::GetProfileByUserIdHash(user->username_hash());
249
250 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
251 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
252 if (UserManager::Get()->IsLoggedInAsGuest())
253 profile = profile->GetOffTheRecordProfile();
254
255 return profile;
256 }
257
258 Profile* ProfileHelper::GetProfileByUserUnsafe(const user_manager::User* user) {
259 // This map is non-empty only in tests.
260 if (!user_to_profile_for_testing_.empty()) {
261 std::map<const user_manager::User*, Profile*>::const_iterator it =
262 user_to_profile_for_testing_.find(user);
263 return it == user_to_profile_for_testing_.end() ? NULL : it->second;
264 }
265
245 Profile* profile = NULL; 266 Profile* profile = NULL;
246 if (user->is_profile_created()) 267 if (user->is_profile_created()) {
247 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); 268 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
248 else 269 } else {
270 LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when "
271 "|user|'s profile is not created. It probably means that "
272 "something is wrong with a calling code. Please report in "
273 "http://crbug.com/361528 if you see this message.";
249 profile = ProfileManager::GetActiveUserProfile(); 274 profile = ProfileManager::GetActiveUserProfile();
275 }
250 276
251 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance 277 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
252 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. 278 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
253 if (profile && UserManager::Get()->IsLoggedInAsGuest()) 279 if (profile && UserManager::Get()->IsLoggedInAsGuest())
254 profile = profile->GetOffTheRecordProfile(); 280 profile = profile->GetOffTheRecordProfile();
255 return profile; 281 return profile;
256 } 282 }
257 283
258 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) { 284 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) {
259 // This map is non-empty only in tests. 285 // This map is non-empty only in tests.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ProfileHelper::SetProfileToUserForTestingEnabled(true); 391 ProfileHelper::SetProfileToUserForTestingEnabled(true);
366 } 392 }
367 393
368 void ProfileHelper::SetUserToProfileMappingForTesting( 394 void ProfileHelper::SetUserToProfileMappingForTesting(
369 const user_manager::User* user, 395 const user_manager::User* user,
370 Profile* profile) { 396 Profile* profile) {
371 user_to_profile_for_testing_[user] = profile; 397 user_to_profile_for_testing_[user] = profile;
372 } 398 }
373 399
374 } // namespace chromeos 400 } // namespace chromeos
OLDNEW
« 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