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

Unified Diff: chrome/browser/first_run_mac.mm

Issue 173020: Make Mac first run store sentinel in Profile directory. (Closed)
Patch Set: spelling Created 11 years, 4 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_mac.mm
diff --git a/chrome/browser/first_run_mac.mm b/chrome/browser/first_run_mac.mm
index eef12380679675fea9bb0f1b414c72009f3af86e..ac4946675c9fbb730da5dede3dd7b7655a906912 100644
--- a/chrome/browser/first_run_mac.mm
+++ b/chrome/browser/first_run_mac.mm
@@ -15,21 +15,79 @@
#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.
Mark Mentovai 2009/08/18 21:51:48 Put a TODO on it. Put specific conditions for rem
+namespace old_first_run_mac {
+
+const NSString *kOldUsageStatsPrefName = @"usagestats";
+
+// returns - is this the first run?
Mark Mentovai 2009/08/18 21:51:48 What's this mean?
+// |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 - performed migration, false - no previous first run
Mark Mentovai 2009/08/18 21:51:48 Use complete sentences, especially when you're des
+// information 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 +122,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 +152,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 +184,16 @@ bool FirstRunController::DoFirstRun(Profile* profile,
return false;
}
+ bool stats_enabled = false;
#if defined(GOOGLE_CHROME_BUILD)
- BOOL stats_enabled = [dialog.get() statsEnabled];
+ stats_enabled = [dialog.get() statsEnabled] ? true : false;
+#else
Mark Mentovai 2009/08/18 21:51:48 I'd just leave the #else out. You can keep the co
+ // Don't enable stats in Chromium.
+#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 +201,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) {

Powered by Google App Engine
This is Rietveld 408576698