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

Unified Diff: chrome/browser/first_run/first_run.cc

Issue 208393020: Fix the new First Run sentinel file path determination. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify changes. Created 6 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
Index: chrome/browser/first_run/first_run.cc
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index ee7d583d66f39f3215a253656bbbd7baae6f6449..e292aae29eafac0deafef1052bb49d9530b3c659 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -46,6 +46,7 @@
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -447,30 +448,6 @@ void ProcessDefaultBrowserPolicy(bool make_chrome_default_for_user) {
}
}
-bool IsFirstRunSentinelPresent() {
- base::FilePath first_run_sentinel;
- // Treat sentinel as being present if the path can't be obtained.
- if (!first_run::internal::GetFirstRunSentinelFilePath(&first_run_sentinel) ||
- base::PathExists(first_run_sentinel)) {
- return true;
- }
- // Sentinel is truly absent if there's no legacy path or legacy doesn't exist.
- base::FilePath legacy_first_run_sentinel;
- if (!first_run::internal::GetLegacyFirstRunSentinelFilePath(
- &legacy_first_run_sentinel) ||
- !base::PathExists(legacy_first_run_sentinel)) {
- return false;
- }
- // Migrate the legacy sentinel to the new location if it was found. This does
- // a copy instead of a move to avoid breaking the developer build case where
- // the First Run sentinel is dropped beside chrome.exe by a build action
- // (i.e., at the legacy path).
- bool migrated = base::CopyFile(legacy_first_run_sentinel, first_run_sentinel);
- DPCHECK(migrated);
- // Sentinel is present regardless of whether or not it was migrated.
- return true;
-}
-
} // namespace
namespace first_run {
@@ -565,11 +542,17 @@ void SetupMasterPrefsFromInstallPrefs(
&out_prefs->suppress_default_browser_prompt_for_version);
}
+bool GetFirstRunSentinelFilePath(base::FilePath* path) {
+ base::FilePath user_data_dir;
+ if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
+ *path = user_data_dir.Append(chrome::kFirstRunSentinel);
+ return !path->empty();
grt (UTC plus 2) 2014/03/27 15:35:20 it's not safe to assume that the caller passes in
msw 2014/03/28 00:04:11 Done (restored the original pattern).
+}
+
bool CreateSentinel() {
base::FilePath first_run_sentinel;
- if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
- return false;
- return base::WriteFile(first_run_sentinel, "", 0) != -1;
+ return GetFirstRunSentinelFilePath(&first_run_sentinel) &&
+ base::WriteFile(first_run_sentinel, "", 0) != -1;
grt (UTC plus 2) 2014/03/27 15:35:20 nit: either 4-space indent or wrap the whole thing
msw 2014/03/28 00:04:11 Done (4-space indent).
}
// -- Platform-specific functions --
@@ -596,20 +579,15 @@ MasterPrefs::MasterPrefs()
MasterPrefs::~MasterPrefs() {}
bool IsChromeFirstRun() {
- if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN)
- return internal::first_run_ == internal::FIRST_RUN_TRUE;
-
- internal::first_run_ = internal::FIRST_RUN_FALSE;
-
- base::FilePath first_run_sentinel;
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kForceFirstRun)) {
- internal::first_run_ = internal::FIRST_RUN_TRUE;
- } else if (!command_line->HasSwitch(switches::kNoFirstRun) &&
- !IsFirstRunSentinelPresent()) {
- internal::first_run_ = internal::FIRST_RUN_TRUE;
+ if (internal::first_run_ == internal::FIRST_RUN_UNKNOWN) {
+ internal::first_run_ = internal::FIRST_RUN_FALSE;
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kForceFirstRun) ||
+ (!command_line->HasSwitch(switches::kNoFirstRun) &&
+ !internal::IsFirstRunSentinelPresent())) {
+ internal::first_run_ = internal::FIRST_RUN_TRUE;
+ }
}
-
return internal::first_run_ == internal::FIRST_RUN_TRUE;
}
@@ -637,9 +615,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
bool RemoveSentinel() {
base::FilePath first_run_sentinel;
- if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
- return false;
- return base::DeleteFile(first_run_sentinel, false);
+ return internal::GetFirstRunSentinelFilePath(&first_run_sentinel) &&
+ base::DeleteFile(first_run_sentinel, false);
grt (UTC plus 2) 2014/03/27 15:35:20 same indentation nit
msw 2014/03/28 00:04:11 Done.
}
bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) {

Powered by Google App Engine
This is Rietveld 408576698