| 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 "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 12 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 12 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 13 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 14 #include "chrome/browser/chromeos/base/file_flusher.h" |
| 14 #include "chrome/browser/chromeos/login/helper.h" | 15 #include "chrome/browser/chromeos/login/helper.h" |
| 15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 16 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
| 17 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 18 #include "chrome/browser/download/download_prefs.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/profiles/profiles_state.h" | 21 #include "chrome/browser/profiles/profiles_state.h" |
| 19 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chromeos/chromeos_constants.h" |
| 21 #include "chromeos/chromeos_switches.h" | 25 #include "chromeos/chromeos_switches.h" |
| 22 #include "components/guest_view/browser/guest_view_manager.h" | 26 #include "components/guest_view/browser/guest_view_manager.h" |
| 23 #include "components/user_manager/user.h" | 27 #include "components/user_manager/user.h" |
| 24 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 28 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 32 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 33 #include "extensions/common/constants.h" |
| 29 | 34 |
| 30 namespace chromeos { | 35 namespace chromeos { |
| 31 | 36 |
| 32 namespace { | 37 namespace { |
| 33 | 38 |
| 34 // As defined in /chromeos/dbus/cryptohome_client.cc. | 39 // As defined in /chromeos/dbus/cryptohome_client.cc. |
| 35 static const char kUserIdHashSuffix[] = "-hash"; | 40 static const char kUserIdHashSuffix[] = "-hash"; |
| 36 | 41 |
| 37 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { | 42 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { |
| 38 // Do not add profile dir prefix for legacy profile dir and test | 43 // Do not add profile dir prefix for legacy profile dir and test |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 : base::FilePath(user_id_hash); | 155 : base::FilePath(user_id_hash); |
| 151 } | 156 } |
| 152 | 157 |
| 153 // static | 158 // static |
| 154 bool ProfileHelper::IsSigninProfile(const Profile* profile) { | 159 bool ProfileHelper::IsSigninProfile(const Profile* profile) { |
| 155 return profile && | 160 return profile && |
| 156 profile->GetPath().BaseName().value() == chrome::kInitialProfile; | 161 profile->GetPath().BaseName().value() == chrome::kInitialProfile; |
| 157 } | 162 } |
| 158 | 163 |
| 159 // static | 164 // static |
| 160 bool ProfileHelper::IsOwnerProfile(Profile* profile) { | 165 bool ProfileHelper::IsOwnerProfile(const Profile* profile) { |
| 161 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 166 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 162 chromeos::switches::kStubCrosSettings)) { | 167 chromeos::switches::kStubCrosSettings)) { |
| 163 return true; | 168 return true; |
| 164 } | 169 } |
| 165 | 170 |
| 166 if (!profile) | 171 if (!profile) |
| 167 return false; | 172 return false; |
| 168 const user_manager::User* user = | 173 const user_manager::User* user = |
| 169 ProfileHelper::Get()->GetUserByProfile(profile); | 174 ProfileHelper::Get()->GetUserByProfile(profile); |
| 170 if (!user) | 175 if (!user) |
| 171 return false; | 176 return false; |
| 172 return user->GetAccountId() == | 177 return user->GetAccountId() == |
| 173 user_manager::UserManager::Get()->GetOwnerAccountId(); | 178 user_manager::UserManager::Get()->GetOwnerAccountId(); |
| 174 } | 179 } |
| 175 | 180 |
| 176 // static | 181 // static |
| 177 bool ProfileHelper::IsPrimaryProfile(const Profile* profile) { | 182 bool ProfileHelper::IsPrimaryProfile(const Profile* profile) { |
| 178 if (!profile) | 183 if (!profile) |
| 179 return false; | 184 return false; |
| 180 const user_manager::User* user = | 185 const user_manager::User* user = |
| 181 ProfileHelper::Get()->GetUserByProfile(profile); | 186 ProfileHelper::Get()->GetUserByProfile(profile); |
| 182 if (!user) | 187 if (!user) |
| 183 return false; | 188 return false; |
| 184 return user == user_manager::UserManager::Get()->GetPrimaryUser(); | 189 return user == user_manager::UserManager::Get()->GetPrimaryUser(); |
| 185 } | 190 } |
| 186 | 191 |
| 192 // static |
| 193 bool ProfileHelper::IsEphemeralUserProfile(const Profile* profile) { |
| 194 if (!profile) |
| 195 return false; |
| 196 |
| 197 // Owner profile is always persistent. |
| 198 if (IsOwnerProfile(profile)) |
| 199 return false; |
| 200 |
| 201 const user_manager::User* user = |
| 202 ProfileHelper::Get()->GetUserByProfile(profile); |
| 203 if (!user) |
| 204 return false; |
| 205 |
| 206 // Guest and public account is ephemeral. |
| 207 const user_manager::UserType user_type = user->GetType(); |
| 208 if (user_type == user_manager::USER_TYPE_GUEST || |
| 209 user_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
| 210 return true; |
| 211 } |
| 212 |
| 213 // Otherwise, users are ephemeral when the policy is enabled. |
| 214 return ChromeUserManager::Get()->AreEphemeralUsersEnabled(); |
| 215 } |
| 216 |
| 187 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { | 217 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { |
| 188 // Initialize Chrome OS preferences like touch pad sensitivity. For the | 218 // Initialize Chrome OS preferences like touch pad sensitivity. For the |
| 189 // preferences to work in the guest mode, the initialization has to be | 219 // preferences to work in the guest mode, the initialization has to be |
| 190 // done after |profile| is switched to the incognito profile (which | 220 // done after |profile| is switched to the incognito profile (which |
| 191 // is actually GuestSessionProfile in the guest mode). See the | 221 // is actually GuestSessionProfile in the guest mode). See the |
| 192 // GetOffTheRecordProfile() call above. | 222 // GetOffTheRecordProfile() call above. |
| 193 profile->InitChromeOSPreferences(); | 223 profile->InitChromeOSPreferences(); |
| 194 | 224 |
| 195 // Add observer so we can see when the first profile's session restore is | 225 // Add observer so we can see when the first profile's session restore is |
| 196 // completed. After that, we won't need the default profile anymore. | 226 // completed. After that, we won't need the default profile anymore. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 Profile* profile) { | 454 Profile* profile) { |
| 425 user_to_profile_for_testing_[user] = profile; | 455 user_to_profile_for_testing_[user] = profile; |
| 426 } | 456 } |
| 427 | 457 |
| 428 // static | 458 // static |
| 429 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( | 459 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 430 const std::string& user_id) { | 460 const std::string& user_id) { |
| 431 return user_id + kUserIdHashSuffix; | 461 return user_id + kUserIdHashSuffix; |
| 432 } | 462 } |
| 433 | 463 |
| 464 void ProfileHelper::FlushProfile(Profile* profile) { |
| 465 if (!profile_flusher_) |
| 466 profile_flusher_.reset(new FileFlusher); |
| 467 |
| 468 // Files/directories that do not need to be flushed. |
| 469 std::vector<base::FilePath> excludes; |
| 470 |
| 471 // Preferences file is handled by ImportantFileWriter. |
| 472 excludes.push_back(base::FilePath(chrome::kPreferencesFilename)); |
| 473 // Do not flush cache files. |
| 474 excludes.push_back(base::FilePath(chrome::kCacheDirname)); |
| 475 excludes.push_back(base::FilePath(chrome::kMediaCacheDirname)); |
| 476 excludes.push_back(base::FilePath(FILE_PATH_LITERAL("GPUCache"))); |
| 477 // Do not flush user Downloads. |
| 478 excludes.push_back( |
| 479 DownloadPrefs::FromBrowserContext(profile)->DownloadPath()); |
| 480 // Let extension system handle extension files. |
| 481 excludes.push_back(base::FilePath(extensions::kInstallDirectoryName)); |
| 482 // Do not flush Drive cache. |
| 483 excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname)); |
| 484 |
| 485 profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure()); |
| 486 } |
| 487 |
| 434 } // namespace chromeos | 488 } // namespace chromeos |
| OLD | NEW |