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 kLockScreenAppProfile[] = "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() == kLockScreenAppProfile; |
| 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(kLockScreenAppProfile); |
| 186 } |
| 187 |
| 188 // static |
| 189 std::string ProfileHelper::GetLockScreenAppProfileName() { |
| 190 return kLockScreenAppProfile; |
| 191 } |
| 192 |
| 193 // static |
174 bool ProfileHelper::IsOwnerProfile(const Profile* profile) { | 194 bool ProfileHelper::IsOwnerProfile(const Profile* profile) { |
175 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 195 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
176 chromeos::switches::kStubCrosSettings)) { | 196 chromeos::switches::kStubCrosSettings)) { |
177 return true; | 197 return true; |
178 } | 198 } |
179 | 199 |
180 if (!profile) | 200 if (!profile) |
181 return false; | 201 return false; |
182 const user_manager::User* user = | 202 const user_manager::User* user = |
183 ProfileHelper::Get()->GetUserByProfile(profile); | 203 ProfileHelper::Get()->GetUserByProfile(profile); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 return *it; | 371 return *it; |
352 } | 372 } |
353 | 373 |
354 // In case of test setup we should always default to primary user. | 374 // In case of test setup we should always default to primary user. |
355 return user_manager::UserManager::Get()->GetPrimaryUser(); | 375 return user_manager::UserManager::Get()->GetPrimaryUser(); |
356 } | 376 } |
357 | 377 |
358 DCHECK(!content::BrowserThread::IsThreadInitialized( | 378 DCHECK(!content::BrowserThread::IsThreadInitialized( |
359 content::BrowserThread::UI) || | 379 content::BrowserThread::UI) || |
360 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 380 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
361 if (ProfileHelper::IsSigninProfile(profile)) | 381 if (ProfileHelper::IsSigninProfile(profile) || |
362 return NULL; | 382 ProfileHelper::IsLockScreenAppProfile(profile)) { |
| 383 return nullptr; |
| 384 } |
363 | 385 |
364 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 386 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
365 | 387 |
366 // Special case for non-CrOS tests that do create several profiles | 388 // Special case for non-CrOS tests that do create several profiles |
367 // and don't really care about mapping to the real user. | 389 // and don't really care about mapping to the real user. |
368 // Without multi-profiles on Chrome OS such tests always got active_user_. | 390 // Without multi-profiles on Chrome OS such tests always got active_user_. |
369 // Now these tests will specify special flag to continue working. | 391 // Now these tests will specify special flag to continue working. |
370 // In future those tests can get a proper CrOS configuration i.e. register | 392 // 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. | 393 // and login several users if they want to work with an additional profile. |
372 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 394 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 DownloadPrefs::FromBrowserContext(profile)->DownloadPath()); | 525 DownloadPrefs::FromBrowserContext(profile)->DownloadPath()); |
504 // Let extension system handle extension files. | 526 // Let extension system handle extension files. |
505 excludes.push_back(base::FilePath(extensions::kInstallDirectoryName)); | 527 excludes.push_back(base::FilePath(extensions::kInstallDirectoryName)); |
506 // Do not flush Drive cache. | 528 // Do not flush Drive cache. |
507 excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname)); | 529 excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname)); |
508 | 530 |
509 profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure()); | 531 profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure()); |
510 } | 532 } |
511 | 533 |
512 } // namespace chromeos | 534 } // namespace chromeos |
OLD | NEW |