Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/first_run.h" | 5 #include "chrome/browser/first_run.h" |
| 6 | 6 |
| 7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #import "chrome/app/breakpad_mac.h" | 9 #import "chrome/app/breakpad_mac.h" |
| 10 #import "chrome/browser/cocoa/first_run_dialog.h" | 10 #import "chrome/browser/cocoa/first_run_dialog.h" |
| 11 #import "chrome/browser/cocoa/import_progress_dialog.h" | 11 #import "chrome/browser/cocoa/import_progress_dialog.h" |
| 12 #include "chrome/browser/importer/importer.h" | 12 #include "chrome/browser/importer/importer.h" |
| 13 #include "chrome/browser/metrics/user_metrics.h" | 13 #include "chrome/browser/metrics/user_metrics.h" |
| 14 #include "chrome/browser/shell_integration.h" | 14 #include "chrome/browser/shell_integration.h" |
| 15 #include "chrome/installer/util/google_update_constants.h" | 15 #include "chrome/installer/util/google_update_constants.h" |
| 16 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_settings.h" |
| 17 | 17 |
| 18 // static | 18 //------------------ Start Temporary Code --------------------- |
| 19 bool FirstRun::IsChromeFirstRun() { | 19 // The Mac version used to store first run in the user defaults, this has |
| 20 // Use presence of kRegUsageStatsField key as an indicator of whether or not | 20 // now been moved to the profile directory like other platforms. |
| 21 // this is the first run. | 21 // These functions are here to use for migration, they should be removed |
| 22 // See chrome/browser/google_update_settings_mac.mm for details on why we use | 22 // 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
| |
| 23 // the defualts dictionary here. | 23 namespace old_first_run_mac { |
| 24 | |
| 25 const NSString *kOldUsageStatsPrefName = @"usagestats"; | |
| 26 | |
| 27 // returns - is this the first run? | |
|
Mark Mentovai
2009/08/18 21:51:48
What's this mean?
| |
| 28 // |usage_stats_enabled| - Where the usage stats previously enabled? | |
| 29 bool IsOldChromeFirstRunFromDictionary(NSDictionary *dict, | |
| 30 bool *usage_stats_enabled) { | |
| 31 *usage_stats_enabled = false; | |
| 32 | |
| 33 // Use presence of kOldUsageStatsPrefName key as an indicator of whether or | |
| 34 // not this is the first run. | |
| 35 NSNumber* val = [dict objectForKey:kOldUsageStatsPrefName]; | |
| 36 | |
| 37 if (val == nil) { | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 if ([val respondsToSelector:@selector(boolValue)]) { | |
| 42 *usage_stats_enabled = [val boolValue] ? true : false; | |
| 43 } | |
| 44 | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 bool IsOldChromeFirstRun(bool *usage_stats_enabled) { | |
| 24 NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults]; | 49 NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults]; |
| 25 NSDictionary* defaults_dict = [std_defaults dictionaryRepresentation]; | 50 NSDictionary* defaults_dict = [std_defaults dictionaryRepresentation]; |
| 26 NSString* collect_stats_key = base::SysWideToNSString( | |
| 27 google_update::kRegUsageStatsField); | |
| 28 | 51 |
| 29 bool not_in_dict = [defaults_dict objectForKey:collect_stats_key] == nil; | 52 return IsOldChromeFirstRunFromDictionary(defaults_dict, usage_stats_enabled); |
| 30 return not_in_dict; | |
| 31 } | 53 } |
| 32 | 54 |
| 55 // Remove the old first run key from the defaults dictionary. | |
| 56 void RemoveOldFirstRunDefaultsKey() { | |
| 57 NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults]; | |
| 58 [std_defaults removeObjectForKey:kOldUsageStatsPrefName]; | |
| 59 [std_defaults synchronize]; | |
| 60 } | |
| 61 | |
| 62 // 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
| |
| 63 // information found. | |
| 64 bool MigrateOldFirstRun() { | |
| 65 bool usage_stats_enabled = false; | |
| 66 | |
| 67 if (!IsOldChromeFirstRun(&usage_stats_enabled)) | |
| 68 return false; | |
| 69 | |
| 70 FirstRun::CreateSentinel(); | |
| 71 GoogleUpdateSettings::SetCollectStatsConsent(usage_stats_enabled); | |
| 72 | |
| 73 // Migrate old first run data. | |
| 74 #if defined(GOOGLE_CHROME_BUILD) | |
| 75 // Breakpad is normally enabled very early in the startup process, | |
| 76 // however, on the first run it's off by default. If the user opts-in to | |
| 77 // stats, enable breakpad. | |
| 78 if (usage_stats_enabled) { | |
| 79 InitCrashReporter(); | |
| 80 InitCrashProcessInfo(); | |
| 81 } | |
| 82 #endif // GOOGLE_CHROME_BUILD | |
| 83 | |
| 84 RemoveOldFirstRunDefaultsKey(); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 } // namespace old_first_run_mac | |
| 89 //------------------ End Temporary Code --------------------- | |
| 90 | |
| 33 // Class that handles conducting the first run operation. | 91 // Class that handles conducting the first run operation. |
| 34 // FirstRunController deletes itself when the first run operation ends. | 92 // FirstRunController deletes itself when the first run operation ends. |
| 35 class FirstRunController : public ImportObserver { | 93 class FirstRunController : public ImportObserver { |
| 36 public: | 94 public: |
| 37 explicit FirstRunController(); | 95 explicit FirstRunController(); |
| 38 virtual ~FirstRunController() {} | 96 virtual ~FirstRunController() {} |
| 39 | 97 |
| 40 // Overridden methods from ImportObserver. | 98 // Overridden methods from ImportObserver. |
| 41 virtual void ImportCanceled() { | 99 virtual void ImportCanceled() { |
| 42 FirstRunDone(); | 100 FirstRunDone(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 | 115 |
| 58 scoped_refptr<ImporterHost> importer_host_; | 116 scoped_refptr<ImporterHost> importer_host_; |
| 59 | 117 |
| 60 DISALLOW_COPY_AND_ASSIGN(FirstRunController); | 118 DISALLOW_COPY_AND_ASSIGN(FirstRunController); |
| 61 }; | 119 }; |
| 62 | 120 |
| 63 | 121 |
| 64 bool OpenFirstRunDialog(Profile* profile, | 122 bool OpenFirstRunDialog(Profile* profile, |
| 65 bool homepage_defined, | 123 bool homepage_defined, |
| 66 ProcessSingleton* process_singleton) { | 124 ProcessSingleton* process_singleton) { |
| 67 // OpenFirstRunDialog is a no-op on non-branded builds. | |
| 68 FirstRunController* controller = new FirstRunController; | 125 FirstRunController* controller = new FirstRunController; |
| 69 return controller->DoFirstRun(profile, process_singleton); | 126 return controller->DoFirstRun(profile, process_singleton); |
| 70 } | 127 } |
| 71 | 128 |
| 72 FirstRunController::FirstRunController() | 129 FirstRunController::FirstRunController() |
| 73 : importer_host_(new ImporterHost) { | 130 : importer_host_(new ImporterHost) { |
| 74 } | 131 } |
| 75 | 132 |
| 76 void FirstRunController::FirstRunDone() { | 133 void FirstRunController::FirstRunDone() { |
| 77 // Set preference to show first run bubble and welcome page. | 134 // Set preference to show first run bubble and welcome page. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 88 scoped_ptr<FirstRunController> gc(this); | 145 scoped_ptr<FirstRunController> gc(this); |
| 89 | 146 |
| 90 // Breakpad should not be enabled on first run until the user has explicitly | 147 // Breakpad should not be enabled on first run until the user has explicitly |
| 91 // opted-into stats. | 148 // opted-into stats. |
| 92 // TODO: The behavior we probably want here is to enable Breakpad on first run | 149 // TODO: The behavior we probably want here is to enable Breakpad on first run |
| 93 // but display a confirmation dialog before sending a crash report so we | 150 // but display a confirmation dialog before sending a crash report so we |
| 94 // respect a user's privacy while still getting any crashes that might happen | 151 // respect a user's privacy while still getting any crashes that might happen |
| 95 // before this point. Then remove the need for that dialog here. | 152 // before this point. Then remove the need for that dialog here. |
| 96 DCHECK(IsCrashReporterDisabled()); | 153 DCHECK(IsCrashReporterDisabled()); |
| 97 | 154 |
| 155 //------------------ Start Temporary Code --------------------- | |
| 156 // Migrate old first run format. | |
| 157 if (old_first_run_mac::MigrateOldFirstRun()) { | |
| 158 return true; | |
| 159 } | |
| 160 //------------------ End Temporary Code --------------------- | |
| 161 | |
| 98 scoped_nsobject<FirstRunDialogController> dialog( | 162 scoped_nsobject<FirstRunDialogController> dialog( |
| 99 [[FirstRunDialogController alloc] init]); | 163 [[FirstRunDialogController alloc] init]); |
| 100 | 164 |
| 101 // Set list of browsers we know how to import. | 165 // Set list of browsers we know how to import. |
| 102 ssize_t profiles_count = importer_host_->GetAvailableProfileCount(); | 166 ssize_t profiles_count = importer_host_->GetAvailableProfileCount(); |
| 103 | 167 |
| 104 // TODO(jeremy): Test on newly created account. | 168 // TODO(jeremy): Test on newly created account. |
| 105 // TODO(jeremy): Correctly handle case where no browsers to import from | 169 // TODO(jeremy): Correctly handle case where no browsers to import from |
| 106 // are detected. | 170 // are detected. |
| 107 NSMutableArray *browsers = [NSMutableArray arrayWithCapacity:profiles_count]; | 171 NSMutableArray *browsers = [NSMutableArray arrayWithCapacity:profiles_count]; |
| 108 for (int i = 0; i < profiles_count; ++i) { | 172 for (int i = 0; i < profiles_count; ++i) { |
| 109 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); | 173 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); |
| 110 [browsers addObject:base::SysWideToNSString(profile)]; | 174 [browsers addObject:base::SysWideToNSString(profile)]; |
| 111 } | 175 } |
| 112 [dialog.get() setBrowserImportList:browsers]; | 176 [dialog.get() setBrowserImportList:browsers]; |
| 113 | 177 |
| 114 // FirstRunDialogController will call exit if "Cancel" is clicked. | 178 // FirstRunDialogController will call exit if "Cancel" is clicked. |
| 115 [dialog.get() showWindow:nil]; | 179 [dialog.get() showWindow:nil]; |
| 116 | 180 |
| 117 // If user clicked cancel, bail - browser_main will return if we haven't | 181 // If user clicked cancel, bail - browser_main will return if we haven't |
| 118 // turned off the first run flag when this function returns. | 182 // turned off the first run flag when this function returns. |
| 119 if ([dialog.get() userDidCancel]) { | 183 if ([dialog.get() userDidCancel]) { |
| 120 return false; | 184 return false; |
| 121 } | 185 } |
| 122 | 186 |
| 187 bool stats_enabled = false; | |
| 123 #if defined(GOOGLE_CHROME_BUILD) | 188 #if defined(GOOGLE_CHROME_BUILD) |
| 124 BOOL stats_enabled = [dialog.get() statsEnabled]; | 189 stats_enabled = [dialog.get() statsEnabled] ? true : false; |
| 190 #else | |
|
Mark Mentovai
2009/08/18 21:51:48
I'd just leave the #else out. You can keep the co
| |
| 191 // Don't enable stats in Chromium. | |
| 192 #endif // GOOGLE_CHROME_BUILD | |
| 193 FirstRun::CreateSentinel(); | |
| 194 GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled); | |
| 125 | 195 |
| 196 #if defined(GOOGLE_CHROME_BUILD) | |
| 126 // Breakpad is normally enabled very early in the startup process, | 197 // Breakpad is normally enabled very early in the startup process, |
| 127 // however, on the first run it's off by default. If the user opts-in to | 198 // however, on the first run it's off by default. If the user opts-in to |
| 128 // stats, enable breakpad. | 199 // stats, enable breakpad. |
| 129 if (stats_enabled) { | 200 if (stats_enabled) { |
| 130 InitCrashReporter(); | 201 InitCrashReporter(); |
| 131 InitCrashProcessInfo(); | 202 InitCrashProcessInfo(); |
| 132 } | 203 } |
| 133 | |
| 134 | |
| 135 #else | |
| 136 // Don't enable stats in Chromium. | |
| 137 BOOL stats_enabled = NO; | |
| 138 #endif // GOOGLE_CHROME_BUILD | 204 #endif // GOOGLE_CHROME_BUILD |
| 139 | 205 |
| 140 GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled); | |
| 141 | |
| 142 // If selected set as default browser. | 206 // If selected set as default browser. |
| 143 BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; | 207 BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; |
| 144 if (make_default_browser) { | 208 if (make_default_browser) { |
| 145 bool success = ShellIntegration::SetAsDefaultBrowser(); | 209 bool success = ShellIntegration::SetAsDefaultBrowser(); |
| 146 DCHECK(success); | 210 DCHECK(success); |
| 147 } | 211 } |
| 148 | 212 |
| 149 // Import bookmarks. | 213 // Import bookmarks. |
| 150 if ([dialog.get() importBookmarks]) { | 214 if ([dialog.get() importBookmarks]) { |
| 151 const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( | 215 const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( |
| 152 [dialog.get() browserImportSelectedIndex]); | 216 [dialog.get() browserImportSelectedIndex]); |
| 153 int16 items = source_profile.services_supported; | 217 int16 items = source_profile.services_supported; |
| 154 // TODO(port): Do the actual import in a new process like Windows. | 218 // TODO(port): Do the actual import in a new process like Windows. |
| 155 gc.release(); | 219 gc.release(); |
| 156 StartImportingWithUI(nil, items, importer_host_.get(), | 220 StartImportingWithUI(nil, items, importer_host_.get(), |
| 157 source_profile, profile, this, true); | 221 source_profile, profile, this, true); |
| 158 } | 222 } |
| 159 | 223 |
| 160 return true; | 224 return true; |
| 161 } | 225 } |
| OLD | NEW |