| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 Profile* ProfileHelper::GetSigninProfile() { | 105 Profile* ProfileHelper::GetSigninProfile() { |
| 106 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 106 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 107 return profile_manager->GetProfile(GetSigninProfileDir())-> | 107 return profile_manager->GetProfile(GetSigninProfileDir())-> |
| 108 GetOffTheRecordProfile(); | 108 GetOffTheRecordProfile(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // static | 111 // static |
| 112 std::string ProfileHelper::GetUserIdHashFromProfile(Profile* profile) { | 112 std::string ProfileHelper::GetUserIdHashFromProfile(const Profile* profile) { |
| 113 if (!profile) | 113 if (!profile) |
| 114 return std::string(); | 114 return std::string(); |
| 115 | 115 |
| 116 std::string profile_dir = profile->GetPath().BaseName().value(); | 116 std::string profile_dir = profile->GetPath().BaseName().value(); |
| 117 | 117 |
| 118 // Don't strip prefix if the dir is not supposed to be prefixed. | 118 // Don't strip prefix if the dir is not supposed to be prefixed. |
| 119 if (!ShouldAddProfileDirPrefix(profile_dir)) | 119 if (!ShouldAddProfileDirPrefix(profile_dir)) |
| 120 return profile_dir; | 120 return profile_dir; |
| 121 | 121 |
| 122 // Check that profile directory starts with the correct prefix. | 122 // Check that profile directory starts with the correct prefix. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 // static | 133 // static |
| 134 base::FilePath ProfileHelper::GetUserProfileDir( | 134 base::FilePath ProfileHelper::GetUserProfileDir( |
| 135 const std::string& user_id_hash) { | 135 const std::string& user_id_hash) { |
| 136 CHECK(!user_id_hash.empty()); | 136 CHECK(!user_id_hash.empty()); |
| 137 return ShouldAddProfileDirPrefix(user_id_hash) | 137 return ShouldAddProfileDirPrefix(user_id_hash) |
| 138 ? base::FilePath(chrome::kProfileDirPrefix + user_id_hash) | 138 ? base::FilePath(chrome::kProfileDirPrefix + user_id_hash) |
| 139 : base::FilePath(user_id_hash); | 139 : base::FilePath(user_id_hash); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 bool ProfileHelper::IsSigninProfile(Profile* profile) { | 143 bool ProfileHelper::IsSigninProfile(const Profile* profile) { |
| 144 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; | 144 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; |
| 145 } | 145 } |
| 146 | 146 |
| 147 // static | 147 // static |
| 148 bool ProfileHelper::IsOwnerProfile(Profile* profile) { | 148 bool ProfileHelper::IsOwnerProfile(Profile* profile) { |
| 149 if (!profile) | 149 if (!profile) |
| 150 return false; | 150 return false; |
| 151 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); | 151 const user_manager::User* user = |
| 152 ProfileHelper::Get()->GetUserByProfile(profile); |
| 152 if (!user) | 153 if (!user) |
| 153 return false; | 154 return false; |
| 154 | 155 |
| 155 return user->email() == user_manager::UserManager::Get()->GetOwnerEmail(); | 156 return user->email() == user_manager::UserManager::Get()->GetOwnerEmail(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 // static | 159 // static |
| 159 bool ProfileHelper::IsPrimaryProfile(Profile* profile) { | 160 bool ProfileHelper::IsPrimaryProfile(const Profile* profile) { |
| 160 if (!profile) | 161 if (!profile) |
| 161 return false; | 162 return false; |
| 162 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); | 163 const user_manager::User* user = |
| 164 ProfileHelper::Get()->GetUserByProfile(profile); |
| 163 if (!user) | 165 if (!user) |
| 164 return false; | 166 return false; |
| 165 return user == user_manager::UserManager::Get()->GetPrimaryUser(); | 167 return user == user_manager::UserManager::Get()->GetPrimaryUser(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { | 170 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { |
| 169 // Initialize Chrome OS preferences like touch pad sensitivity. For the | 171 // Initialize Chrome OS preferences like touch pad sensitivity. For the |
| 170 // preferences to work in the guest mode, the initialization has to be | 172 // preferences to work in the guest mode, the initialization has to be |
| 171 // done after |profile| is switched to the incognito profile (which | 173 // done after |profile| is switched to the incognito profile (which |
| 172 // is actually GuestSessionProfile in the guest mode). See the | 174 // is actually GuestSessionProfile in the guest mode). See the |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 profile = ProfileManager::GetActiveUserProfile(); | 255 profile = ProfileManager::GetActiveUserProfile(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance | 258 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance |
| 257 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. | 259 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. |
| 258 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest()) | 260 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest()) |
| 259 profile = profile->GetOffTheRecordProfile(); | 261 profile = profile->GetOffTheRecordProfile(); |
| 260 return profile; | 262 return profile; |
| 261 } | 263 } |
| 262 | 264 |
| 263 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) { | 265 const user_manager::User* ProfileHelper::GetUserByProfile( |
| 266 const Profile* profile) const { |
| 264 // This map is non-empty only in tests. | 267 // This map is non-empty only in tests. |
| 265 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { | 268 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) { |
| 266 if (always_return_primary_user_for_testing) | 269 if (always_return_primary_user_for_testing) |
| 267 return const_cast<user_manager::User*>( | 270 return user_manager::UserManager::Get()->GetPrimaryUser(); |
| 268 user_manager::UserManager::Get()->GetPrimaryUser()); | |
| 269 | 271 |
| 270 const std::string& user_name = profile->GetProfileUserName(); | 272 const std::string& user_name = profile->GetProfileUserName(); |
| 271 for (user_manager::UserList::const_iterator it = | 273 for (user_manager::UserList::const_iterator it = |
| 272 user_list_for_testing_.begin(); | 274 user_list_for_testing_.begin(); |
| 273 it != user_list_for_testing_.end(); | 275 it != user_list_for_testing_.end(); |
| 274 ++it) { | 276 ++it) { |
| 275 if ((*it)->email() == user_name) | 277 if ((*it)->email() == user_name) |
| 276 return *it; | 278 return *it; |
| 277 } | 279 } |
| 278 | 280 |
| 279 // In case of test setup we should always default to primary user. | 281 // In case of test setup we should always default to primary user. |
| 280 return const_cast<user_manager::User*>( | 282 return user_manager::UserManager::Get()->GetPrimaryUser(); |
| 281 user_manager::UserManager::Get()->GetPrimaryUser()); | |
| 282 } | 283 } |
| 283 | 284 |
| 284 DCHECK(!content::BrowserThread::IsThreadInitialized( | 285 DCHECK(!content::BrowserThread::IsThreadInitialized( |
| 285 content::BrowserThread::UI) || | 286 content::BrowserThread::UI) || |
| 286 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 287 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 287 if (ProfileHelper::IsSigninProfile(profile)) | 288 if (ProfileHelper::IsSigninProfile(profile)) |
| 288 return NULL; | 289 return NULL; |
| 289 | 290 |
| 290 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 291 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 291 | 292 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 307 users.begin(), users.end(), UsernameHashMatcher(username_hash)); | 308 users.begin(), users.end(), UsernameHashMatcher(username_hash)); |
| 308 if (pos != users.end()) | 309 if (pos != users.end()) |
| 309 return *pos; | 310 return *pos; |
| 310 | 311 |
| 311 // Many tests do not have their users registered with UserManager and | 312 // Many tests do not have their users registered with UserManager and |
| 312 // runs here. If |active_user_| matches |profile|, returns it. | 313 // runs here. If |active_user_| matches |profile|, returns it. |
| 313 const user_manager::User* active_user = user_manager->GetActiveUser(); | 314 const user_manager::User* active_user = user_manager->GetActiveUser(); |
| 314 return active_user && | 315 return active_user && |
| 315 ProfileHelper::GetProfilePathByUserIdHash( | 316 ProfileHelper::GetProfilePathByUserIdHash( |
| 316 active_user->username_hash()) == profile->GetPath() | 317 active_user->username_hash()) == profile->GetPath() |
| 317 ? const_cast<user_manager::User*>(active_user) | 318 ? active_user |
| 318 : NULL; | 319 : NULL; |
| 319 } | 320 } |
| 320 | 321 |
| 322 user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) const { |
| 323 return const_cast<user_manager::User*>( |
| 324 GetUserByProfile(static_cast<const Profile*>(profile))); |
| 325 } |
| 326 |
| 321 //////////////////////////////////////////////////////////////////////////////// | 327 //////////////////////////////////////////////////////////////////////////////// |
| 322 // ProfileHelper, BrowsingDataRemover::Observer implementation: | 328 // ProfileHelper, BrowsingDataRemover::Observer implementation: |
| 323 | 329 |
| 324 void ProfileHelper::OnBrowsingDataRemoverDone() { | 330 void ProfileHelper::OnBrowsingDataRemoverDone() { |
| 325 signin_profile_clear_requested_ = false; | 331 signin_profile_clear_requested_ = false; |
| 326 for (size_t i = 0; i < on_clear_callbacks_.size(); ++i) { | 332 for (size_t i = 0; i < on_clear_callbacks_.size(); ++i) { |
| 327 if (!on_clear_callbacks_[i].is_null()) | 333 if (!on_clear_callbacks_[i].is_null()) |
| 328 on_clear_callbacks_[i].Run(); | 334 on_clear_callbacks_[i].Run(); |
| 329 } | 335 } |
| 330 on_clear_callbacks_.clear(); | 336 on_clear_callbacks_.clear(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 user_to_profile_for_testing_[user] = profile; | 382 user_to_profile_for_testing_[user] = profile; |
| 377 } | 383 } |
| 378 | 384 |
| 379 // static | 385 // static |
| 380 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( | 386 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 381 const std::string& user_id) { | 387 const std::string& user_id) { |
| 382 return user_id + kUserIdHashSuffix; | 388 return user_id + kUserIdHashSuffix; |
| 383 } | 389 } |
| 384 | 390 |
| 385 } // namespace chromeos | 391 } // namespace chromeos |
| OLD | NEW |