Commit 10f895cf authored by James Cook's avatar James Cook Committed by Commit Bot

first_run: Consolidate duplicate code for IsFirstRunSentinelPresent

There's no per-platform difference for this function, so consolidate
the two copies into one in first_run.cc.

No functional changes - this is just cleanup in preparation for a
first-run change for the go/lacros project.

Bug: 1129954
Test: existing unit_tests
Change-Id: I9871f2501f87fdd88f2e7598d0d43cf14fef59ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418570
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808973}
parent 6f9855ee
......@@ -214,12 +214,28 @@ void ProcessDefaultBrowserPolicy(bool make_chrome_default_for_user) {
}
}
// Get the file path of the first run sentinel; returns false on failure.
bool GetFirstRunSentinelFilePath(base::FilePath* path) {
base::FilePath user_data_dir;
if (!base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
return false;
*path = user_data_dir.Append(chrome::kFirstRunSentinel);
return true;
}
// Create the first run sentinel file; returns false on failure.
bool CreateSentinel() {
base::FilePath first_run_sentinel;
return GetFirstRunSentinelFilePath(&first_run_sentinel) &&
base::WriteFile(first_run_sentinel, "");
}
// Reads the creation time of the first run sentinel file. If the first run
// sentinel file does not exist, it will return base::Time().
base::Time ReadFirstRunSentinelCreationTime() {
base::Time first_run_sentinel_creation_time = base::Time();
base::FilePath first_run_sentinel;
if (first_run::internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) {
if (GetFirstRunSentinelFilePath(&first_run_sentinel)) {
base::File::Info info;
if (base::GetFileInfo(first_run_sentinel, &info))
first_run_sentinel_creation_time = info.creation_time;
......@@ -227,6 +243,12 @@ base::Time ReadFirstRunSentinelCreationTime() {
return first_run_sentinel_creation_time;
}
// Returns true if the sentinel file exists (or the path cannot be obtained).
bool IsFirstRunSentinelPresent() {
base::FilePath sentinel;
return !GetFirstRunSentinelFilePath(&sentinel) || base::PathExists(sentinel);
}
} // namespace
namespace first_run {
......@@ -254,20 +276,6 @@ void SetupInitialPrefsFromInstallPrefs(
&out_prefs->suppress_default_browser_prompt_for_version);
}
bool GetFirstRunSentinelFilePath(base::FilePath* path) {
base::FilePath user_data_dir;
if (!base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
return false;
*path = user_data_dir.Append(chrome::kFirstRunSentinel);
return true;
}
bool CreateSentinel() {
base::FilePath first_run_sentinel;
return GetFirstRunSentinelFilePath(&first_run_sentinel) &&
base::WriteFile(first_run_sentinel, "");
}
// -- Platform-specific functions --
#if !defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_BSD)
......@@ -307,7 +315,7 @@ bool IsChromeFirstRun() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
g_first_run = internal::DetermineFirstRunState(
internal::IsFirstRunSentinelPresent(),
IsFirstRunSentinelPresent(),
command_line->HasSwitch(switches::kForceFirstRun),
command_line->HasSwitch(switches::kNoFirstRun));
}
......@@ -329,7 +337,7 @@ bool IsMetricsReportingOptIn() {
void CreateSentinelIfNeeded() {
if (IsChromeFirstRun())
internal::CreateSentinel();
CreateSentinel();
// Causes the first run sentinel creation time to be read and cached, while
// I/O is still allowed.
......
......@@ -35,19 +35,10 @@ void SetupInitialPrefsFromInstallPrefs(
const installer::InitialPreferences& install_prefs,
MasterPrefs* out_prefs);
// Get the file path of the first run sentinel; returns false on failure.
bool GetFirstRunSentinelFilePath(base::FilePath* path);
// Create the first run sentinel file; returns false on failure.
bool CreateSentinel();
// -- Platform-specific functions --
void DoPostImportPlatformSpecificTasks(Profile* profile);
// Returns true if the sentinel file exists (or the path cannot be obtained).
bool IsFirstRunSentinelPresent();
// This function has a common implementationin for all non-linux platforms, and
// a linux specific implementation.
bool IsOrganicFirstRun();
......
......@@ -108,11 +108,6 @@ void DoPostImportPlatformSpecificTasks(Profile* profile) {
#endif // !OS_CHROMEOS
}
bool IsFirstRunSentinelPresent() {
base::FilePath sentinel;
return !GetFirstRunSentinelFilePath(&sentinel) || base::PathExists(sentinel);
}
bool ShowPostInstallEULAIfNeeded(installer::InitialPreferences* install_prefs) {
// The EULA is only handled on Windows.
return true;
......
......@@ -120,11 +120,6 @@ void DoPostImportPlatformSpecificTasks(Profile* /* profile */) {
}
}
bool IsFirstRunSentinelPresent() {
base::FilePath sentinel;
return !GetFirstRunSentinelFilePath(&sentinel) || base::PathExists(sentinel);
}
bool ShowPostInstallEULAIfNeeded(installer::InitialPreferences* install_prefs) {
if (IsEULANotAccepted(install_prefs)) {
// Show the post-installation EULA. This is done by setup.exe and the
......
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