| OLD | NEW |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (UserManager::IsInitialized()) |
| 65 UserManager::Get()->RemoveSessionStateObserver(this); | 65 GetUserManager()->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 Loading... |
| 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* user = UserManager::Get()->FindUser(user_id); | 154 const User* user = GetUserManager()->FindUser(user_id); |
| 155 if (user && !user->username_hash().empty()) | 155 if (user && !user->username_hash().empty()) |
| 156 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash()); | 156 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash()); |
| 157 | 157 |
| 158 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 158 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 159 profile_dir = profile_manager->user_data_dir().Append(profile_dir); | 159 profile_dir = profile_manager->user_data_dir().Append(profile_dir); |
| 160 | 160 |
| 161 return profile_dir; | 161 return profile_dir; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // static | 164 // static |
| 165 bool ProfileHelper::IsSigninProfile(Profile* profile) { | 165 bool ProfileHelper::IsSigninProfile(Profile* profile) { |
| 166 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; | 166 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // static | 169 // static |
| 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 chromeos::User* user = ProfileHelper::Get()->GetUserByProfile(profile); | 173 chromeos::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::GetUserManager()->GetOwnerEmail(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { | 180 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { |
| 181 // Initialize Chrome OS preferences like touch pad sensitivity. For the | 181 // Initialize Chrome OS preferences like touch pad sensitivity. For the |
| 182 // preferences to work in the guest mode, the initialization has to be | 182 // preferences to work in the guest mode, the initialization has to be |
| 183 // done after |profile| is switched to the incognito profile (which | 183 // done after |profile| is switched to the incognito profile (which |
| 184 // is actually GuestSessionProfile in the guest mode). See the | 184 // is actually GuestSessionProfile in the guest mode). See the |
| 185 // GetOffTheRecordProfile() call above. | 185 // GetOffTheRecordProfile() call above. |
| 186 profile->InitChromeOSPreferences(); | 186 profile->InitChromeOSPreferences(); |
| 187 | 187 |
| 188 // Add observer so we can see when the first profile's session restore is | 188 // Add observer so we can see when the first profile's session restore is |
| 189 // completed. After that, we won't need the default profile anymore. | 189 // completed. After that, we won't need the default profile anymore. |
| 190 if (!IsSigninProfile(profile) && | 190 if (!IsSigninProfile(profile) && |
| 191 UserManager::Get()->IsLoggedInAsRegularUser() && | 191 GetUserManager()->IsLoggedInAsRegularUser() && |
| 192 !UserManager::Get()->IsLoggedInAsStub()) { | 192 !GetUserManager()->IsLoggedInAsStub()) { |
| 193 chromeos::OAuth2LoginManager* login_manager = | 193 chromeos::OAuth2LoginManager* login_manager = |
| 194 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile( | 194 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile( |
| 195 profile); | 195 profile); |
| 196 if (login_manager) | 196 if (login_manager) |
| 197 login_manager->AddObserver(this); | 197 login_manager->AddObserver(this); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 base::FilePath ProfileHelper::GetActiveUserProfileDir() { | 201 base::FilePath ProfileHelper::GetActiveUserProfileDir() { |
| 202 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); | 202 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void ProfileHelper::Initialize() { | 205 void ProfileHelper::Initialize() { |
| 206 UserManager::Get()->AddSessionStateObserver(this); | 206 GetUserManager()->AddSessionStateObserver(this); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { | 209 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { |
| 210 on_clear_callbacks_.push_back(on_clear_callback); | 210 on_clear_callbacks_.push_back(on_clear_callback); |
| 211 if (signin_profile_clear_requested_) | 211 if (signin_profile_clear_requested_) |
| 212 return; | 212 return; |
| 213 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 213 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 214 // Check if signin profile was loaded. | 214 // Check if signin profile was loaded. |
| 215 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { | 215 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { |
| 216 OnBrowsingDataRemoverDone(); | 216 OnBrowsingDataRemoverDone(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 233 } | 233 } |
| 234 | 234 |
| 235 Profile* profile = NULL; | 235 Profile* profile = NULL; |
| 236 if (user->is_profile_created()) | 236 if (user->is_profile_created()) |
| 237 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); | 237 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); |
| 238 else | 238 else |
| 239 profile = ProfileManager::GetActiveUserProfile(); | 239 profile = ProfileManager::GetActiveUserProfile(); |
| 240 | 240 |
| 241 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance | 241 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance |
| 242 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. | 242 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. |
| 243 if (profile && UserManager::Get()->IsLoggedInAsGuest()) | 243 if (profile && GetUserManager()->IsLoggedInAsGuest()) |
| 244 profile = profile->GetOffTheRecordProfile(); | 244 profile = profile->GetOffTheRecordProfile(); |
| 245 return profile; | 245 return profile; |
| 246 } | 246 } |
| 247 | 247 |
| 248 User* ProfileHelper::GetUserByProfile(Profile* profile) { | 248 User* ProfileHelper::GetUserByProfile(Profile* profile) { |
| 249 // This map is non-empty only in tests. | 249 // This map is non-empty only in tests. |
| 250 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { | 250 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { |
| 251 if (always_return_primary_user_for_testing) | 251 if (always_return_primary_user_for_testing) |
| 252 return const_cast<User*>(UserManager::Get()->GetPrimaryUser()); | 252 return const_cast<User*>(GetUserManager()->GetPrimaryUser()); |
| 253 | 253 |
| 254 const std::string& user_name = profile->GetProfileName(); | 254 const std::string& user_name = profile->GetProfileName(); |
| 255 for (UserList::const_iterator it = user_list_for_testing_.begin(); | 255 for (UserList::const_iterator it = user_list_for_testing_.begin(); |
| 256 it != user_list_for_testing_.end(); | 256 it != user_list_for_testing_.end(); |
| 257 ++it) { | 257 ++it) { |
| 258 if ((*it)->email() == user_name) | 258 if ((*it)->email() == user_name) |
| 259 return *it; | 259 return *it; |
| 260 } | 260 } |
| 261 | 261 |
| 262 // In case of test setup we should always default to primary user. | 262 // In case of test setup we should always default to primary user. |
| 263 return const_cast<User*>(UserManager::Get()->GetPrimaryUser()); | 263 return const_cast<User*>(GetUserManager()->GetPrimaryUser()); |
| 264 } | 264 } |
| 265 | 265 |
| 266 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 266 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 267 if (ProfileHelper::IsSigninProfile(profile)) | 267 if (ProfileHelper::IsSigninProfile(profile)) |
| 268 return NULL; | 268 return NULL; |
| 269 | 269 |
| 270 UserManager* user_manager = UserManager::Get(); | 270 UserManager* user_manager = GetUserManager(); |
| 271 | 271 |
| 272 // Special case for non-CrOS tests that do create several profiles | 272 // Special case for non-CrOS tests that do create several profiles |
| 273 // and don't really care about mapping to the real user. | 273 // and don't really care about mapping to the real user. |
| 274 // Without multi-profiles on Chrome OS such tests always got active_user_. | 274 // Without multi-profiles on Chrome OS such tests always got active_user_. |
| 275 // Now these tests will specify special flag to continue working. | 275 // Now these tests will specify special flag to continue working. |
| 276 // In future those tests can get a proper CrOS configuration i.e. register | 276 // In future those tests can get a proper CrOS configuration i.e. register |
| 277 // and login several users if they want to work with an additional profile. | 277 // and login several users if they want to work with an additional profile. |
| 278 if (CommandLine::ForCurrentProcess()->HasSwitch( | 278 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 279 switches::kIgnoreUserProfileMappingForTests)) { | 279 switches::kIgnoreUserProfileMappingForTests)) { |
| 280 return user_manager->GetActiveUser(); | 280 return user_manager->GetActiveUser(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 always_return_primary_user_for_testing = true; | 350 always_return_primary_user_for_testing = true; |
| 351 ProfileHelper::SetProfileToUserForTestingEnabled(true); | 351 ProfileHelper::SetProfileToUserForTestingEnabled(true); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void ProfileHelper::SetUserToProfileMappingForTesting(const User* user, | 354 void ProfileHelper::SetUserToProfileMappingForTesting(const User* user, |
| 355 Profile* profile) { | 355 Profile* profile) { |
| 356 user_to_profile_for_testing_[user] = profile; | 356 user_to_profile_for_testing_[user] = profile; |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace chromeos | 359 } // namespace chromeos |
| OLD | NEW |