| 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/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 35 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 36 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
| 37 | 37 |
| 38 namespace chromeos { | 38 namespace chromeos { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // As defined in /chromeos/dbus/cryptohome_client.cc. | 42 // As defined in /chromeos/dbus/cryptohome_client.cc. |
| 43 static const char kUserIdHashSuffix[] = "-hash"; | 43 static const char kUserIdHashSuffix[] = "-hash"; |
| 44 | 44 |
| 45 // The name for the lock screen app profile. |
| 46 static const char kLockScreenAppProfileName[] = "LockScreenAppsProfile"; |
| 47 |
| 45 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { | 48 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { |
| 46 // Do not add profile dir prefix for legacy profile dir and test | 49 // Do not add profile dir prefix for legacy profile dir and test |
| 47 // user profile. The reason of not adding prefix for test user profile | 50 // user profile. The reason of not adding prefix for test user profile |
| 48 // is to keep the promise that TestingProfile::kTestUserProfileDir and | 51 // is to keep the promise that TestingProfile::kTestUserProfileDir and |
| 49 // chrome::kTestUserProfileDir are always in sync. Otherwise, | 52 // chrome::kTestUserProfileDir are always in sync. Otherwise, |
| 50 // TestingProfile::kTestUserProfileDir needs to be dynamically calculated | 53 // TestingProfile::kTestUserProfileDir needs to be dynamically calculated |
| 51 // based on whether multi profile is enabled or not. | 54 // based on whether multi profile is enabled or not. |
| 52 return user_id_hash != chrome::kLegacyProfileDir && | 55 return user_id_hash != chrome::kLegacyProfileDir && |
| 53 user_id_hash != chrome::kTestUserProfileDir; | 56 user_id_hash != chrome::kTestUserProfileDir; |
| 54 } | 57 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 : base::FilePath(user_id_hash); | 167 : base::FilePath(user_id_hash); |
| 165 } | 168 } |
| 166 | 169 |
| 167 // static | 170 // static |
| 168 bool ProfileHelper::IsSigninProfile(const Profile* profile) { | 171 bool ProfileHelper::IsSigninProfile(const Profile* profile) { |
| 169 return profile && | 172 return profile && |
| 170 profile->GetPath().BaseName().value() == chrome::kInitialProfile; | 173 profile->GetPath().BaseName().value() == chrome::kInitialProfile; |
| 171 } | 174 } |
| 172 | 175 |
| 173 // static | 176 // static |
| 177 bool ProfileHelper::IsLockScreenAppProfile(const Profile* profile) { |
| 178 return profile && |
| 179 profile->GetPath().BaseName().value() == kLockScreenAppProfileName; |
| 180 } |
| 181 |
| 182 // static |
| 183 base::FilePath ProfileHelper::GetLockScreenAppProfilePath() { |
| 184 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 185 return profile_manager->user_data_dir().AppendASCII( |
| 186 kLockScreenAppProfileName); |
| 187 } |
| 188 |
| 189 // static |
| 190 std::string ProfileHelper::GetLockScreenAppProfileName() { |
| 191 return kLockScreenAppProfileName; |
| 192 } |
| 193 |
| 194 // static |
| 174 bool ProfileHelper::IsOwnerProfile(const Profile* profile) { | 195 bool ProfileHelper::IsOwnerProfile(const Profile* profile) { |
| 175 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 196 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 176 chromeos::switches::kStubCrosSettings)) { | 197 chromeos::switches::kStubCrosSettings)) { |
| 177 return true; | 198 return true; |
| 178 } | 199 } |
| 179 | 200 |
| 180 if (!profile) | 201 if (!profile) |
| 181 return false; | 202 return false; |
| 182 const user_manager::User* user = | 203 const user_manager::User* user = |
| 183 ProfileHelper::Get()->GetUserByProfile(profile); | 204 ProfileHelper::Get()->GetUserByProfile(profile); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return *it; | 372 return *it; |
| 352 } | 373 } |
| 353 | 374 |
| 354 // In case of test setup we should always default to primary user. | 375 // In case of test setup we should always default to primary user. |
| 355 return user_manager::UserManager::Get()->GetPrimaryUser(); | 376 return user_manager::UserManager::Get()->GetPrimaryUser(); |
| 356 } | 377 } |
| 357 | 378 |
| 358 DCHECK(!content::BrowserThread::IsThreadInitialized( | 379 DCHECK(!content::BrowserThread::IsThreadInitialized( |
| 359 content::BrowserThread::UI) || | 380 content::BrowserThread::UI) || |
| 360 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 381 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 361 if (ProfileHelper::IsSigninProfile(profile)) | 382 if (ProfileHelper::IsSigninProfile(profile) || |
| 362 return NULL; | 383 ProfileHelper::IsLockScreenAppProfile(profile)) { |
| 384 return nullptr; |
| 385 } |
| 363 | 386 |
| 364 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 387 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 365 | 388 |
| 366 // Special case for non-CrOS tests that do create several profiles | 389 // Special case for non-CrOS tests that do create several profiles |
| 367 // and don't really care about mapping to the real user. | 390 // and don't really care about mapping to the real user. |
| 368 // Without multi-profiles on Chrome OS such tests always got active_user_. | 391 // Without multi-profiles on Chrome OS such tests always got active_user_. |
| 369 // Now these tests will specify special flag to continue working. | 392 // Now these tests will specify special flag to continue working. |
| 370 // In future those tests can get a proper CrOS configuration i.e. register | 393 // In future those tests can get a proper CrOS configuration i.e. register |
| 371 // and login several users if they want to work with an additional profile. | 394 // and login several users if they want to work with an additional profile. |
| 372 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 395 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 DownloadPrefs::FromBrowserContext(profile)->DownloadPath()); | 526 DownloadPrefs::FromBrowserContext(profile)->DownloadPath()); |
| 504 // Let extension system handle extension files. | 527 // Let extension system handle extension files. |
| 505 excludes.push_back(base::FilePath(extensions::kInstallDirectoryName)); | 528 excludes.push_back(base::FilePath(extensions::kInstallDirectoryName)); |
| 506 // Do not flush Drive cache. | 529 // Do not flush Drive cache. |
| 507 excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname)); | 530 excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname)); |
| 508 | 531 |
| 509 profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure()); | 532 profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure()); |
| 510 } | 533 } |
| 511 | 534 |
| 512 } // namespace chromeos | 535 } // namespace chromeos |
| OLD | NEW |