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

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

Issue 444903002: [cros] user_manager component - move UserManagerBase and UserManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: similarity 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/chromeos/login/users/user_manager.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
16 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
19 #include "components/user_manager/user.h" 18 #include "components/user_manager/user.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 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { 26 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) {
27 // Do not add profile dir prefix for legacy profile dir and test 27 // 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 28 // user profile. The reason of not adding prefix for test user profile
29 // is to keep the promise that TestingProfile::kTestUserProfileDir and 29 // is to keep the promise that TestingProfile::kTestUserProfileDir and
(...skipping 24 matching lines...) Expand all
54 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
55 // ProfileHelper, public 55 // ProfileHelper, public
56 56
57 ProfileHelper::ProfileHelper() 57 ProfileHelper::ProfileHelper()
58 : signin_profile_clear_requested_(false) { 58 : signin_profile_clear_requested_(false) {
59 } 59 }
60 60
61 ProfileHelper::~ProfileHelper() { 61 ProfileHelper::~ProfileHelper() {
62 // Checking whether UserManager is initialized covers case 62 // Checking whether UserManager is initialized covers case
63 // when ScopedTestUserManager is used. 63 // when ScopedTestUserManager is used.
64 if (UserManager::IsInitialized()) 64 if (user_manager::UserManager::IsInitialized())
65 UserManager::Get()->RemoveSessionStateObserver(this); 65 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
66 } 66 }
67 67
68 // static 68 // static
69 ProfileHelper* ProfileHelper::Get() { 69 ProfileHelper* ProfileHelper::Get() {
70 return g_browser_process->platform_part()->profile_helper(); 70 return g_browser_process->platform_part()->profile_helper();
71 } 71 }
72 72
73 // static 73 // static
74 Profile* ProfileHelper::GetProfileByUserIdHash( 74 Profile* ProfileHelper::GetProfileByUserIdHash(
75 const std::string& user_id_hash) { 75 const std::string& user_id_hash) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 : base::FilePath(user_id_hash); 144 : base::FilePath(user_id_hash);
145 } 145 }
146 146
147 // static 147 // static
148 base::FilePath ProfileHelper::GetUserProfileDirByUserId( 148 base::FilePath ProfileHelper::GetUserProfileDirByUserId(
149 const std::string& user_id) { 149 const std::string& user_id) {
150 // TODO(dpolukhin): Remove Chrome OS specific profile path logic from 150 // TODO(dpolukhin): Remove Chrome OS specific profile path logic from
151 // ProfileManager and use only this function to construct profile path. 151 // ProfileManager and use only this function to construct profile path.
152 // TODO(nkostylev): Cleanup profile dir related code paths crbug.com/294233 152 // TODO(nkostylev): Cleanup profile dir related code paths crbug.com/294233
153 base::FilePath profile_dir; 153 base::FilePath profile_dir;
154 const user_manager::User* user = UserManager::Get()->FindUser(user_id); 154 const user_manager::User* user =
155 user_manager::UserManager::Get()->FindUser(user_id);
155 if (user && !user->username_hash().empty()) 156 if (user && !user->username_hash().empty())
156 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash()); 157 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash());
157 158
158 ProfileManager* profile_manager = g_browser_process->profile_manager(); 159 ProfileManager* profile_manager = g_browser_process->profile_manager();
159 profile_dir = profile_manager->user_data_dir().Append(profile_dir); 160 profile_dir = profile_manager->user_data_dir().Append(profile_dir);
160 161
161 return profile_dir; 162 return profile_dir;
162 } 163 }
163 164
164 // static 165 // static
165 bool ProfileHelper::IsSigninProfile(Profile* profile) { 166 bool ProfileHelper::IsSigninProfile(Profile* profile) {
166 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 167 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
167 } 168 }
168 169
169 // static 170 // static
170 bool ProfileHelper::IsOwnerProfile(Profile* profile) { 171 bool ProfileHelper::IsOwnerProfile(Profile* profile) {
171 if (!profile) 172 if (!profile)
172 return false; 173 return false;
173 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 174 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
174 if (!user) 175 if (!user)
175 return false; 176 return false;
176 177
177 return user->email() == chromeos::UserManager::Get()->GetOwnerEmail(); 178 return user->email() == user_manager::UserManager::Get()->GetOwnerEmail();
178 } 179 }
179 180
180 //static 181 // static
181 bool ProfileHelper::IsPrimaryProfile(Profile* profile) { 182 bool ProfileHelper::IsPrimaryProfile(Profile* profile) {
182 if (!profile) 183 if (!profile)
183 return false; 184 return false;
184 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 185 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
185 if (!user) 186 if (!user)
186 return false; 187 return false;
187 return user == chromeos::UserManager::Get()->GetPrimaryUser(); 188 return user == user_manager::UserManager::Get()->GetPrimaryUser();
188 } 189 }
189 190
190 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 191 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
191 // Initialize Chrome OS preferences like touch pad sensitivity. For the 192 // Initialize Chrome OS preferences like touch pad sensitivity. For the
192 // preferences to work in the guest mode, the initialization has to be 193 // preferences to work in the guest mode, the initialization has to be
193 // done after |profile| is switched to the incognito profile (which 194 // done after |profile| is switched to the incognito profile (which
194 // is actually GuestSessionProfile in the guest mode). See the 195 // is actually GuestSessionProfile in the guest mode). See the
195 // GetOffTheRecordProfile() call above. 196 // GetOffTheRecordProfile() call above.
196 profile->InitChromeOSPreferences(); 197 profile->InitChromeOSPreferences();
197 198
198 // Add observer so we can see when the first profile's session restore is 199 // Add observer so we can see when the first profile's session restore is
199 // completed. After that, we won't need the default profile anymore. 200 // completed. After that, we won't need the default profile anymore.
200 if (!IsSigninProfile(profile) && 201 if (!IsSigninProfile(profile) &&
201 UserManager::Get()->IsLoggedInAsRegularUser() && 202 user_manager::UserManager::Get()->IsLoggedInAsRegularUser() &&
202 !UserManager::Get()->IsLoggedInAsStub()) { 203 !user_manager::UserManager::Get()->IsLoggedInAsStub()) {
203 chromeos::OAuth2LoginManager* login_manager = 204 chromeos::OAuth2LoginManager* login_manager =
204 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile( 205 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
205 profile); 206 profile);
206 if (login_manager) 207 if (login_manager)
207 login_manager->AddObserver(this); 208 login_manager->AddObserver(this);
208 } 209 }
209 } 210 }
210 211
211 base::FilePath ProfileHelper::GetActiveUserProfileDir() { 212 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
212 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); 213 return ProfileHelper::GetUserProfileDir(active_user_id_hash_);
213 } 214 }
214 215
215 void ProfileHelper::Initialize() { 216 void ProfileHelper::Initialize() {
216 UserManager::Get()->AddSessionStateObserver(this); 217 user_manager::UserManager::Get()->AddSessionStateObserver(this);
217 } 218 }
218 219
219 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { 220 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
220 on_clear_callbacks_.push_back(on_clear_callback); 221 on_clear_callbacks_.push_back(on_clear_callback);
221 if (signin_profile_clear_requested_) 222 if (signin_profile_clear_requested_)
222 return; 223 return;
223 ProfileManager* profile_manager = g_browser_process->profile_manager(); 224 ProfileManager* profile_manager = g_browser_process->profile_manager();
224 // Check if signin profile was loaded. 225 // Check if signin profile was loaded.
225 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { 226 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) {
226 OnBrowsingDataRemoverDone(); 227 OnBrowsingDataRemoverDone();
(...skipping 16 matching lines...) Expand all
243 } 244 }
244 245
245 Profile* profile = NULL; 246 Profile* profile = NULL;
246 if (user->is_profile_created()) 247 if (user->is_profile_created())
247 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); 248 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
248 else 249 else
249 profile = ProfileManager::GetActiveUserProfile(); 250 profile = ProfileManager::GetActiveUserProfile();
250 251
251 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance 252 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
252 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. 253 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
253 if (profile && UserManager::Get()->IsLoggedInAsGuest()) 254 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest())
254 profile = profile->GetOffTheRecordProfile(); 255 profile = profile->GetOffTheRecordProfile();
255 return profile; 256 return profile;
256 } 257 }
257 258
258 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) { 259 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) {
259 // This map is non-empty only in tests. 260 // This map is non-empty only in tests.
260 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { 261 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) {
261 if (always_return_primary_user_for_testing) 262 if (always_return_primary_user_for_testing)
262 return const_cast<user_manager::User*>( 263 return const_cast<user_manager::User*>(
263 UserManager::Get()->GetPrimaryUser()); 264 user_manager::UserManager::Get()->GetPrimaryUser());
264 265
265 const std::string& user_name = profile->GetProfileName(); 266 const std::string& user_name = profile->GetProfileName();
266 for (user_manager::UserList::const_iterator it = 267 for (user_manager::UserList::const_iterator it =
267 user_list_for_testing_.begin(); 268 user_list_for_testing_.begin();
268 it != user_list_for_testing_.end(); 269 it != user_list_for_testing_.end();
269 ++it) { 270 ++it) {
270 if ((*it)->email() == user_name) 271 if ((*it)->email() == user_name)
271 return *it; 272 return *it;
272 } 273 }
273 274
274 // In case of test setup we should always default to primary user. 275 // In case of test setup we should always default to primary user.
275 return const_cast<user_manager::User*>( 276 return const_cast<user_manager::User*>(
276 UserManager::Get()->GetPrimaryUser()); 277 user_manager::UserManager::Get()->GetPrimaryUser());
277 } 278 }
278 279
279 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 280 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
280 if (ProfileHelper::IsSigninProfile(profile)) 281 if (ProfileHelper::IsSigninProfile(profile))
281 return NULL; 282 return NULL;
282 283
283 UserManager* user_manager = UserManager::Get(); 284 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
284 285
285 // Special case for non-CrOS tests that do create several profiles 286 // Special case for non-CrOS tests that do create several profiles
286 // and don't really care about mapping to the real user. 287 // and don't really care about mapping to the real user.
287 // Without multi-profiles on Chrome OS such tests always got active_user_. 288 // Without multi-profiles on Chrome OS such tests always got active_user_.
288 // Now these tests will specify special flag to continue working. 289 // Now these tests will specify special flag to continue working.
289 // In future those tests can get a proper CrOS configuration i.e. register 290 // In future those tests can get a proper CrOS configuration i.e. register
290 // and login several users if they want to work with an additional profile. 291 // and login several users if they want to work with an additional profile.
291 if (CommandLine::ForCurrentProcess()->HasSwitch( 292 if (CommandLine::ForCurrentProcess()->HasSwitch(
292 switches::kIgnoreUserProfileMappingForTests)) { 293 switches::kIgnoreUserProfileMappingForTests)) {
293 return user_manager->GetActiveUser(); 294 return user_manager->GetActiveUser();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ProfileHelper::SetProfileToUserForTestingEnabled(true); 366 ProfileHelper::SetProfileToUserForTestingEnabled(true);
366 } 367 }
367 368
368 void ProfileHelper::SetUserToProfileMappingForTesting( 369 void ProfileHelper::SetUserToProfileMappingForTesting(
369 const user_manager::User* user, 370 const user_manager::User* user,
370 Profile* profile) { 371 Profile* profile) {
371 user_to_profile_for_testing_[user] = profile; 372 user_to_profile_for_testing_[user] = profile;
372 } 373 }
373 374
374 } // namespace chromeos 375 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698