Commit 9ac8d605 authored by tnagel's avatar tnagel Committed by Commit bot

StartupUtils: Improve docs and move static functions to anonymous namespace.

Moving static functions to anonymous namespace for more modern style and better readability.

BUG=587495

Review URL: https://codereview.chromium.org/1707733002

Cr-Commit-Position: refs/heads/master@{#376121}
parent 6b8b26b6
...@@ -47,6 +47,35 @@ void SaveStringPreferenceForced(const char* pref_name, ...@@ -47,6 +47,35 @@ void SaveStringPreferenceForced(const char* pref_name,
prefs->CommitPendingWrite(); prefs->CommitPendingWrite();
} }
// Returns the path to flag file indicating that both parts of OOBE were
// completed.
// On chrome device, returns /home/chronos/.oobe_completed.
// On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed.
base::FilePath GetOobeCompleteFlagPath() {
// The constant is defined here so it won't be referenced directly.
const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed";
if (base::SysInfo::IsRunningOnChromeOS()) {
return base::FilePath(kOobeCompleteFlagFilePath);
} else {
base::FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
return user_data_dir.AppendASCII(".oobe_completed");
}
}
void CreateOobeCompleteFlagFile() {
// Create flag file for boot-time init scripts.
const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath();
if (!base::PathExists(oobe_complete_flag_path)) {
FILE* oobe_flag_file = base::OpenFile(oobe_complete_flag_path, "w+b");
if (oobe_flag_file == NULL)
DLOG(WARNING) << oobe_complete_flag_path.value() << " doesn't exist.";
else
base::CloseFile(oobe_flag_file);
}
}
} // namespace } // namespace
namespace chromeos { namespace chromeos {
...@@ -92,23 +121,6 @@ void StartupUtils::SaveOobePendingScreen(const std::string& screen) { ...@@ -92,23 +121,6 @@ void StartupUtils::SaveOobePendingScreen(const std::string& screen) {
SaveStringPreferenceForced(prefs::kOobeScreenPending, screen); SaveStringPreferenceForced(prefs::kOobeScreenPending, screen);
} }
// Returns the path to flag file indicating that both parts of OOBE were
// completed.
// On chrome device, returns /home/chronos/.oobe_completed.
// On Linux desktop, returns {DIR_USER_DATA}/.oobe_completed.
static base::FilePath GetOobeCompleteFlagPath() {
// The constant is defined here so it won't be referenced directly.
const char kOobeCompleteFlagFilePath[] = "/home/chronos/.oobe_completed";
if (base::SysInfo::IsRunningOnChromeOS()) {
return base::FilePath(kOobeCompleteFlagFilePath);
} else {
base::FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
return user_data_dir.AppendASCII(".oobe_completed");
}
}
// static // static
base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() { base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() {
const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath(); const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath();
...@@ -118,18 +130,6 @@ base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() { ...@@ -118,18 +130,6 @@ base::TimeDelta StartupUtils::GetTimeSinceOobeFlagFileCreation() {
return base::TimeDelta(); return base::TimeDelta();
} }
static void CreateOobeCompleteFlagFile() {
// Create flag file for boot-time init scripts.
const base::FilePath oobe_complete_flag_path = GetOobeCompleteFlagPath();
if (!base::PathExists(oobe_complete_flag_path)) {
FILE* oobe_flag_file = base::OpenFile(oobe_complete_flag_path, "w+b");
if (oobe_flag_file == NULL)
DLOG(WARNING) << oobe_complete_flag_path.value() << " doesn't exist.";
else
base::CloseFile(oobe_flag_file);
}
}
// static // static
bool StartupUtils::IsDeviceRegistered() { bool StartupUtils::IsDeviceRegistered() {
int value = int value =
......
...@@ -24,7 +24,9 @@ class StartupUtils { ...@@ -24,7 +24,9 @@ class StartupUtils {
// Returns true if EULA has been accepted. // Returns true if EULA has been accepted.
static bool IsEulaAccepted(); static bool IsEulaAccepted();
// Returns OOBE completion status. // Returns OOBE completion status, i.e. whether the OOBE wizard should be run
// on next boot. This is NOT what causes the .oobe_completed flag file to be
// written.
static bool IsOobeCompleted(); static bool IsOobeCompleted();
// Marks EULA status as accepted. // Marks EULA status as accepted.
...@@ -36,10 +38,13 @@ class StartupUtils { ...@@ -36,10 +38,13 @@ class StartupUtils {
// Stores the next pending OOBE screen in case it will need to be resumed. // Stores the next pending OOBE screen in case it will need to be resumed.
static void SaveOobePendingScreen(const std::string& screen); static void SaveOobePendingScreen(const std::string& screen);
// Returns the time since the Oobe flag file was created. // Returns the time since the OOBE flag file was created.
static base::TimeDelta GetTimeSinceOobeFlagFileCreation(); static base::TimeDelta GetTimeSinceOobeFlagFileCreation();
// Returns device registration completion status, i.e. second part of OOBE. // Returns device registration completion status, i.e. second part of OOBE.
// It is triggered by enrolling the device, but also by logging in as a
// consumer owner or by logging in as guest. This state change is announced
// to the system by writing the .oobe_completed flag file.
static bool IsDeviceRegistered(); static bool IsDeviceRegistered();
// Marks device registered. i.e. second part of OOBE is completed. // Marks device registered. i.e. second part of OOBE is completed.
......
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