blob: cb7f6e2f444fa587de2df77f9f6284778b49a179 [file] [log] [blame]
[email protected]afde2622013-04-18 05:04:291// 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
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/profiles/profile_helper.h"
6
ginkage74a79da42015-03-23 10:36:557#include "base/barrier_closure.h"
[email protected]f8622a42013-06-07 14:12:368#include "base/callback.h"
[email protected]7cad6b0d2013-04-25 20:29:329#include "base/command_line.h"
[email protected]afde2622013-04-18 05:04:2910#include "chrome/browser/browser_process.h"
[email protected]4c335a292013-05-08 21:41:0111#include "chrome/browser/browsing_data/browsing_data_helper.h"
dzhioevb1875912015-04-02 12:13:2512#include "chrome/browser/chromeos/login/helper.h"
[email protected]83d82d42014-05-16 02:04:4213#include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
[email protected]afde2622013-04-18 05:04:2914#include "chrome/browser/profiles/profile.h"
[email protected]afde2622013-04-18 05:04:2915#include "chrome/browser/profiles/profile_manager.h"
[email protected]f9357a442014-05-15 18:44:0716#include "chrome/browser/profiles/profiles_state.h"
[email protected]afde2622013-04-18 05:04:2917#include "chrome/common/chrome_constants.h"
[email protected]7cad6b0d2013-04-25 20:29:3218#include "chrome/common/chrome_switches.h"
[email protected]82b1ec872013-12-06 17:07:1519#include "chromeos/chromeos_switches.h"
fsamuel8dfa19a2015-05-05 01:00:3920#include "components/guest_view/browser/guest_view_manager.h"
[email protected]2fda9972014-07-23 14:51:5921#include "components/user_manager/user.h"
[email protected]4d390782014-08-15 09:22:5822#include "components/user_manager/user_manager.h"
[email protected]052e3ac2014-06-30 14:22:4723#include "content/public/browser/browser_thread.h"
ginkage74a79da42015-03-23 10:36:5524#include "content/public/browser/storage_partition.h"
25#include "content/public/browser/web_contents.h"
ginkage74a79da42015-03-23 10:36:5526#include "extensions/browser/guest_view/web_view/web_view_guest.h"
[email protected]afde2622013-04-18 05:04:2927
28namespace chromeos {
29
[email protected]09f34ec72013-06-24 14:49:5530namespace {
31
dzhioev0298d722014-08-26 13:18:5232// As defined in /chromeos/dbus/cryptohome_client.cc.
33static const char kUserIdHashSuffix[] = "-hash";
34
[email protected]64146ec2014-03-19 21:52:2535bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) {
36 // Do not add profile dir prefix for legacy profile dir and test
37 // user profile. The reason of not adding prefix for test user profile
38 // is to keep the promise that TestingProfile::kTestUserProfileDir and
39 // chrome::kTestUserProfileDir are always in sync. Otherwise,
40 // TestingProfile::kTestUserProfileDir needs to be dynamically calculated
41 // based on whether multi profile is enabled or not.
42 return user_id_hash != chrome::kLegacyProfileDir &&
43 user_id_hash != chrome::kTestUserProfileDir;
44}
45
[email protected]052e3ac2014-06-30 14:22:4746class UsernameHashMatcher {
47 public:
48 explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {}
[email protected]2fda9972014-07-23 14:51:5949 bool operator()(const user_manager::User* user) const {
[email protected]052e3ac2014-06-30 14:22:4750 return user->username_hash() == username_hash;
51 }
52
53 private:
54 const std::string& username_hash;
55};
56
[email protected]09f34ec72013-06-24 14:49:5557} // anonymous namespace
58
[email protected]052e3ac2014-06-30 14:22:4759// static
60bool ProfileHelper::enable_profile_to_user_testing = false;
61bool ProfileHelper::always_return_primary_user_for_testing = false;
62
[email protected]7cad6b0d2013-04-25 20:29:3263////////////////////////////////////////////////////////////////////////////////
64// ProfileHelper, public
65
[email protected]4c335a292013-05-08 21:41:0166ProfileHelper::ProfileHelper()
dzhioevb1875912015-04-02 12:13:2567 : browsing_data_remover_(nullptr), weak_factory_(this) {
[email protected]7cad6b0d2013-04-25 20:29:3268}
69
70ProfileHelper::~ProfileHelper() {
[email protected]f8622a42013-06-07 14:12:3671 // Checking whether UserManager is initialized covers case
72 // when ScopedTestUserManager is used.
[email protected]4d390782014-08-15 09:22:5873 if (user_manager::UserManager::IsInitialized())
74 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
dzhioevb1875912015-04-02 12:13:2575
76 if (browsing_data_remover_) {
77 browsing_data_remover_->RemoveObserver(this);
78 // BrowsingDataRemover deletes itself.
79 browsing_data_remover_ = nullptr;
80 }
[email protected]7cad6b0d2013-04-25 20:29:3281}
82
83// static
[email protected]052e3ac2014-06-30 14:22:4784ProfileHelper* ProfileHelper::Get() {
85 return g_browser_process->platform_part()->profile_helper();
86}
87
88// static
[email protected]7cad6b0d2013-04-25 20:29:3289Profile* ProfileHelper::GetProfileByUserIdHash(
90 const std::string& user_id_hash) {
91 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]847522f2013-05-10 09:32:4292 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
[email protected]7cad6b0d2013-04-25 20:29:3293}
94
[email protected]afde2622013-04-18 05:04:2995// static
[email protected]d02f6c692013-05-23 13:58:1396base::FilePath ProfileHelper::GetProfilePathByUserIdHash(
97 const std::string& user_id_hash) {
[email protected]f9357a442014-05-15 18:44:0798 // Fails for KioskTest.InstallAndLaunchApp test - crbug.com/238985
99 // Will probably fail for Guest session / restart after a crash -
100 // crbug.com/238998
101 // TODO(nkostylev): Remove this check once these bugs are fixed.
102 DCHECK(!user_id_hash.empty());
[email protected]d02f6c692013-05-23 13:58:13103 ProfileManager* profile_manager = g_browser_process->profile_manager();
104 base::FilePath profile_path = profile_manager->user_data_dir();
[email protected]64146ec2014-03-19 21:52:25105
106 return profile_path.Append(GetUserProfileDir(user_id_hash));
[email protected]d02f6c692013-05-23 13:58:13107}
108
109// static
[email protected]c65b9c282014-04-04 16:37:17110base::FilePath ProfileHelper::GetSigninProfileDir() {
111 ProfileManager* profile_manager = g_browser_process->profile_manager();
112 base::FilePath user_data_dir = profile_manager->user_data_dir();
113 return user_data_dir.AppendASCII(chrome::kInitialProfile);
114}
115
116// static
[email protected]afde2622013-04-18 05:04:29117Profile* ProfileHelper::GetSigninProfile() {
118 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]09f34ec72013-06-24 14:49:55119 return profile_manager->GetProfile(GetSigninProfileDir())->
[email protected]afde2622013-04-18 05:04:29120 GetOffTheRecordProfile();
121}
122
123// static
isherman91ffd8b2015-02-19 08:51:32124std::string ProfileHelper::GetUserIdHashFromProfile(const Profile* profile) {
[email protected]847522f2013-05-10 09:32:42125 if (!profile)
126 return std::string();
127
[email protected]847522f2013-05-10 09:32:42128 std::string profile_dir = profile->GetPath().BaseName().value();
[email protected]64146ec2014-03-19 21:52:25129
130 // Don't strip prefix if the dir is not supposed to be prefixed.
131 if (!ShouldAddProfileDirPrefix(profile_dir))
132 return profile_dir;
133
134 // Check that profile directory starts with the correct prefix.
[email protected]68e31692013-05-20 13:08:27135 std::string prefix(chrome::kProfileDirPrefix);
[email protected]847522f2013-05-10 09:32:42136 if (profile_dir.find(prefix) != 0) {
[email protected]0301c5f2014-01-23 04:32:15137 // This happens when creating a TestingProfile in browser tests.
[email protected]847522f2013-05-10 09:32:42138 return std::string();
139 }
140
141 return profile_dir.substr(prefix.length(),
142 profile_dir.length() - prefix.length());
143}
144
145// static
[email protected]82b1ec872013-12-06 17:07:15146base::FilePath ProfileHelper::GetUserProfileDir(
147 const std::string& user_id_hash) {
dzhioev0298d722014-08-26 13:18:52148 CHECK(!user_id_hash.empty());
[email protected]64146ec2014-03-19 21:52:25149 return ShouldAddProfileDirPrefix(user_id_hash)
150 ? base::FilePath(chrome::kProfileDirPrefix + user_id_hash)
151 : base::FilePath(user_id_hash);
[email protected]82b1ec872013-12-06 17:07:15152}
153
154// static
isherman91ffd8b2015-02-19 08:51:32155bool ProfileHelper::IsSigninProfile(const Profile* profile) {
ginkage9d3e6462015-02-26 12:18:05156 return profile &&
157 profile->GetPath().BaseName().value() == chrome::kInitialProfile;
[email protected]42c0d5ed2013-04-30 17:04:45158}
159
[email protected]cb9934802014-01-30 01:45:10160// static
161bool ProfileHelper::IsOwnerProfile(Profile* profile) {
[email protected]24c22df2014-02-10 15:36:52162 if (!profile)
163 return false;
isherman91ffd8b2015-02-19 08:51:32164 const user_manager::User* user =
165 ProfileHelper::Get()->GetUserByProfile(profile);
[email protected]24c22df2014-02-10 15:36:52166 if (!user)
167 return false;
[email protected]052e3ac2014-06-30 14:22:47168
[email protected]4d390782014-08-15 09:22:58169 return user->email() == user_manager::UserManager::Get()->GetOwnerEmail();
[email protected]cb9934802014-01-30 01:45:10170}
171
[email protected]64268342014-08-12 17:18:22172// static
isherman91ffd8b2015-02-19 08:51:32173bool ProfileHelper::IsPrimaryProfile(const Profile* profile) {
[email protected]6465e0f2014-08-07 07:57:58174 if (!profile)
175 return false;
isherman91ffd8b2015-02-19 08:51:32176 const user_manager::User* user =
177 ProfileHelper::Get()->GetUserByProfile(profile);
[email protected]6465e0f2014-08-07 07:57:58178 if (!user)
179 return false;
[email protected]4d390782014-08-15 09:22:58180 return user == user_manager::UserManager::Get()->GetPrimaryUser();
[email protected]6465e0f2014-08-07 07:57:58181}
182
[email protected]afde2622013-04-18 05:04:29183void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
184 // Initialize Chrome OS preferences like touch pad sensitivity. For the
185 // preferences to work in the guest mode, the initialization has to be
186 // done after |profile| is switched to the incognito profile (which
187 // is actually GuestSessionProfile in the guest mode). See the
188 // GetOffTheRecordProfile() call above.
189 profile->InitChromeOSPreferences();
190
[email protected]56f10afd2013-09-12 02:01:16191 // Add observer so we can see when the first profile's session restore is
192 // completed. After that, we won't need the default profile anymore.
193 if (!IsSigninProfile(profile) &&
merkulovac3ae44d2014-11-17 09:35:07194 user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount() &&
[email protected]4d390782014-08-15 09:22:58195 !user_manager::UserManager::Get()->IsLoggedInAsStub()) {
[email protected]56f10afd2013-09-12 02:01:16196 chromeos::OAuth2LoginManager* login_manager =
197 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
198 profile);
199 if (login_manager)
200 login_manager->AddObserver(this);
[email protected]afde2622013-04-18 05:04:29201 }
202}
203
[email protected]847522f2013-05-10 09:32:42204base::FilePath ProfileHelper::GetActiveUserProfileDir() {
[email protected]82b1ec872013-12-06 17:07:15205 return ProfileHelper::GetUserProfileDir(active_user_id_hash_);
[email protected]847522f2013-05-10 09:32:42206}
207
[email protected]7cad6b0d2013-04-25 20:29:32208void ProfileHelper::Initialize() {
[email protected]4d390782014-08-15 09:22:58209 user_manager::UserManager::Get()->AddSessionStateObserver(this);
[email protected]7cad6b0d2013-04-25 20:29:32210}
211
dzhioevb1875912015-04-02 12:13:25212void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
213 on_clear_callbacks_.push_back(on_clear_callback);
214
215 // Profile is already clearing.
216 if (on_clear_callbacks_.size() > 1)
[email protected]4c335a292013-05-08 21:41:01217 return;
dzhioevb1875912015-04-02 12:13:25218
219 on_clear_profile_stage_finished_ =
220 base::BarrierClosure(2, base::Bind(&ProfileHelper::OnSigninProfileCleared,
221 weak_factory_.GetWeakPtr()));
222
[email protected]09f34ec72013-06-24 14:49:55223 ProfileManager* profile_manager = g_browser_process->profile_manager();
224 // Check if signin profile was loaded.
xiyuan353d7ce2015-04-14 20:08:30225 if (profile_manager->GetProfileByPath(GetSigninProfileDir())) {
dzhioevb1875912015-04-02 12:13:25226 LOG_ASSERT(!browsing_data_remover_);
227 browsing_data_remover_ =
xiyuan353d7ce2015-04-14 20:08:30228 BrowsingDataRemover::CreateForUnboundedRange(GetSigninProfile());
dzhioevb1875912015-04-02 12:13:25229 browsing_data_remover_->AddObserver(this);
230 browsing_data_remover_->Remove(BrowsingDataRemover::REMOVE_SITE_DATA,
231 BrowsingDataHelper::ALL);
232 } else {
233 on_clear_profile_stage_finished_.Run();
[email protected]09f34ec72013-06-24 14:49:55234 }
dzhioevb1875912015-04-02 12:13:25235
236 if (content::StoragePartition* partition = login::GetSigninPartition()) {
237 partition->ClearData(
238 content::StoragePartition::REMOVE_DATA_MASK_ALL,
239 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, GURL(),
240 content::StoragePartition::OriginMatcherFunction(), base::Time(),
241 base::Time::Now(), on_clear_profile_stage_finished_);
242 } else {
243 on_clear_profile_stage_finished_.Run();
244 }
[email protected]4c335a292013-05-08 21:41:01245}
246
[email protected]2fda9972014-07-23 14:51:59247Profile* ProfileHelper::GetProfileByUser(const user_manager::User* user) {
[email protected]052e3ac2014-06-30 14:22:47248 // This map is non-empty only in tests.
249 if (!user_to_profile_for_testing_.empty()) {
[email protected]2fda9972014-07-23 14:51:59250 std::map<const user_manager::User*, Profile*>::const_iterator it =
[email protected]052e3ac2014-06-30 14:22:47251 user_to_profile_for_testing_.find(user);
252 return it == user_to_profile_for_testing_.end() ? NULL : it->second;
253 }
254
[email protected]64268342014-08-12 17:18:22255 if (!user->is_profile_created())
256 return NULL;
257 Profile* profile =
258 ProfileHelper::GetProfileByUserIdHash(user->username_hash());
259
260 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
261 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
[email protected]4d390782014-08-15 09:22:58262 if (user_manager::UserManager::Get()->IsLoggedInAsGuest())
[email protected]64268342014-08-12 17:18:22263 profile = profile->GetOffTheRecordProfile();
264
265 return profile;
266}
267
268Profile* ProfileHelper::GetProfileByUserUnsafe(const user_manager::User* user) {
269 // This map is non-empty only in tests.
270 if (!user_to_profile_for_testing_.empty()) {
271 std::map<const user_manager::User*, Profile*>::const_iterator it =
272 user_to_profile_for_testing_.find(user);
273 return it == user_to_profile_for_testing_.end() ? NULL : it->second;
274 }
275
[email protected]052e3ac2014-06-30 14:22:47276 Profile* profile = NULL;
[email protected]64268342014-08-12 17:18:22277 if (user->is_profile_created()) {
[email protected]052e3ac2014-06-30 14:22:47278 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
[email protected]64268342014-08-12 17:18:22279 } else {
280 LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when "
281 "|user|'s profile is not created. It probably means that "
282 "something is wrong with a calling code. Please report in "
nkostylev5df7e992014-09-26 09:03:47283 "http://crbug.com/361528 if you see this message. user_id: "
284 << user->email();
[email protected]052e3ac2014-06-30 14:22:47285 profile = ProfileManager::GetActiveUserProfile();
[email protected]64268342014-08-12 17:18:22286 }
[email protected]052e3ac2014-06-30 14:22:47287
288 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
289 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
[email protected]4d390782014-08-15 09:22:58290 if (profile && user_manager::UserManager::Get()->IsLoggedInAsGuest())
[email protected]052e3ac2014-06-30 14:22:47291 profile = profile->GetOffTheRecordProfile();
292 return profile;
293}
294
isherman91ffd8b2015-02-19 08:51:32295const user_manager::User* ProfileHelper::GetUserByProfile(
296 const Profile* profile) const {
[email protected]052e3ac2014-06-30 14:22:47297 // This map is non-empty only in tests.
298 if (enable_profile_to_user_testing || !user_list_for_testing_.empty()) {
299 if (always_return_primary_user_for_testing)
isherman91ffd8b2015-02-19 08:51:32300 return user_manager::UserManager::Get()->GetPrimaryUser();
[email protected]052e3ac2014-06-30 14:22:47301
nomsd9d36d72015-02-10 04:48:26302 const std::string& user_name = profile->GetProfileUserName();
[email protected]2fda9972014-07-23 14:51:59303 for (user_manager::UserList::const_iterator it =
304 user_list_for_testing_.begin();
[email protected]052e3ac2014-06-30 14:22:47305 it != user_list_for_testing_.end();
306 ++it) {
307 if ((*it)->email() == user_name)
308 return *it;
309 }
310
311 // In case of test setup we should always default to primary user.
isherman91ffd8b2015-02-19 08:51:32312 return user_manager::UserManager::Get()->GetPrimaryUser();
[email protected]052e3ac2014-06-30 14:22:47313 }
314
dzhioev0298d722014-08-26 13:18:52315 DCHECK(!content::BrowserThread::IsThreadInitialized(
316 content::BrowserThread::UI) ||
317 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]052e3ac2014-06-30 14:22:47318 if (ProfileHelper::IsSigninProfile(profile))
319 return NULL;
320
[email protected]4d390782014-08-15 09:22:58321 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
[email protected]052e3ac2014-06-30 14:22:47322
323 // Special case for non-CrOS tests that do create several profiles
324 // and don't really care about mapping to the real user.
325 // Without multi-profiles on Chrome OS such tests always got active_user_.
326 // Now these tests will specify special flag to continue working.
327 // In future those tests can get a proper CrOS configuration i.e. register
328 // and login several users if they want to work with an additional profile.
avi3ef9ec9e2014-12-22 22:50:17329 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]052e3ac2014-06-30 14:22:47330 switches::kIgnoreUserProfileMappingForTests)) {
331 return user_manager->GetActiveUser();
332 }
333
334 const std::string username_hash =
335 ProfileHelper::GetUserIdHashFromProfile(profile);
[email protected]2fda9972014-07-23 14:51:59336 const user_manager::UserList& users = user_manager->GetUsers();
337 const user_manager::UserList::const_iterator pos = std::find_if(
[email protected]052e3ac2014-06-30 14:22:47338 users.begin(), users.end(), UsernameHashMatcher(username_hash));
339 if (pos != users.end())
340 return *pos;
341
342 // Many tests do not have their users registered with UserManager and
343 // runs here. If |active_user_| matches |profile|, returns it.
[email protected]2fda9972014-07-23 14:51:59344 const user_manager::User* active_user = user_manager->GetActiveUser();
[email protected]052e3ac2014-06-30 14:22:47345 return active_user &&
346 ProfileHelper::GetProfilePathByUserIdHash(
347 active_user->username_hash()) == profile->GetPath()
isherman91ffd8b2015-02-19 08:51:32348 ? active_user
[email protected]052e3ac2014-06-30 14:22:47349 : NULL;
350}
351
isherman91ffd8b2015-02-19 08:51:32352user_manager::User* ProfileHelper::GetUserByProfile(Profile* profile) const {
353 return const_cast<user_manager::User*>(
354 GetUserByProfile(static_cast<const Profile*>(profile)));
355}
356
dzhioevb1875912015-04-02 12:13:25357void ProfileHelper::OnSigninProfileCleared() {
358 std::vector<base::Closure> callbacks;
359 callbacks.swap(on_clear_callbacks_);
360 for (const base::Closure& callback : callbacks) {
361 if (!callback.is_null())
362 callback.Run();
363 }
364}
365
[email protected]4c335a292013-05-08 21:41:01366////////////////////////////////////////////////////////////////////////////////
367// ProfileHelper, BrowsingDataRemover::Observer implementation:
368
369void ProfileHelper::OnBrowsingDataRemoverDone() {
dzhioevb1875912015-04-02 12:13:25370 LOG_ASSERT(browsing_data_remover_);
371 browsing_data_remover_->RemoveObserver(this);
372 // BrowsingDataRemover deletes itself.
373 browsing_data_remover_ = nullptr;
374
375 on_clear_profile_stage_finished_.Run();
[email protected]4c335a292013-05-08 21:41:01376}
377
[email protected]7cad6b0d2013-04-25 20:29:32378////////////////////////////////////////////////////////////////////////////////
[email protected]56f10afd2013-09-12 02:01:16379// ProfileHelper, OAuth2LoginManager::Observer implementation:
[email protected]f8622a42013-06-07 14:12:36380
[email protected]56f10afd2013-09-12 02:01:16381void ProfileHelper::OnSessionRestoreStateChanged(
382 Profile* user_profile,
383 OAuth2LoginManager::SessionRestoreState state) {
[email protected]8321c5f2013-10-11 11:26:18384 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE ||
385 state == OAuth2LoginManager::SESSION_RESTORE_FAILED ||
386 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) {
[email protected]56f10afd2013-09-12 02:01:16387 chromeos::OAuth2LoginManager* login_manager =
[email protected]8321c5f2013-10-11 11:26:18388 chromeos::OAuth2LoginManagerFactory::GetInstance()->
389 GetForProfile(user_profile);
[email protected]56f10afd2013-09-12 02:01:16390 login_manager->RemoveObserver(this);
dzhioevb1875912015-04-02 12:13:25391 ClearSigninProfile(base::Closure());
[email protected]56f10afd2013-09-12 02:01:16392 }
[email protected]f8622a42013-06-07 14:12:36393}
394
395////////////////////////////////////////////////////////////////////////////////
[email protected]7cad6b0d2013-04-25 20:29:32396// ProfileHelper, UserManager::UserSessionStateObserver implementation:
397
398void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
399 active_user_id_hash_ = hash;
[email protected]7cad6b0d2013-04-25 20:29:32400}
401
[email protected]2fda9972014-07-23 14:51:59402void ProfileHelper::SetProfileToUserMappingForTesting(
403 user_manager::User* user) {
[email protected]052e3ac2014-06-30 14:22:47404 user_list_for_testing_.push_back(user);
405}
406
407// static
408void ProfileHelper::SetProfileToUserForTestingEnabled(bool enabled) {
409 enable_profile_to_user_testing = enabled;
410}
411
412// static
413void ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(bool value) {
414 always_return_primary_user_for_testing = true;
415 ProfileHelper::SetProfileToUserForTestingEnabled(true);
416}
417
[email protected]2fda9972014-07-23 14:51:59418void ProfileHelper::SetUserToProfileMappingForTesting(
419 const user_manager::User* user,
420 Profile* profile) {
[email protected]052e3ac2014-06-30 14:22:47421 user_to_profile_for_testing_[user] = profile;
422}
423
dzhioev0298d722014-08-26 13:18:52424// static
425std::string ProfileHelper::GetUserIdHashByUserIdForTesting(
426 const std::string& user_id) {
427 return user_id + kUserIdHashSuffix;
428}
429
[email protected]afde2622013-04-18 05:04:29430} // namespace chromeos