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

Side by Side Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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/barrier_closure.h" 7 #include "base/barrier_closure.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 // static 160 // static
161 bool ProfileHelper::IsOwnerProfile(Profile* profile) { 161 bool ProfileHelper::IsOwnerProfile(Profile* profile) {
162 if (!profile) 162 if (!profile)
163 return false; 163 return false;
164 const user_manager::User* user = 164 const user_manager::User* user =
165 ProfileHelper::Get()->GetUserByProfile(profile); 165 ProfileHelper::Get()->GetUserByProfile(profile);
166 if (!user) 166 if (!user)
167 return false; 167 return false;
168 168
169 return user->email() == user_manager::UserManager::Get()->GetOwnerEmail(); 169 return user->GetUserID() == user_manager::UserManager::Get()->GetOwnerID();
170 } 170 }
171 171
172 // static 172 // static
173 bool ProfileHelper::IsPrimaryProfile(const Profile* profile) { 173 bool ProfileHelper::IsPrimaryProfile(const Profile* profile) {
174 if (!profile) 174 if (!profile)
175 return false; 175 return false;
176 const user_manager::User* user = 176 const user_manager::User* user =
177 ProfileHelper::Get()->GetUserByProfile(profile); 177 ProfileHelper::Get()->GetUserByProfile(profile);
178 if (!user) 178 if (!user)
179 return false; 179 return false;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 275
276 Profile* profile = NULL; 276 Profile* profile = NULL;
277 if (user->is_profile_created()) { 277 if (user->is_profile_created()) {
278 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); 278 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
279 } else { 279 } else {
280 LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when " 280 LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when "
281 "|user|'s profile is not created. It probably means that " 281 "|user|'s profile is not created. It probably means that "
282 "something is wrong with a calling code. Please report in " 282 "something is wrong with a calling code. Please report in "
283 "http://crbug.com/361528 if you see this message. user_id: " 283 "http://crbug.com/361528 if you see this message. user_id: "
284 << user->email(); 284 << user->GetUserID().GetUserEmail();
285 profile = ProfileManager::GetActiveUserProfile(); 285 profile = ProfileManager::GetActiveUserProfile();
286 } 286 }
287 287
288 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance 288 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
289 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. 289 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
290 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest()) 290 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest())
291 profile = profile->GetOffTheRecordProfile(); 291 profile = profile->GetOffTheRecordProfile();
292 return profile; 292 return profile;
293 } 293 }
294 294
295 const user_manager::User* ProfileHelper::GetUserByProfile( 295 const user_manager::User* ProfileHelper::GetUserByProfile(
296 const Profile* profile) const { 296 const Profile* profile) const {
297 // This map is non-empty only in tests. 297 // This map is non-empty only in tests.
298 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { 298 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) {
299 if (always_return_primary_user_for_testing) 299 if (always_return_primary_user_for_testing)
300 return user_manager::UserManager::Get()->GetPrimaryUser(); 300 return user_manager::UserManager::Get()->GetPrimaryUser();
301 301
302 const std::string& user_name = profile->GetProfileUserName(); 302 const user_manager::UserID user_id = user_manager::UserID::FromUserEmail(pro file->GetProfileUserName());
303 for (user_manager::UserList::const_iterator it = 303 for (user_manager::UserList::const_iterator it =
304 user_list_for_testing_.begin(); 304 user_list_for_testing_.begin();
305 it != user_list_for_testing_.end(); 305 it != user_list_for_testing_.end();
306 ++it) { 306 ++it) {
307 if ((*it)->email() == user_name) 307 if ((*it)->GetUserID() == user_id)
308 return *it; 308 return *it;
309 } 309 }
310 310
311 // In case of test setup we should always default to primary user. 311 // In case of test setup we should always default to primary user.
312 return user_manager::UserManager::Get()->GetPrimaryUser(); 312 return user_manager::UserManager::Get()->GetPrimaryUser();
313 } 313 }
314 314
315 DCHECK(!content::BrowserThread::IsThreadInitialized( 315 DCHECK(!content::BrowserThread::IsThreadInitialized(
316 content::BrowserThread::UI) || 316 content::BrowserThread::UI) ||
317 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 317 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 user_to_profile_for_testing_[user] = profile; 421 user_to_profile_for_testing_[user] = profile;
422 } 422 }
423 423
424 // static 424 // static
425 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( 425 std::string ProfileHelper::GetUserIdHashByUserIdForTesting(
426 const std::string& user_id) { 426 const std::string& user_id) {
427 return user_id + kUserIdHashSuffix; 427 return user_id + kUserIdHashSuffix;
428 } 428 }
429 429
430 } // namespace chromeos 430 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698