summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 02:29:36 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 02:29:36 +0000
commit38335efa75be7ea8fc99caf73789c85092e06d80 (patch)
tree48a59b30a420d2a29f677beff349cf727c755ca4 /chrome/browser
parente52146dac4696c7ef277dbd386415026ada77199 (diff)
downloadchromium_src-38335efa75be7ea8fc99caf73789c85092e06d80.zip
chromium_src-38335efa75be7ea8fc99caf73789c85092e06d80.tar.gz
chromium_src-38335efa75be7ea8fc99caf73789c85092e06d80.tar.bz2
Make Mac first run store sentinel in Profile directory.
* Added code to migrate from previous defaults-based first run. * Renamed linux_guid -> posix_guid. BUG=19260 TEST=Open current official release and go through first run UI, then open a release compiled with this patch. First run UI should not be displayed again. TEST=First Run UI should only be displayed once on first run and not anew on each launch. Review URL: http://codereview.chromium.org/173020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/first_run.cc3
-rw-r--r--chrome/browser/first_run_mac.mm105
-rw-r--r--chrome/browser/first_run_migration_mac_unittest.mm62
-rw-r--r--chrome/browser/google_update_settings_mac.mm49
-rw-r--r--chrome/browser/google_update_settings_mac_unittest.mm53
-rw-r--r--chrome/browser/google_update_settings_posix.cc (renamed from chrome/browser/google_update_settings_linux.cc)27
-rw-r--r--chrome/browser/google_update_settings_posix_unittest.cc (renamed from chrome/browser/google_update_settings_linux_unittest.cc)0
7 files changed, 168 insertions, 131 deletions
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index 712d3b1..67069ba 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -57,8 +57,6 @@ bool GetFirstRunSentinelFilePath(FilePath* path) {
} // namespace
-// TODO(port): Mac should share this code.
-#if !defined(OS_MACOSX)
bool FirstRun::IsChromeFirstRun() {
// A troolean, 0 means not yet set, 1 means set to true, 2 set to false.
static int first_run = 0;
@@ -74,7 +72,6 @@ bool FirstRun::IsChromeFirstRun() {
first_run = 1;
return true;
}
-#endif
bool FirstRun::RemoveSentinel() {
FilePath first_run_sentinel;
diff --git a/chrome/browser/first_run_mac.mm b/chrome/browser/first_run_mac.mm
index eef1238..23186b9 100644
--- a/chrome/browser/first_run_mac.mm
+++ b/chrome/browser/first_run_mac.mm
@@ -15,21 +15,83 @@
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
-// static
-bool FirstRun::IsChromeFirstRun() {
- // Use presence of kRegUsageStatsField key as an indicator of whether or not
- // this is the first run.
- // See chrome/browser/google_update_settings_mac.mm for details on why we use
- // the defualts dictionary here.
+//------------------ Start Temporary Code ---------------------
+// The Mac version used to store first run in the user defaults, this has
+// now been moved to the profile directory like other platforms.
+// These functions are here to use for migration, they should be removed
+// in the near future once most people are upgraded.
+// This should be removed after 2 dev release cycles following the checkin
+// of this code, or by 15-Sept-2009. Whichever comes first.
+namespace old_first_run_mac {
+
+const NSString *kOldUsageStatsPrefName = @"usagestats";
+
+// returns true if the first run sentinel is present in the dictionary
+// false if no sentinel is present.
+// |usage_stats_enabled| - Where the usage stats previously enabled?
+bool IsOldChromeFirstRunFromDictionary(NSDictionary *dict,
+ bool *usage_stats_enabled) {
+ *usage_stats_enabled = false;
+
+ // Use presence of kOldUsageStatsPrefName key as an indicator of whether or
+ // not this is the first run.
+ NSNumber* val = [dict objectForKey:kOldUsageStatsPrefName];
+
+ if (val == nil) {
+ return false;
+ }
+
+ if ([val respondsToSelector:@selector(boolValue)]) {
+ *usage_stats_enabled = [val boolValue] ? true : false;
+ }
+
+ return true;
+}
+
+bool IsOldChromeFirstRun(bool *usage_stats_enabled) {
NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
NSDictionary* defaults_dict = [std_defaults dictionaryRepresentation];
- NSString* collect_stats_key = base::SysWideToNSString(
- google_update::kRegUsageStatsField);
- bool not_in_dict = [defaults_dict objectForKey:collect_stats_key] == nil;
- return not_in_dict;
+ return IsOldChromeFirstRunFromDictionary(defaults_dict, usage_stats_enabled);
+}
+
+// Remove the old first run key from the defaults dictionary.
+void RemoveOldFirstRunDefaultsKey() {
+ NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
+ [std_defaults removeObjectForKey:kOldUsageStatsPrefName];
+ [std_defaults synchronize];
}
+// returns:
+// true - If old first run sentinel found and migration was performed.
+// false - no previous first run sentinel found.
+bool MigrateOldFirstRun() {
+ bool usage_stats_enabled = false;
+
+ if (!IsOldChromeFirstRun(&usage_stats_enabled))
+ return false;
+
+ FirstRun::CreateSentinel();
+ GoogleUpdateSettings::SetCollectStatsConsent(usage_stats_enabled);
+
+ // Migrate old first run data.
+#if defined(GOOGLE_CHROME_BUILD)
+ // Breakpad is normally enabled very early in the startup process,
+ // however, on the first run it's off by default. If the user opts-in to
+ // stats, enable breakpad.
+ if (usage_stats_enabled) {
+ InitCrashReporter();
+ InitCrashProcessInfo();
+ }
+#endif // GOOGLE_CHROME_BUILD
+
+ RemoveOldFirstRunDefaultsKey();
+ return true;
+}
+
+} // namespace old_first_run_mac
+//------------------ End Temporary Code ---------------------
+
// Class that handles conducting the first run operation.
// FirstRunController deletes itself when the first run operation ends.
class FirstRunController : public ImportObserver {
@@ -64,7 +126,6 @@ class FirstRunController : public ImportObserver {
bool OpenFirstRunDialog(Profile* profile,
bool homepage_defined,
ProcessSingleton* process_singleton) {
-// OpenFirstRunDialog is a no-op on non-branded builds.
FirstRunController* controller = new FirstRunController;
return controller->DoFirstRun(profile, process_singleton);
}
@@ -95,6 +156,13 @@ bool FirstRunController::DoFirstRun(Profile* profile,
// before this point. Then remove the need for that dialog here.
DCHECK(IsCrashReporterDisabled());
+ //------------------ Start Temporary Code ---------------------
+ // Migrate old first run format.
+ if (old_first_run_mac::MigrateOldFirstRun()) {
+ return true;
+ }
+ //------------------ End Temporary Code ---------------------
+
scoped_nsobject<FirstRunDialogController> dialog(
[[FirstRunDialogController alloc] init]);
@@ -120,9 +188,15 @@ bool FirstRunController::DoFirstRun(Profile* profile,
return false;
}
+ // Don't enable stats in Chromium.
+ bool stats_enabled = false;
#if defined(GOOGLE_CHROME_BUILD)
- BOOL stats_enabled = [dialog.get() statsEnabled];
+ stats_enabled = [dialog.get() statsEnabled] ? true : false;
+#endif // GOOGLE_CHROME_BUILD
+ FirstRun::CreateSentinel();
+ GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled);
+#if defined(GOOGLE_CHROME_BUILD)
// Breakpad is normally enabled very early in the startup process,
// however, on the first run it's off by default. If the user opts-in to
// stats, enable breakpad.
@@ -130,15 +204,8 @@ bool FirstRunController::DoFirstRun(Profile* profile,
InitCrashReporter();
InitCrashProcessInfo();
}
-
-
-#else
- // Don't enable stats in Chromium.
- BOOL stats_enabled = NO;
#endif // GOOGLE_CHROME_BUILD
- GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled);
-
// If selected set as default browser.
BOOL make_default_browser = [dialog.get() makeDefaultBrowser];
if (make_default_browser) {
diff --git a/chrome/browser/first_run_migration_mac_unittest.mm b/chrome/browser/first_run_migration_mac_unittest.mm
new file mode 100644
index 0000000..23955e2
--- /dev/null
+++ b/chrome/browser/first_run_migration_mac_unittest.mm
@@ -0,0 +1,62 @@
+// Copyright (c) 2009 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.
+
+#import <Foundation/Foundation.h>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+// This is a test for temporary code, see chrome/browser/first_run_mac.mm
+// for details.
+
+namespace old_first_run_mac {
+
+bool IsOldChromeFirstRunFromDictionary(NSDictionary *dict,
+ bool *usage_stats_enabled);
+
+extern const NSString *kOldUsageStatsPrefName;
+} // namespace google_update
+
+
+class FirstRunMigrationTest : public PlatformTest {
+};
+
+TEST_F(FirstRunMigrationTest, MigrateOldFirstRunSettings) {
+ using old_first_run_mac::IsOldChromeFirstRunFromDictionary;
+ using old_first_run_mac::kOldUsageStatsPrefName;
+
+ // Stats are off by default.
+ bool stats_on;
+ NSDictionary* empty_dict = [NSDictionary dictionary];
+ EXPECT_FALSE(IsOldChromeFirstRunFromDictionary(empty_dict, &stats_on));
+ EXPECT_FALSE(stats_on);
+
+ // Stats reporting is ON.
+ NSNumber* stats_enabled = [NSNumber numberWithBool:YES];
+ NSDictionary* enabled_dict = [NSDictionary
+ dictionaryWithObject:stats_enabled
+ forKey:kOldUsageStatsPrefName];
+ EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(enabled_dict, &stats_on));
+ EXPECT_TRUE(stats_on);
+
+ // Stats reporting is OFF.
+ stats_enabled = [NSNumber numberWithBool:NO];
+ enabled_dict = [NSDictionary
+ dictionaryWithObject:stats_enabled
+ forKey:kOldUsageStatsPrefName];
+ EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(enabled_dict, &stats_on));
+ EXPECT_FALSE(stats_on);
+
+
+ // If an object of the wrong type is present, we still consider this to
+ // be a first run, but stats reporting is disabled.
+ NSDictionary* wrong_type_dict = [NSDictionary
+ dictionaryWithObject:empty_dict
+ forKey:kOldUsageStatsPrefName];
+ EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(wrong_type_dict, &stats_on));
+ EXPECT_FALSE(stats_on);
+}
diff --git a/chrome/browser/google_update_settings_mac.mm b/chrome/browser/google_update_settings_mac.mm
index 3462b70..d69709f 100644
--- a/chrome/browser/google_update_settings_mac.mm
+++ b/chrome/browser/google_update_settings_mac.mm
@@ -11,55 +11,6 @@
#include "base/sys_string_conversions.h"
#include "chrome/installer/util/google_update_constants.h"
-namespace google_update {
-
-// This is copied from chrome/installer/util/google_update_constants.cc
-// Reasons duplication acceptable:
-// 1. At the time of this writing, this code is a one-off for the dev release.
-// 2. The value of this constant is unlikely to change and even if it does
-// that negates the point of reusing it in the Mac version.
-// 3. To make x-platform usage fo the constants in google_update_constants.cc
-// we probably want to split them up into windows-only and x-platform strings.
-const wchar_t kRegUsageStatsField[] = L"usagestats";
-
-// Declared in a public namespace for testing purposes.
-// If pref not set, assume false.
-bool GetCollectStatsConsentFromDictionary(NSDictionary* dict) {
- NSString* collect_stats_key = base::SysWideToNSString(
- google_update::kRegUsageStatsField);
- NSNumber* val = [dict objectForKey:collect_stats_key];
-
- if (![val respondsToSelector:@selector(boolValue)]) {
- return false;
- }
-
- return ([val boolValue] == YES);
-}
-
-} // namespace google_update
-
-// static
-bool GoogleUpdateSettings::GetCollectStatsConsent() {
- // TODO(mac): This value should be read from the Chrome prefs setting.
- // For Dev-release purposes, we read this value from the user's
- // defaults. This allows easy control of the setting from the terminal.
- // To turn stat reporting off, run the following command from the terminal:
- // $ defaults write com.google.Chrome usagestats -bool 'NO'
- NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
- return google_update::GetCollectStatsConsentFromDictionary(
- [std_defaults dictionaryRepresentation]);
-}
-
-// static
-bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
- NSString* collect_stats_key = base::SysWideToNSString(
- google_update::kRegUsageStatsField);
- NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
- BOOL val_to_store = consented ? YES : NO;
- [std_defaults setBool:val_to_store forKey:collect_stats_key];
- return [std_defaults synchronize];
-}
-
// static
bool GoogleUpdateSettings::GetBrowser(std::wstring* browser) {
NOTIMPLEMENTED();
diff --git a/chrome/browser/google_update_settings_mac_unittest.mm b/chrome/browser/google_update_settings_mac_unittest.mm
deleted file mode 100644
index d24c843..0000000
--- a/chrome/browser/google_update_settings_mac_unittest.mm
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2009 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 <Foundation/Foundation.h>
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/sys_string_conversions.h"
-#include "chrome/installer/util/google_update_constants.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
-
-namespace google_update {
-
-bool GetCollectStatsConsentFromDictionary(NSDictionary* dict);
-
-} // namespace google_update
-
-
-class GoogleUpdateTest : public PlatformTest {
-};
-
-TEST_F(GoogleUpdateTest, StatsConstent) {
- using google_update::GetCollectStatsConsentFromDictionary;
-
- // Stats are off by default.
- NSDictionary* empty_dict = [NSDictionary dictionary];
- ASSERT_FALSE(GetCollectStatsConsentFromDictionary(empty_dict));
-
- NSString* collect_stats_key = base::SysWideToNSString(
- google_update::kRegUsageStatsField);
-
- // Stats reporting is ON.
- NSNumber* stats_enabled = [NSNumber numberWithBool:YES];
- NSDictionary* enabled_dict = [NSDictionary
- dictionaryWithObject:stats_enabled
- forKey:collect_stats_key];
- ASSERT_TRUE(GetCollectStatsConsentFromDictionary(enabled_dict));
-
- // Stats reporting is OFF.
- NSNumber* stats_disabled = [NSNumber numberWithBool:NO];
- NSDictionary* disabled_dict = [NSDictionary
- dictionaryWithObject:stats_disabled
- forKey:collect_stats_key];
- ASSERT_FALSE(GetCollectStatsConsentFromDictionary(disabled_dict));
-
- // Check that we fail gracefully if an object of the wrong type is present.
- NSDictionary* wrong_type_dict = [NSDictionary
- dictionaryWithObject:empty_dict
- forKey:collect_stats_key];
- ASSERT_FALSE(GetCollectStatsConsentFromDictionary(wrong_type_dict));
-}
diff --git a/chrome/browser/google_update_settings_linux.cc b/chrome/browser/google_update_settings_posix.cc
index d05ef09..fd38372 100644
--- a/chrome/browser/google_update_settings_linux.cc
+++ b/chrome/browser/google_update_settings_posix.cc
@@ -11,9 +11,11 @@
#include "base/string_util.h"
#include "chrome/common/chrome_paths.h"
+#if !defined(OS_MACOSX)
namespace google_update {
std::string linux_guid;
}
+#endif // !OS_MACOSX
// File name used in the user data dir to indicate consent.
static const char kConsentToSendStats[] = "Consent To Send Stats";
@@ -21,17 +23,28 @@ static const int kGuidLen = sizeof(uint64) * 4; // 128 bits -> 32 bytes hex.
// static
bool GoogleUpdateSettings::GetCollectStatsConsent() {
+#if defined(OS_MACOSX)
+ std::string linux_guid;
+#else
+ using google_update::linux_guid;
+#endif // OS_MACOSX
FilePath consent_file;
PathService::Get(chrome::DIR_USER_DATA, &consent_file);
consent_file = consent_file.Append(kConsentToSendStats);
bool r = file_util::ReadFileToString(consent_file,
- &google_update::linux_guid);
- google_update::linux_guid.resize(kGuidLen, '0');
+ &linux_guid);
+ linux_guid.resize(kGuidLen, '0');
return r;
}
// static
bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
+#if defined(OS_MACOSX)
+ std::string linux_guid;
+#else
+ using google_update::linux_guid;
+#endif // OS_MACOSX
+
FilePath consent_dir;
PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
if (!file_util::DirectoryExists(consent_dir))
@@ -40,17 +53,17 @@ bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats);
if (consented) {
uint64 random;
- google_update::linux_guid.clear();
+ linux_guid.clear();
for (int i = 0; i < 2; i++) {
random = base::RandUint64();
- google_update::linux_guid += HexEncode(&random, sizeof(uint64));
+ linux_guid += HexEncode(&random, sizeof(uint64));
}
- const char* c_str = google_update::linux_guid.c_str();
+ const char* c_str = linux_guid.c_str();
return file_util::WriteFile(consent_file, c_str, kGuidLen) == kGuidLen;
}
else {
- google_update::linux_guid .clear();
- google_update::linux_guid.resize(kGuidLen, '0');
+ linux_guid .clear();
+ linux_guid.resize(kGuidLen, '0');
return file_util::Delete(consent_file, false);
}
}
diff --git a/chrome/browser/google_update_settings_linux_unittest.cc b/chrome/browser/google_update_settings_posix_unittest.cc
index 35f956a..35f956a 100644
--- a/chrome/browser/google_update_settings_linux_unittest.cc
+++ b/chrome/browser/google_update_settings_posix_unittest.cc