Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 1815853002: cros: Flush profile files at critical moments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits and create test files to fix trybots Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/profiles/profile_helper.cc
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc
index ee28d782819d967beecc706d9a17f6fc670d2e4e..d492f72b87dae11cf6646816509b602f35d3a248 100644
--- a/chrome/browser/chromeos/profiles/profile_helper.cc
+++ b/chrome/browser/chromeos/profiles/profile_helper.cc
@@ -11,13 +11,17 @@
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
+#include "chrome/browser/chromeos/base/file_flusher.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
+#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
+#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
+#include "chromeos/chromeos_constants.h"
#include "chromeos/chromeos_switches.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/user_manager/user.h"
@@ -26,6 +30,7 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
+#include "extensions/common/constants.h"
namespace chromeos {
@@ -157,7 +162,7 @@ bool ProfileHelper::IsSigninProfile(const Profile* profile) {
}
// static
-bool ProfileHelper::IsOwnerProfile(Profile* profile) {
+bool ProfileHelper::IsOwnerProfile(const Profile* profile) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kStubCrosSettings)) {
return true;
@@ -184,6 +189,31 @@ bool ProfileHelper::IsPrimaryProfile(const Profile* profile) {
return user == user_manager::UserManager::Get()->GetPrimaryUser();
}
+// static
+bool ProfileHelper::IsEphemeralUserProfile(const Profile* profile) {
+ if (!profile)
+ return false;
+
+ // Owner profile is always persistent.
+ if (IsOwnerProfile(profile))
+ return false;
+
+ const user_manager::User* user =
+ ProfileHelper::Get()->GetUserByProfile(profile);
+ if (!user)
+ return false;
+
+ // Guest and public account is ephemeral.
+ const user_manager::UserType user_type = user->GetType();
+ if (user_type == user_manager::USER_TYPE_GUEST ||
+ user_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
+ return true;
+ }
+
+ // Otherwise, users are ephemeral when the policy is enabled.
+ return ChromeUserManager::Get()->AreEphemeralUsersEnabled();
+}
+
void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
// Initialize Chrome OS preferences like touch pad sensitivity. For the
// preferences to work in the guest mode, the initialization has to be
@@ -431,4 +461,28 @@ std::string ProfileHelper::GetUserIdHashByUserIdForTesting(
return user_id + kUserIdHashSuffix;
}
+void ProfileHelper::FlushProfile(Profile* profile) {
+ if (!profile_flusher_)
+ profile_flusher_.reset(new FileFlusher);
+
+ // Files/directories that do not need to be flushed.
+ std::vector<base::FilePath> excludes;
+
+ // Preferences file is handled by ImportantFileWriter.
+ excludes.push_back(base::FilePath(chrome::kPreferencesFilename));
+ // Do not flush cache files.
+ excludes.push_back(base::FilePath(chrome::kCacheDirname));
+ excludes.push_back(base::FilePath(chrome::kMediaCacheDirname));
+ excludes.push_back(base::FilePath(FILE_PATH_LITERAL("GPUCache")));
+ // Do not flush user Downloads.
+ excludes.push_back(
+ DownloadPrefs::FromBrowserContext(profile)->DownloadPath());
+ // Let extension system handle extension files.
+ excludes.push_back(base::FilePath(extensions::kInstallDirectoryName));
+ // Do not flush Drive cache.
+ excludes.push_back(base::FilePath(chromeos::kDriveCacheDirname));
+
+ profile_flusher_->RequestFlush(profile->GetPath(), excludes, base::Closure());
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698