Commit 9f1f32df authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

User profile: Save the profile creation time in profile prefs

Profile::GetCreationTime relied on the directory's creation time, which
is not supported by all the file systems. For example, in POSIX we use
the st_ctim property, which is the last file status change timestamp.
Using the prefs will ensure that the creation time never changes if the
profile directory is copied or if the file creation time is not
supported by the file system. This also ensures that
Profile::GetCreationTime works properly across enterprise snapshots.

Bug: 958893
Change-Id: I4e6189642939bb52524c412a9146087d597320dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079163
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746813}
parent fd70e3c3
......@@ -412,16 +412,17 @@ void ProfileImpl::RegisterProfilePrefs(
#if !defined(OS_ANDROID)
registry->RegisterBooleanPref(prefs::kShowCastIconInToolbar, false);
#endif // !defined(OS_ANDROID)
registry->RegisterTimePref(prefs::kProfileCreationTime, base::Time());
}
ProfileImpl::ProfileImpl(
const base::FilePath& path,
Delegate* delegate,
CreateMode create_mode,
base::Time creation_time,
base::Time path_creation_time,
scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: path_(path),
creation_time_(creation_time),
path_creation_time_(path_creation_time),
io_task_runner_(std::move(io_task_runner)),
io_data_(this),
last_session_exit_type_(EXIT_NORMAL),
......@@ -607,6 +608,15 @@ void ProfileImpl::DoFinalInit() {
TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
PrefService* prefs = GetPrefs();
// Do not override the existing pref in case a profile directory is copied, or
// if the file system does not support creation time and the property (i.e.
// st_ctim in posix which is actually the last status change time when the
// inode was last updated) use to mimic it changes because of some other
// modification.
if (!prefs->HasPrefPath(prefs::kProfileCreationTime))
prefs->SetTime(prefs::kProfileCreationTime, path_creation_time_);
pref_change_registrar_.Init(prefs);
pref_change_registrar_.Add(
prefs::kSupervisedUserId,
......@@ -831,7 +841,7 @@ base::FilePath ProfileImpl::GetPath() const {
}
base::Time ProfileImpl::GetCreationTime() const {
return creation_time_;
return prefs_->GetTime(prefs::kProfileCreationTime);
}
scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() {
......@@ -1411,7 +1421,7 @@ void ProfileImpl::InitChromeOSPreferences() {
#endif // defined(OS_CHROMEOS)
void ProfileImpl::SetCreationTimeForTesting(base::Time creation_time) {
creation_time_ = creation_time;
prefs_->SetTime(prefs::kProfileCreationTime, creation_time);
}
GURL ProfileImpl::GetHomePage() {
......
......@@ -15,6 +15,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
......@@ -181,7 +182,7 @@ class ProfileImpl : public Profile {
ProfileImpl(const base::FilePath& path,
Delegate* delegate,
CreateMode create_mode,
base::Time creation_time,
base::Time path_creation_time,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
#if defined(OS_ANDROID)
......@@ -223,7 +224,7 @@ class ProfileImpl : public Profile {
base::FilePath path_;
base::Time creation_time_;
base::Time path_creation_time_;
// Task runner used for file access in the profile path.
scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
......
......@@ -66,6 +66,9 @@ const char kHomePage[] = "homepage";
// frequency it has been ignored.
const char kImportantSitesDialogHistory[] = "important_sites_dialog";
// This is the profile creation time.
const char kProfileCreationTime[] = "profile.creation_time";
#if defined(OS_WIN)
// This is a timestamp of the last time this profile was reset by a third party
// tool. On Windows, a third party tool may set a registry value that will be
......
......@@ -31,6 +31,7 @@ extern const char kForceEphemeralProfiles[];
extern const char kHomePageIsNewTabPage[];
extern const char kHomePage[];
extern const char kImportantSitesDialogHistory[];
extern const char kProfileCreationTime[];
#if defined(OS_WIN)
extern const char kLastProfileResetTimestamp[];
extern const char kChromeCleanerResetPending[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment