OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/first_run.h" | 5 #include "chrome/browser/first_run/first_run.h" |
6 | 6 |
7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
8 #include "base/sys_string_conversions.h" | |
9 #import "chrome/app/breakpad_mac.h" | 8 #import "chrome/app/breakpad_mac.h" |
10 #import "chrome/browser/cocoa/first_run_dialog.h" | 9 #import "chrome/browser/cocoa/first_run_dialog.h" |
11 #import "chrome/browser/cocoa/import_progress_dialog.h" | 10 #import "chrome/browser/cocoa/search_engine_dialog_controller.h" |
12 #include "chrome/browser/importer/importer.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/importer/importer_data_types.h" | |
14 #include "chrome/browser/metrics/user_metrics.h" | |
15 #include "chrome/browser/shell_integration.h" | 12 #include "chrome/browser/shell_integration.h" |
| 13 #include "chrome/common/pref_names.h" |
16 #include "chrome/installer/util/google_update_constants.h" | 14 #include "chrome/installer/util/google_update_constants.h" |
17 #include "chrome/installer/util/google_update_settings.h" | 15 #include "chrome/installer/util/google_update_settings.h" |
18 | 16 |
19 // Class that handles conducting the first run operation. | 17 namespace { |
20 // FirstRunController deletes itself when the first run operation ends. | |
21 class FirstRunController : public ImportObserver { | |
22 public: | |
23 explicit FirstRunController(); | |
24 virtual ~FirstRunController() {} | |
25 | 18 |
26 // Overridden methods from ImportObserver. | 19 // Show the search engine selection dialog. |
27 virtual void ImportCanceled() { | 20 void ShowSearchEngineSelectionDialog(Profile* profile, |
28 FirstRunDone(); | 21 bool randomize_search_engine_experiment) { |
29 } | 22 scoped_nsobject<SearchEngineDialogController> dialog( |
30 virtual void ImportComplete() { | 23 [[SearchEngineDialogController alloc] init]); |
31 FirstRunDone(); | 24 [dialog.get() setProfile:profile]; |
32 } | 25 [dialog.get() setRandomize:randomize_search_engine_experiment]; |
33 | 26 |
34 // Display first run UI, start the import and return when it's all over. | 27 [dialog.get() showWindow:nil]; |
35 bool DoFirstRun(Profile* profile, ProcessSingleton* process_singleton); | |
36 | |
37 private: | |
38 // This method closes the first run window and quits the message loop so that | |
39 // the Chrome startup can continue. This should be called when all the | |
40 // first run tasks are done. | |
41 void FirstRunDone(); | |
42 | |
43 scoped_refptr<ImporterHost> importer_host_; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(FirstRunController); | |
46 }; | |
47 | |
48 | |
49 bool OpenFirstRunDialog(Profile* profile, | |
50 bool homepage_defined, | |
51 int import_items, | |
52 int dont_import_items, | |
53 bool search_engine_experiment, | |
54 bool randomize_search_engine_experiment, | |
55 ProcessSingleton* process_singleton) { | |
56 FirstRunController* controller = new FirstRunController; | |
57 return controller->DoFirstRun(profile, process_singleton); | |
58 } | 28 } |
59 | 29 |
60 FirstRunController::FirstRunController() | 30 // Show the first run UI. |
61 : importer_host_(new ExternalProcessImporterHost) { | 31 void ShowFirstRun(Profile* profile) { |
62 } | 32 #if defined(GOOGLE_CHROME_BUILD) |
| 33 // The purpose of the dialog is to ask the user to enable stats and crash |
| 34 // reporting. This setting may be controlled through configuration management |
| 35 // in enterprise scenarios. If that is the case, skip the dialog entirely, as |
| 36 // it's not worth bothering the user for only the default browser question |
| 37 // (which is likely to be forced in enterprise deployments anyway). |
| 38 const PrefService::Preference* metrics_reporting_pref = |
| 39 g_browser_process->local_state()->FindPreference( |
| 40 prefs::kMetricsReportingEnabled); |
| 41 if (!metrics_reporting_pref || !metrics_reporting_pref->IsManaged()) { |
| 42 scoped_nsobject<FirstRunDialogController> dialog( |
| 43 [[FirstRunDialogController alloc] init]); |
63 | 44 |
64 void FirstRunController::FirstRunDone() { | 45 [dialog.get() showWindow:nil]; |
65 // Set preference to show first run bubble and welcome page. | |
66 FirstRun::SetShowFirstRunBubblePref(true); | |
67 FirstRun::SetShowWelcomePagePref(); | |
68 } | |
69 | 46 |
70 bool FirstRunController::DoFirstRun(Profile* profile, | 47 // If the dialog asked the user to opt-in for stats and crash reporting, |
71 ProcessSingleton* process_singleton) { | 48 // record the decision and enable the crash reporter if appropriate. |
72 // This object is responsible for deleting itself, make sure that happens. | |
73 scoped_ptr<FirstRunController> gc(this); | |
74 | |
75 scoped_nsobject<FirstRunDialogController> dialog( | |
76 [[FirstRunDialogController alloc] init]); | |
77 | |
78 // Set list of browsers we know how to import. | |
79 ssize_t profiles_count = importer_host_->GetAvailableProfileCount(); | |
80 | |
81 // TODO(jeremy): Test on newly created account. | |
82 // TODO(jeremy): Correctly handle case where no browsers to import from | |
83 // are detected. | |
84 NSMutableArray *browsers = [NSMutableArray arrayWithCapacity:profiles_count]; | |
85 for (int i = 0; i < profiles_count; ++i) { | |
86 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); | |
87 [browsers addObject:base::SysWideToNSString(profile)]; | |
88 } | |
89 [dialog.get() setBrowserImportList:browsers]; | |
90 | |
91 BOOL browser_import_disabled = profiles_count == 0; | |
92 [dialog.get() setBrowserImportListHidden:browser_import_disabled]; | |
93 | |
94 // FirstRunDialogController will call exit if "Cancel" is clicked. | |
95 [dialog.get() showWindow:nil]; | |
96 | |
97 // If user clicked cancel, bail - browser_main will return if we haven't | |
98 // turned off the first run flag when this function returns. | |
99 if ([dialog.get() userDidCancel]) { | |
100 return false; | |
101 } | |
102 | |
103 FirstRun::CreateSentinel(); | |
104 | |
105 // If the dialog asked the user to opt-in for stats and crash reporting, | |
106 // record the decision and enable the crash reporter if appropriate. | |
107 if (![dialog.get() statsCheckboxHidden]) { | |
108 bool stats_enabled = [dialog.get() statsEnabled]; | 49 bool stats_enabled = [dialog.get() statsEnabled]; |
109 GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled); | 50 GoogleUpdateSettings::SetCollectStatsConsent(stats_enabled); |
110 | 51 |
111 #if defined(GOOGLE_CHROME_BUILD) | |
112 // Breakpad is normally enabled very early in the startup process. However, | 52 // Breakpad is normally enabled very early in the startup process. However, |
113 // on the first run it may not have been enabled due to the missing opt-in | 53 // on the first run it may not have been enabled due to the missing opt-in |
114 // from the user. If the user agreed now, enable breakpad if necessary. | 54 // from the user. If the user agreed now, enable breakpad if necessary. |
115 if (!IsCrashReporterEnabled() && stats_enabled) { | 55 if (!IsCrashReporterEnabled() && stats_enabled) { |
116 InitCrashReporter(); | 56 InitCrashReporter(); |
117 InitCrashProcessInfo(); | 57 InitCrashProcessInfo(); |
118 } | 58 } |
| 59 |
| 60 // If selected set as default browser. |
| 61 BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; |
| 62 if (make_default_browser) { |
| 63 bool success = ShellIntegration::SetAsDefaultBrowser(); |
| 64 DCHECK(success); |
| 65 } |
| 66 } |
| 67 #else // GOOGLE_CHROME_BUILD |
| 68 // We don't show the dialog in Chromium. |
119 #endif // GOOGLE_CHROME_BUILD | 69 #endif // GOOGLE_CHROME_BUILD |
120 } | |
121 | 70 |
122 // If selected set as default browser. | 71 FirstRun::CreateSentinel(); |
123 BOOL make_default_browser = [dialog.get() makeDefaultBrowser]; | |
124 if (make_default_browser) { | |
125 bool success = ShellIntegration::SetAsDefaultBrowser(); | |
126 DCHECK(success); | |
127 } | |
128 | 72 |
129 // Import bookmarks. | 73 // Set preference to show first run bubble and welcome page. |
130 if (!browser_import_disabled && [dialog.get() importBookmarks]) { | 74 FirstRun::SetShowFirstRunBubblePref(true); |
131 const importer::ProfileInfo& source_profile = importer_host_-> | 75 FirstRun::SetShowWelcomePagePref(); |
132 GetSourceProfileInfoAt([dialog.get() browserImportSelectedIndex]); | 76 } |
133 int16 items = source_profile.services_supported; | |
134 // TODO(port): Do the actual import in a new process like Windows. | |
135 ignore_result(gc.release()); | |
136 StartImportingWithUI(nil, items, importer_host_.get(), | |
137 source_profile, profile, this, true); | |
138 } else { | |
139 // This is called by the importer if it runs. | |
140 FirstRunDone(); | |
141 } | |
142 | 77 |
143 return true; | 78 } // namespace |
| 79 |
| 80 // static |
| 81 void FirstRun::ShowFirstRunDialog(Profile* profile, |
| 82 bool randomize_search_engine_experiment) { |
| 83 ShowSearchEngineSelectionDialog(profile, |
| 84 randomize_search_engine_experiment); |
| 85 ShowFirstRun(profile); |
144 } | 86 } |
| 87 |
145 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { | 88 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { |
146 // http://crbug.com/48880 | 89 // http://crbug.com/48880 |
147 return false; | 90 return false; |
148 } | 91 } |
| 92 |
| 93 // static |
| 94 bool FirstRun::IsOrganic() { |
| 95 // We treat all installs as organic. |
| 96 return true; |
| 97 } |
| 98 |
| 99 // static |
| 100 void FirstRun::PlatformSetup() { |
| 101 // Things that Windows does here (creating a desktop icon, for example) are |
| 102 // not needed. |
| 103 } |
OLD | NEW |