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

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

Issue 442043002: ProfileManager doesn't depend on "--login-profile" switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased and 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"
11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" 11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
18 #include "components/user_manager/user.h" 18 #include "components/user_manager/user.h"
19 #include "components/user_manager/user_manager.h" 19 #include "components/user_manager/user_manager.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 namespace { 24 namespace {
25 25
26 // As defined in /chromeos/dbus/cryptohome_client.cc.
27 static const char kUserIdHashSuffix[] = "-hash";
28
26 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { 29 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) {
27 // Do not add profile dir prefix for legacy profile dir and test 30 // Do not add profile dir prefix for legacy profile dir and test
28 // user profile. The reason of not adding prefix for test user profile 31 // user profile. The reason of not adding prefix for test user profile
29 // is to keep the promise that TestingProfile::kTestUserProfileDir and 32 // is to keep the promise that TestingProfile::kTestUserProfileDir and
30 // chrome::kTestUserProfileDir are always in sync. Otherwise, 33 // chrome::kTestUserProfileDir are always in sync. Otherwise,
31 // TestingProfile::kTestUserProfileDir needs to be dynamically calculated 34 // TestingProfile::kTestUserProfileDir needs to be dynamically calculated
32 // based on whether multi profile is enabled or not. 35 // based on whether multi profile is enabled or not.
33 return user_id_hash != chrome::kLegacyProfileDir && 36 return user_id_hash != chrome::kLegacyProfileDir &&
34 user_id_hash != chrome::kTestUserProfileDir; 37 user_id_hash != chrome::kTestUserProfileDir;
35 } 38 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // crbug.com/238998 88 // crbug.com/238998
86 // TODO(nkostylev): Remove this check once these bugs are fixed. 89 // TODO(nkostylev): Remove this check once these bugs are fixed.
87 DCHECK(!user_id_hash.empty()); 90 DCHECK(!user_id_hash.empty());
88 ProfileManager* profile_manager = g_browser_process->profile_manager(); 91 ProfileManager* profile_manager = g_browser_process->profile_manager();
89 base::FilePath profile_path = profile_manager->user_data_dir(); 92 base::FilePath profile_path = profile_manager->user_data_dir();
90 93
91 return profile_path.Append(GetUserProfileDir(user_id_hash)); 94 return profile_path.Append(GetUserProfileDir(user_id_hash));
92 } 95 }
93 96
94 // static 97 // static
95 base::FilePath ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch() {
96 const std::string login_profile_value =
97 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
98 chromeos::switches::kLoginProfile);
99 return ProfileHelper::GetUserProfileDir(login_profile_value);
100 }
101
102 // static
103 base::FilePath ProfileHelper::GetSigninProfileDir() { 98 base::FilePath ProfileHelper::GetSigninProfileDir() {
104 ProfileManager* profile_manager = g_browser_process->profile_manager(); 99 ProfileManager* profile_manager = g_browser_process->profile_manager();
105 base::FilePath user_data_dir = profile_manager->user_data_dir(); 100 base::FilePath user_data_dir = profile_manager->user_data_dir();
106 return user_data_dir.AppendASCII(chrome::kInitialProfile); 101 return user_data_dir.AppendASCII(chrome::kInitialProfile);
107 } 102 }
108 103
109 // static 104 // static
110 Profile* ProfileHelper::GetSigninProfile() { 105 Profile* ProfileHelper::GetSigninProfile() {
111 ProfileManager* profile_manager = g_browser_process->profile_manager(); 106 ProfileManager* profile_manager = g_browser_process->profile_manager();
112 return profile_manager->GetProfile(GetSigninProfileDir())-> 107 return profile_manager->GetProfile(GetSigninProfileDir())->
(...skipping 18 matching lines...) Expand all
131 return std::string(); 126 return std::string();
132 } 127 }
133 128
134 return profile_dir.substr(prefix.length(), 129 return profile_dir.substr(prefix.length(),
135 profile_dir.length() - prefix.length()); 130 profile_dir.length() - prefix.length());
136 } 131 }
137 132
138 // static 133 // static
139 base::FilePath ProfileHelper::GetUserProfileDir( 134 base::FilePath ProfileHelper::GetUserProfileDir(
140 const std::string& user_id_hash) { 135 const std::string& user_id_hash) {
141 DCHECK(!user_id_hash.empty()); 136 CHECK(!user_id_hash.empty());
142 return ShouldAddProfileDirPrefix(user_id_hash) 137 return ShouldAddProfileDirPrefix(user_id_hash)
143 ? base::FilePath(chrome::kProfileDirPrefix + user_id_hash) 138 ? base::FilePath(chrome::kProfileDirPrefix + user_id_hash)
144 : base::FilePath(user_id_hash); 139 : base::FilePath(user_id_hash);
145 } 140 }
146 141
147 // static 142 // static
148 base::FilePath ProfileHelper::GetUserProfileDirByUserId(
149 const std::string& user_id) {
150 // TODO(dpolukhin): Remove Chrome OS specific profile path logic from
151 // ProfileManager and use only this function to construct profile path.
152 // TODO(nkostylev): Cleanup profile dir related code paths crbug.com/294233
153 base::FilePath profile_dir;
154 const user_manager::User* user =
155 user_manager::UserManager::Get()->FindUser(user_id);
156 if (user && !user->username_hash().empty())
157 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash());
158
159 ProfileManager* profile_manager = g_browser_process->profile_manager();
160 profile_dir = profile_manager->user_data_dir().Append(profile_dir);
161
162 return profile_dir;
163 }
164
165 // static
166 bool ProfileHelper::IsSigninProfile(Profile* profile) { 143 bool ProfileHelper::IsSigninProfile(Profile* profile) {
167 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 144 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
168 } 145 }
169 146
170 // static 147 // static
171 bool ProfileHelper::IsOwnerProfile(Profile* profile) { 148 bool ProfileHelper::IsOwnerProfile(Profile* profile) {
172 if (!profile) 149 if (!profile)
173 return false; 150 return false;
174 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 151 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
175 if (!user) 152 if (!user)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 ++it) { 273 ++it) {
297 if ((*it)->email() == user_name) 274 if ((*it)->email() == user_name)
298 return *it; 275 return *it;
299 } 276 }
300 277
301 // In case of test setup we should always default to primary user. 278 // In case of test setup we should always default to primary user.
302 return const_cast<user_manager::User*>( 279 return const_cast<user_manager::User*>(
303 user_manager::UserManager::Get()->GetPrimaryUser()); 280 user_manager::UserManager::Get()->GetPrimaryUser());
304 } 281 }
305 282
306 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 283 DCHECK(!content::BrowserThread::IsThreadInitialized(
284 content::BrowserThread::UI) ||
285 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
307 if (ProfileHelper::IsSigninProfile(profile)) 286 if (ProfileHelper::IsSigninProfile(profile))
308 return NULL; 287 return NULL;
309 288
310 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 289 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
311 290
312 // Special case for non-CrOS tests that do create several profiles 291 // Special case for non-CrOS tests that do create several profiles
313 // and don't really care about mapping to the real user. 292 // and don't really care about mapping to the real user.
314 // Without multi-profiles on Chrome OS such tests always got active_user_. 293 // Without multi-profiles on Chrome OS such tests always got active_user_.
315 // Now these tests will specify special flag to continue working. 294 // Now these tests will specify special flag to continue working.
316 // In future those tests can get a proper CrOS configuration i.e. register 295 // In future those tests can get a proper CrOS configuration i.e. register
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 login_manager->RemoveObserver(this); 344 login_manager->RemoveObserver(this);
366 ClearSigninProfile(base::Closure()); 345 ClearSigninProfile(base::Closure());
367 } 346 }
368 } 347 }
369 348
370 //////////////////////////////////////////////////////////////////////////////// 349 ////////////////////////////////////////////////////////////////////////////////
371 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 350 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
372 351
373 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 352 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
374 active_user_id_hash_ = hash; 353 active_user_id_hash_ = hash;
375 base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
376 VLOG(1) << "Switching to profile path: " << profile_path.value();
377 } 354 }
378 355
379 void ProfileHelper::SetProfileToUserMappingForTesting( 356 void ProfileHelper::SetProfileToUserMappingForTesting(
380 user_manager::User* user) { 357 user_manager::User* user) {
381 user_list_for_testing_.push_back(user); 358 user_list_for_testing_.push_back(user);
382 } 359 }
383 360
384 // static 361 // static
385 void ProfileHelper::SetProfileToUserForTestingEnabled(bool enabled) { 362 void ProfileHelper::SetProfileToUserForTestingEnabled(bool enabled) {
386 enable_profile_to_user_testing = enabled; 363 enable_profile_to_user_testing = enabled;
387 } 364 }
388 365
389 // static 366 // static
390 void ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(bool value) { 367 void ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(bool value) {
391 always_return_primary_user_for_testing = true; 368 always_return_primary_user_for_testing = true;
392 ProfileHelper::SetProfileToUserForTestingEnabled(true); 369 ProfileHelper::SetProfileToUserForTestingEnabled(true);
393 } 370 }
394 371
395 void ProfileHelper::SetUserToProfileMappingForTesting( 372 void ProfileHelper::SetUserToProfileMappingForTesting(
396 const user_manager::User* user, 373 const user_manager::User* user,
397 Profile* profile) { 374 Profile* profile) {
398 user_to_profile_for_testing_[user] = profile; 375 user_to_profile_for_testing_[user] = profile;
399 } 376 }
400 377
378 std::string ProfileHelper::GetUserIdHashByUserIdForTests(
379 const std::string& user_id) const {
380 return user_id + kUserIdHashSuffix;
381 }
382
401 } // namespace chromeos 383 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698