summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-28 23:07:21 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-28 23:07:21 +0000
commitdfa08b04cf8ee5a34972379f254061647313e2f0 (patch)
treef97fabbf58bded8170db33f41047e350b7006bd2 /chrome/browser/first_run
parent7ccd66a1d36934f1034dfc8eb8583771c125ffd1 (diff)
downloadchromium_src-dfa08b04cf8ee5a34972379f254061647313e2f0.zip
chromium_src-dfa08b04cf8ee5a34972379f254061647313e2f0.tar.gz
chromium_src-dfa08b04cf8ee5a34972379f254061647313e2f0.tar.bz2
Refactor FirstRun class code into namespace first_run progressively. This cl refactors:
IsChromeFirstRun() CreateSentinel() RemoveSentinel() GetFirstRunSentinelFilePath() It also fixed an issue that chromeos first run won't create sentinel file, and the following runs always think it is a first run. BUG=108137 TEST=None Review URL: http://codereview.chromium.org/8989043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r--chrome/browser/first_run/first_run.cc105
-rw-r--r--chrome/browser/first_run/first_run.h46
-rw-r--r--chrome/browser/first_run/first_run_internal.h51
-rw-r--r--chrome/browser/first_run/first_run_posix.cc35
-rw-r--r--chrome/browser/first_run/first_run_unittest.cc9
-rw-r--r--chrome/browser/first_run/first_run_win.cc27
6 files changed, 189 insertions, 84 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 92b1787..0211efc 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/first_run/first_run_dialog.h"
#include "chrome/browser/first_run/first_run_import_observer.h"
+#include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/importer/external_process_importer_host.h"
#include "chrome/browser/importer/importer_host.h"
@@ -44,9 +45,6 @@ using content::UserMetricsAction;
namespace {
-// The kSentinelFile file absence will tell us it is a first run.
-const char kSentinelFile[] = "First Run";
-
FilePath GetDefaultPrefFilePath(bool create_profile_dir,
const FilePath& user_data_dir) {
FilePath default_pref_dir =
@@ -112,9 +110,48 @@ void SetImportItem(PrefService* user_prefs,
} // namespace
-// FirstRun -------------------------------------------------------------------
+namespace first_run {
+namespace internal {
+
+const char* const kSentinelFile = "First Run";
+FirstRunState first_run_ = FIRST_RUN_UNKNOWN;
+
+} // namespace internal
+} // namespace first_run
+
+namespace first_run {
+
+bool IsChromeFirstRun() {
+ if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN)
+ return internal::first_run_ == internal::FIRST_RUN_TRUE;
+
+ FilePath first_run_sentinel;
+ if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel) ||
+ file_util::PathExists(first_run_sentinel)) {
+ internal::first_run_ = internal::FIRST_RUN_FALSE;
+ return false;
+ }
+ internal::first_run_ = internal::FIRST_RUN_TRUE;
+ return true;
+}
+
+bool CreateSentinel() {
+ FilePath first_run_sentinel;
+ if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
+ return false;
+ return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
+}
+
+bool RemoveSentinel() {
+ FilePath first_run_sentinel;
+ if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
+ return false;
+ return file_util::Delete(first_run_sentinel, false);
+}
-FirstRun::FirstRunState FirstRun::first_run_ = FIRST_RUN_UNKNOWN;
+} // namespace first_run
+
+// FirstRun -------------------------------------------------------------------
FirstRun::MasterPrefs::MasterPrefs()
: ping_delay(0),
@@ -307,7 +344,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
// We need to be able to create the first run sentinel or else we cannot
// proceed because ImportSettings will launch the importer process which
// would end up here if the sentinel is not present.
- if (!FirstRun::CreateSentinel())
+ if (!first_run::CreateSentinel())
return false;
if (prefs.GetBool(installer::master_preferences::kDistroShowWelcomePage,
@@ -382,37 +419,6 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
}
// static
-bool FirstRun::IsChromeFirstRun() {
- if (first_run_ != FIRST_RUN_UNKNOWN)
- return first_run_ == FIRST_RUN_TRUE;
-
- FilePath first_run_sentinel;
- if (!GetFirstRunSentinelFilePath(&first_run_sentinel) ||
- file_util::PathExists(first_run_sentinel)) {
- first_run_ = FIRST_RUN_FALSE;
- return false;
- }
- first_run_ = FIRST_RUN_TRUE;
- return true;
-}
-
-// static
-bool FirstRun::RemoveSentinel() {
- FilePath first_run_sentinel;
- if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
- return false;
- return file_util::Delete(first_run_sentinel, false);
-}
-
-// static
-bool FirstRun::CreateSentinel() {
- FilePath first_run_sentinel;
- if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
- return false;
- return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
-}
-
-// static
bool FirstRun::SetShowFirstRunBubblePref(bool show_bubble) {
PrefService* local_state = g_browser_process->local_state();
if (!local_state)
@@ -506,29 +512,6 @@ int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
}
// static
-bool FirstRun::GetFirstRunSentinelFilePath(FilePath* path) {
- FilePath first_run_sentinel;
-
-#if defined(OS_WIN)
- FilePath exe_path;
- if (!PathService::Get(base::DIR_EXE, &exe_path))
- return false;
- if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
- first_run_sentinel = exe_path;
- } else {
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
- }
-#else
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
-#endif
-
- *path = first_run_sentinel.AppendASCII(kSentinelFile);
- return true;
-}
-
-// static
void FirstRun::AutoImport(
Profile* profile,
bool homepage_defined,
@@ -646,7 +629,7 @@ void FirstRun::AutoImport(
FirstRun::SetPersonalDataManagerFirstRunPref();
process_singleton->Unlock();
- FirstRun::CreateSentinel();
+ first_run::CreateSentinel();
#endif
}
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 6685f6b..043dbc4 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -23,6 +23,33 @@ class Profile;
class ProcessSingleton;
class TemplateURLService;
+// TODO(jennyz): All FirstRun class code will be refactored to first_run
+// namespace progressively with several changelists to be landed. Therefore,
+// we keep first_run namespace and FirstRun in the same file temporarily.
+
+// This namespace contains the chrome first-run installation actions needed to
+// fully test the custom installer. It also contains the opposite actions to
+// execute during uninstall. When the first run UI is ready we won't
+// do the actions unconditionally. Currently the only action is to create a
+// desktop shortcut.
+//
+// The way we detect first-run is by looking at a 'sentinel' file.
+// If it does not exist we understand that we need to do the first time
+// install work for this user. After that the sentinel file is created.
+namespace first_run {
+
+// Returns true if this is the first time chrome is run for this user.
+bool IsChromeFirstRun();
+
+// Creates the sentinel file that signals that chrome has been configured.
+bool CreateSentinel();
+
+// Removes the sentinel file created in ConfigDone(). Returns false if the
+// sentinel file could not be removed.
+bool RemoveSentinel();
+
+} // namespace first_run
+
// This class contains the chrome first-run installation actions needed to
// fully test the custom installer. It also contains the opposite actions to
// execute during uninstall. When the first run UI is ready we won't
@@ -91,16 +118,6 @@ class FirstRun {
static bool ProcessMasterPreferences(const FilePath& user_data_dir,
MasterPrefs* out_prefs);
- // Returns true if this is the first time chrome is run for this user.
- static bool IsChromeFirstRun();
-
- // Creates the sentinel file that signals that chrome has been configured.
- static bool CreateSentinel();
-
- // Removes the sentinel file created in ConfigDone(). Returns false if the
- // sentinel file could not be removed.
- static bool RemoveSentinel();
-
// Sets the kShouldShowFirstRunBubble local state pref so that the browser
// shows the bubble once the main message loop gets going (or refrains from
// showing the bubble, if |show_bubble| is false). Returns false if the pref
@@ -198,15 +215,6 @@ class FirstRun {
static bool ImportBookmarks(const FilePath& import_bookmarks_path);
#endif
- enum FirstRunState {
- FIRST_RUN_UNKNOWN, // The state is not tested or set yet.
- FIRST_RUN_TRUE,
- FIRST_RUN_FALSE
- };
-
- // This variable should only be accessed through IsChromeFirstRun().
- static FirstRunState first_run_;
-
// This class is for scoping purposes.
DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun);
};
diff --git a/chrome/browser/first_run/first_run_internal.h b/chrome/browser/first_run/first_run_internal.h
new file mode 100644
index 0000000..7cd9497
--- /dev/null
+++ b/chrome/browser/first_run/first_run_internal.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_FIRST_RUN_FIRST_RUN_INTERNAL_H_
+#define CHROME_BROWSER_FIRST_RUN_FIRST_RUN_INTERNAL_H_
+#pragma once
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
+#include "ui/gfx/native_widget_types.h"
+
+class CommandLine;
+class FilePath;
+class GURL;
+class ImporterHost;
+class ImporterList;
+class Profile;
+class ProcessSingleton;
+class TemplateURLService;
+
+namespace first_run {
+namespace internal {
+
+enum FirstRunState {
+ FIRST_RUN_UNKNOWN, // The state is not tested or set yet.
+ FIRST_RUN_TRUE,
+ FIRST_RUN_FALSE
+};
+
+// This variable should only be accessed through IsChromeFirstRun().
+extern FirstRunState first_run_;
+
+// The kSentinelFile file absence will tell us it is a first run.
+extern const char* const kSentinelFile;
+
+// -- Platform-specific functions --
+
+// Gives the full path to the sentinel file. The file might not exist.
+// This function has a common implementation on OS_POSIX and a windows specific
+// implementation.
+bool GetFirstRunSentinelFilePath(FilePath* path);
+
+} // namespace internal
+} // namespace first_run
+
+#endif // CHROME_BROWSER_FIRST_RUN_FIRST_RUN_INTERNAL_H_
diff --git a/chrome/browser/first_run/first_run_posix.cc b/chrome/browser/first_run/first_run_posix.cc
new file mode 100644
index 0000000..330f3fa
--- /dev/null
+++ b/chrome/browser/first_run/first_run_posix.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/first_run/first_run.h"
+
+#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/first_run/first_run_internal.h"
+#include "chrome/browser/importer/importer_host.h"
+#include "chrome/browser/importer/importer_list.h"
+#include "chrome/browser/importer/importer_progress_dialog.h"
+#include "chrome/browser/importer/importer_progress_observer.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/installer/util/master_preferences.h"
+#include "chrome/installer/util/master_preferences_constants.h"
+
+namespace first_run {
+
+namespace internal {
+
+bool GetFirstRunSentinelFilePath(FilePath* path) {
+ FilePath first_run_sentinel;
+
+ if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
+ return false;
+
+ *path = first_run_sentinel.AppendASCII(kSentinelFile);
+ return true;
+}
+
+} // namespace internal
+
+} // namespace first_run
diff --git a/chrome/browser/first_run/first_run_unittest.cc b/chrome/browser/first_run/first_run_unittest.cc
index 6a32fe1..601416c 100644
--- a/chrome/browser/first_run/first_run_unittest.cc
+++ b/chrome/browser/first_run/first_run_unittest.cc
@@ -1,24 +1,25 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/file_util.h"
#include "chrome/browser/first_run/first_run.h"
+#include "chrome/browser/first_run/first_run_internal.h"
#include "testing/gtest/include/gtest/gtest.h"
class FirstRunTest : public testing::Test {
protected:
virtual void SetUp() {
- FirstRun::GetFirstRunSentinelFilePath(&sentinel_path_);
+ first_run::internal::GetFirstRunSentinelFilePath(&sentinel_path_);
}
FilePath sentinel_path_;
};
TEST_F(FirstRunTest, RemoveSentinel) {
- EXPECT_TRUE(FirstRun::CreateSentinel());
+ EXPECT_TRUE(first_run::CreateSentinel());
EXPECT_TRUE(file_util::PathExists(sentinel_path_));
- EXPECT_TRUE(FirstRun::RemoveSentinel());
+ EXPECT_TRUE(first_run::RemoveSentinel());
EXPECT_FALSE(file_util::PathExists(sentinel_path_));
}
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index 8de0463..4d10848 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -23,11 +23,13 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/first_run/first_run_import_observer.h"
+#include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/browser/importer/importer_host.h"
#include "chrome/browser/importer/importer_list.h"
#include "chrome/browser/importer/importer_progress_dialog.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/worker_thread_ticker.h"
@@ -299,6 +301,31 @@ bool DecodeImportParams(const std::string& encoded,
} // namespace
+namespace first_run {
+
+namespace internal{
+
+bool GetFirstRunSentinelFilePath(FilePath* path) {
+ FilePath first_run_sentinel;
+
+ FilePath exe_path;
+ if (!PathService::Get(base::DIR_EXE, &exe_path))
+ return false;
+ if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
+ first_run_sentinel = exe_path;
+ } else {
+ if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
+ return false;
+ }
+
+ *path = first_run_sentinel.AppendASCII(kSentinelFile);
+ return true;
+}
+
+} // namespace internal
+
+} // namespace first_run
+
// static
void FirstRun::PlatformSetup() {
CreateChromeDesktopShortcut();