1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/first_run/first_run.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/path_service.h"
10 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "ios/chrome/browser/chrome_paths.h"
15 // The absence of kSentinelFile file will tell us it is a first run.
16 const base::FilePath::CharType kSentinelFile[] = FILE_PATH_LITERAL("First Run");
18 // RLZ ping delay pref name.
19 const char kPingDelayPrefName[] = "distribution.ping_delay";
23 FirstRun::FirstRunState FirstRun::first_run_ = FIRST_RUN_UNKNOWN;
26 bool FirstRun::GetFirstRunSentinelFilePath(base::FilePath* path) {
27 base::FilePath first_run_sentinel;
28 if (!PathService::Get(ios::DIR_USER_DATA, &first_run_sentinel))
30 *path = first_run_sentinel.Append(kSentinelFile);
35 bool FirstRun::IsChromeFirstRun() {
36 if (first_run_ != FIRST_RUN_UNKNOWN)
37 return first_run_ == FIRST_RUN_TRUE;
39 base::FilePath first_run_sentinel;
40 if (!GetFirstRunSentinelFilePath(&first_run_sentinel) ||
41 base::PathExists(first_run_sentinel)) {
42 first_run_ = FIRST_RUN_FALSE;
45 first_run_ = FIRST_RUN_TRUE;
50 bool FirstRun::RemoveSentinel() {
51 base::FilePath first_run_sentinel;
52 if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
54 return base::DeleteFile(first_run_sentinel, false);
58 bool FirstRun::CreateSentinel() {
59 base::FilePath first_run_sentinel;
60 if (!GetFirstRunSentinelFilePath(&first_run_sentinel) ||
61 base::PathExists(first_run_sentinel))
63 return base::WriteFile(first_run_sentinel, "", 0) != -1;
67 const char* FirstRun::GetPingDelayPrefName() {
68 return kPingDelayPrefName;
72 void FirstRun::RegisterProfilePrefs(
73 user_prefs::PrefRegistrySyncable* registry) {
74 registry->RegisterIntegerPref(GetPingDelayPrefName(), 0);