diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-16 11:19:39 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-16 11:19:39 +0000 |
commit | 961d1f88a188152331294e3ee099d2e57d4e5a1d (patch) | |
tree | 309348fb381cbffff17fa8407b1a2a63e988659e /chrome/browser/first_run | |
parent | ac480ee572c8cc26c31fbce55d7b959f57abc9b6 (diff) | |
download | chromium_src-961d1f88a188152331294e3ee099d2e57d4e5a1d.zip chromium_src-961d1f88a188152331294e3ee099d2e57d4e5a1d.tar.gz chromium_src-961d1f88a188152331294e3ee099d2e57d4e5a1d.tar.bz2 |
Fix a subtle issue/bug for unit tests to use IsChromeFirstRun. Once first_run was set to 1 from one unit test,
there is no way for other unit tests to change the first_run state regardless first_run_sentinel exists or not.
In this case, IsChromeFirstRun already return true which may not be desirable for some unit test such as Toolbar5ImporterTest::BookmarkParse.
The issue won't cause any problem if all unit tests were run separately instead of in a single unit_test.exe.
But the change itself is minimal, and allow future unit tests for IsChromeFirstRun itself.
Bug=None
Test=None
Review URL: http://codereview.chromium.org/3038024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r-- | chrome/browser/first_run/first_run.cc | 12 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run.h | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc index 225067f..ddc4724 100644 --- a/chrome/browser/first_run/first_run.cc +++ b/chrome/browser/first_run/first_run.cc @@ -28,6 +28,8 @@ const char kSentinelFile[] = "First Run"; } // namespace +FirstRun::FirstRunState FirstRun::first_run_ = FIRST_RUN_UNKNOWN; + // TODO(port): Import switches need to be ported to both Mac and Linux. Not all // import switches here are implemented for Linux. None are implemented for Mac // (as this function will not be called on Mac). @@ -50,18 +52,16 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { // static bool FirstRun::IsChromeFirstRun() { - // A troolean, 0 means not yet set, 1 means set to true, 2 set to false. - static int first_run = 0; - if (first_run != 0) - return first_run == 1; + 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 = 2; + first_run_ = FIRST_RUN_FALSE; return false; } - first_run = 1; + first_run_ = FIRST_RUN_TRUE; return true; } diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h index 4cafd34..9289176 100644 --- a/chrome/browser/first_run/first_run.h +++ b/chrome/browser/first_run/first_run.h @@ -128,6 +128,7 @@ class FirstRun { private: friend class FirstRunTest; + FRIEND_TEST_ALL_PREFIXES(Toolbar5ImporterTest, BookmarkParse); #if defined(OS_WIN) // Imports settings in a separate process. It is the implementation of the @@ -152,6 +153,14 @@ class FirstRun { // Gives the full path to the sentinel file. The file might not exist. static bool GetFirstRunSentinelFilePath(FilePath* path); + 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); }; |