diff options
Diffstat (limited to 'chrome/browser/first_run/first_run_mac.mm')
-rw-r--r-- | chrome/browser/first_run/first_run_mac.mm | 179 |
1 files changed, 67 insertions, 112 deletions
diff --git a/chrome/browser/first_run/first_run_mac.mm b/chrome/browser/first_run/first_run_mac.mm index 0795bce..3159e9d 100644 --- a/chrome/browser/first_run/first_run_mac.mm +++ b/chrome/browser/first_run/first_run_mac.mm @@ -5,110 +5,50 @@ #include "chrome/browser/first_run/first_run.h" #import "base/scoped_nsobject.h" -#include "base/sys_string_conversions.h" #import "chrome/app/breakpad_mac.h" #import "chrome/browser/cocoa/first_run_dialog.h" -#import "chrome/browser/cocoa/import_progress_dialog.h" -#include "chrome/browser/importer/importer.h" -#include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/metrics/user_metrics.h" +#import "chrome/browser/cocoa/search_engine_dialog_controller.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/shell_integration.h" +#include "chrome/common/pref_names.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_update_settings.h" -// Class that handles conducting the first run operation. -// FirstRunController deletes itself when the first run operation ends. -class FirstRunController : public ImportObserver { - public: - explicit FirstRunController(); - virtual ~FirstRunController() {} +namespace { - // Overridden methods from ImportObserver. - virtual void ImportCanceled() { - FirstRunDone(); - } - virtual void ImportComplete() { - FirstRunDone(); - } - - // Display first run UI, start the import and return when it's all over. - bool DoFirstRun(Profile* profile, ProcessSingleton* process_singleton); - - private: - // This method closes the first run window and quits the message loop so that - // the Chrome startup can continue. This should be called when all the - // first run tasks are done. - void FirstRunDone(); - - scoped_refptr<ImporterHost> importer_host_; - - DISALLOW_COPY_AND_ASSIGN(FirstRunController); -}; - - -bool OpenFirstRunDialog(Profile* profile, - bool homepage_defined, - int import_items, - int dont_import_items, - bool search_engine_experiment, - bool randomize_search_engine_experiment, - ProcessSingleton* process_singleton) { - FirstRunController* controller = new FirstRunController; - return controller->DoFirstRun(profile, process_singleton); -} - -FirstRunController::FirstRunController() - : importer_host_(new ExternalProcessImporterHost) { -} - -void FirstRunController::FirstRunDone() { - // Set preference to show first run bubble and welcome page. - FirstRun::SetShowFirstRunBubblePref(true); - FirstRun::SetShowWelcomePagePref(); -} - -bool FirstRunController::DoFirstRun(Profile* profile, - ProcessSingleton* process_singleton) { - // This object is responsible for deleting itself, make sure that happens. - scoped_ptr<FirstRunController> gc(this); - - scoped_nsobject<FirstRunDialogController> dialog( - [[FirstRunDialogController alloc] init]); +// Show the search engine selection dialog. +void ShowSearchEngineSelectionDialog(Profile* profile, + bool randomize_search_engine_experiment) { + scoped_nsobject<SearchEngineDialogController> dialog( + [[SearchEngineDialogController alloc] init]); + [dialog.get() setProfile:profile]; + [dialog.get() setRandomize:randomize_search_engine_experiment]; - // Set list of browsers we know how to import. - ssize_t profiles_count = importer_host_->GetAvailableProfileCount(); - - // TODO(jeremy): Test on newly created account. - // TODO(jeremy): Correctly handle case where no browsers to import from - // are detected. - NSMutableArray *browsers = [NSMutableArray arrayWithCapacity:profiles_count]; - for (int i = 0; i < profiles_count; ++i) { - std::wstring profile = importer_host_->GetSourceProfileNameAt(i); - [browsers addObject:base::SysWideToNSString(profile)]; - } - [dialog.get() setBrowserImportList:browsers]; - - BOOL browser_import_disabled = profiles_count == 0; - [dialog.get() setBrowserImportListHidden:browser_import_disabled]; - - // FirstRunDialogController will call exit if "Cancel" is clicked. [dialog.get() showWindow:nil]; +} - // If user clicked cancel, bail - browser_main will return if we haven't - // turned off the first run flag when this function returns. - if ([dialog.get() userDidCancel]) { - return false; - } - - FirstRun::CreateSentinel(); - - // If the dialog asked the user to opt-in for stats and crash reporting, - // record the decision and enable the crash reporter if appropriate. - if (![dialog.get() statsCheckboxHidden]) { +// Show the first run UI. +void ShowFirstRun(Profile* profile) { +#if defined(GOOGLE_CHROME_BUILD) + // The purpose of the dialog is to ask the user to enable stats and crash + // reporting. This setting may be controlled through configuration management + // in enterprise scenarios. If that is the case, skip the dialog entirely, as + // it's not worth bothering the user for only the default browser question + // (which is likely to be forced in enterprise deployments anyway). + const PrefService::Preference* metrics_reporting_pref = + g_browser_process->local_state()->FindPreference( + prefs::kMetricsReportingEnabled); + if (!metrics_reporting_pref || !metrics_reporting_pref->IsManaged()) { + scoped_nsobject<FirstRunDialogController> dialog( + [[FirstRunDialogController alloc] init]); + + [dialog.get() showWindow:nil]; + + // If the dialog asked the user to opt-in for stats and crash reporting, + // record the decision and enable the crash reporter if appropriate. bool stats_enabled = [dialog.get() statsEnabled]; 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 may not have been enabled due to the missing opt-in // from the user. If the user agreed now, enable breakpad if necessary. @@ -116,33 +56,48 @@ bool FirstRunController::DoFirstRun(Profile* profile, InitCrashReporter(); InitCrashProcessInfo(); } -#endif // GOOGLE_CHROME_BUILD - } - // If selected set as default browser. - BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; - if (make_default_browser) { - bool success = ShellIntegration::SetAsDefaultBrowser(); - DCHECK(success); + // If selected set as default browser. + BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; + if (make_default_browser) { + bool success = ShellIntegration::SetAsDefaultBrowser(); + DCHECK(success); + } } +#else // GOOGLE_CHROME_BUILD + // We don't show the dialog in Chromium. +#endif // GOOGLE_CHROME_BUILD - // Import bookmarks. - if (!browser_import_disabled && [dialog.get() importBookmarks]) { - const importer::ProfileInfo& source_profile = importer_host_-> - GetSourceProfileInfoAt([dialog.get() browserImportSelectedIndex]); - int16 items = source_profile.services_supported; - // TODO(port): Do the actual import in a new process like Windows. - ignore_result(gc.release()); - StartImportingWithUI(nil, items, importer_host_.get(), - source_profile, profile, this, true); - } else { - // This is called by the importer if it runs. - FirstRunDone(); - } + FirstRun::CreateSentinel(); - return true; + // Set preference to show first run bubble and welcome page. + FirstRun::SetShowFirstRunBubblePref(true); + FirstRun::SetShowWelcomePagePref(); +} + +} // namespace + +// static +void FirstRun::ShowFirstRunDialog(Profile* profile, + bool randomize_search_engine_experiment) { + ShowSearchEngineSelectionDialog(profile, + randomize_search_engine_experiment); + ShowFirstRun(profile); } + bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { // http://crbug.com/48880 return false; } + +// static +bool FirstRun::IsOrganic() { + // We treat all installs as organic. + return true; +} + +// static +void FirstRun::PlatformSetup() { + // Things that Windows does here (creating a desktop icon, for example) are + // not needed. +} |