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

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: Rebased. 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Profile* profile = NULL; 245 Profile* profile = NULL;
246 if (user->is_profile_created()) 246 if (user->is_profile_created())
Thiemo Nagel 2014/08/11 14:39:54 Nit: I think it would be more readable to turn the
dzhioev (left Google) 2014/08/12 14:56:28 Done.
247 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); 247 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
248 else
249 profile = ProfileManager::GetActiveUserProfile();
250 248
251 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance 249 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
252 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. 250 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
251 if (profile && UserManager::Get()->IsLoggedInAsGuest())
252 profile = profile->GetOffTheRecordProfile();
253 return profile;
Nikita (slow) 2014/08/11 12:29:24 nit: Insert empty line before return.
dzhioev (left Google) 2014/08/12 14:56:28 Done.
254 }
255
256 Profile* ProfileHelper::GetProfileByUserUnsafe(const user_manager::User* user) {
257 // This map is non-empty only in tests.
258 if (!user_to_profile_for_testing_.empty()) {
259 std::map<const user_manager::User*, Profile*>::const_iterator it =
260 user_to_profile_for_testing_.find(user);
261 return it == user_to_profile_for_testing_.end() ? NULL : it->second;
262 }
263
264 Profile* profile = NULL;
265 if (user->is_profile_created()) {
266 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
267 } else {
268 LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when "
Nikita (slow) 2014/08/11 12:29:24 I don't think it's a good idea to commit this WARN
Thiemo Nagel 2014/08/11 14:39:54 How about DLOG() instead of LOG()?
dzhioev (left Google) 2014/08/12 14:56:28 Now this message shoots only once on adding user i
269 "|user|'s profile is not created. It probably means that "
270 "something is wrong with a calling code. Please report in "
271 "http://crbug.com/361528 if you see this message.";
272 profile = ProfileManager::GetActiveUserProfile();
273 }
274
275 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
276 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
253 if (profile && UserManager::Get()->IsLoggedInAsGuest()) 277 if (profile && UserManager::Get()->IsLoggedInAsGuest())
254 profile = profile->GetOffTheRecordProfile(); 278 profile = profile->GetOffTheRecordProfile();
255 return profile; 279 return profile;
256 } 280 }
257 281
258 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) { 282 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) {
259 // This map is non-empty only in tests. 283 // This map is non-empty only in tests.
260 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { 284 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) {
261 if (always_return_primary_user_for_testing) 285 if (always_return_primary_user_for_testing)
262 return const_cast<user_manager::User*>( 286 return const_cast<user_manager::User*>(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ProfileHelper::SetProfileToUserForTestingEnabled(true); 389 ProfileHelper::SetProfileToUserForTestingEnabled(true);
366 } 390 }
367 391
368 void ProfileHelper::SetUserToProfileMappingForTesting( 392 void ProfileHelper::SetUserToProfileMappingForTesting(
369 const user_manager::User* user, 393 const user_manager::User* user,
370 Profile* profile) { 394 Profile* profile) {
371 user_to_profile_for_testing_[user] = profile; 395 user_to_profile_for_testing_[user] = profile;
372 } 396 }
373 397
374 } // namespace chromeos 398 } // 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