| 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 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 // TODO(port): move more code in back from the first_run_win.cc module. | 9 // TODO(port): move more code in back from the first_run_win.cc module. |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/process_singleton.h" | 23 #include "chrome/browser/process_singleton.h" |
| 24 #include "chrome/browser/profile_manager.h" | 24 #include "chrome/browser/profile_manager.h" |
| 25 #include "chrome/browser/search_engines/template_url_model.h" | 25 #include "chrome/browser/search_engines/template_url_model.h" |
| 26 #include "chrome/browser/shell_integration.h" | 26 #include "chrome/browser/shell_integration.h" |
| 27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/installer/util/master_preferences.h" | 30 #include "chrome/installer/util/master_preferences.h" |
| 31 #include "chrome/installer/util/master_preferences_constants.h" |
| 31 #include "chrome/installer/util/util_constants.h" | 32 #include "chrome/installer/util/util_constants.h" |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // The kSentinelFile file absence will tell us it is a first run. | 36 // The kSentinelFile file absence will tell us it is a first run. |
| 36 const char kSentinelFile[] = "First Run"; | 37 const char kSentinelFile[] = "First Run"; |
| 37 | 38 |
| 38 FilePath GetDefaultPrefFilePath(bool create_profile_dir, | 39 FilePath GetDefaultPrefFilePath(bool create_profile_dir, |
| 39 const FilePath& user_data_dir) { | 40 const FilePath& user_data_dir) { |
| 40 FilePath default_pref_dir = | 41 FilePath default_pref_dir = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, | 89 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, |
| 89 MasterPrefs* out_prefs) { | 90 MasterPrefs* out_prefs) { |
| 90 DCHECK(!user_data_dir.empty()); | 91 DCHECK(!user_data_dir.empty()); |
| 91 | 92 |
| 92 // The standard location of the master prefs is next to the chrome binary. | 93 // The standard location of the master prefs is next to the chrome binary. |
| 93 FilePath master_prefs; | 94 FilePath master_prefs; |
| 94 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 95 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
| 95 return true; | 96 return true; |
| 96 master_prefs = master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); | 97 master_prefs = master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); |
| 97 | 98 |
| 98 scoped_ptr<DictionaryValue> prefs( | 99 installer_util::MasterPreferences prefs(master_prefs); |
| 99 installer_util::ParseDistributionPreferences(master_prefs)); | 100 if (!prefs.read_from_file()) |
| 100 if (!prefs.get()) | |
| 101 return true; | 101 return true; |
| 102 | 102 |
| 103 out_prefs->new_tabs = installer_util::GetFirstRunTabs(prefs.get()); | 103 out_prefs->new_tabs = prefs.GetFirstRunTabs(); |
| 104 | 104 |
| 105 bool value = false; | 105 bool value = false; |
| 106 | 106 |
| 107 #if defined(OS_WIN) | 107 #if defined(OS_WIN) |
| 108 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ | 108 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ |
| 109 // Linux, enable it here. | 109 // Linux, enable it here. |
| 110 if (!installer_util::GetDistroIntegerPreference(prefs.get(), | 110 if (!prefs.GetInt(installer_util::master_preferences::kDistroPingDelay, |
| 111 installer_util::master_preferences::kDistroPingDelay, | 111 &out_prefs->ping_delay)) { |
| 112 &out_prefs->ping_delay)) { | |
| 113 // 90 seconds is the default that we want to use in case master | 112 // 90 seconds is the default that we want to use in case master |
| 114 // preferences is missing, corrupt or ping_delay is missing. | 113 // preferences is missing, corrupt or ping_delay is missing. |
| 115 out_prefs->ping_delay = 90; | 114 out_prefs->ping_delay = 90; |
| 116 } | 115 } |
| 117 | 116 |
| 118 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 117 if (prefs.GetBool(installer_util::master_preferences::kRequireEula, &value) && |
| 119 installer_util::master_preferences::kRequireEula, &value) && value) { | 118 value) { |
| 120 // Show the post-installation EULA. This is done by setup.exe and the | 119 // Show the post-installation EULA. This is done by setup.exe and the |
| 121 // result determines if we continue or not. We wait here until the user | 120 // result determines if we continue or not. We wait here until the user |
| 122 // dismisses the dialog. | 121 // dismisses the dialog. |
| 123 | 122 |
| 124 // The actual eula text is in a resource in chrome. We extract it to | 123 // The actual eula text is in a resource in chrome. We extract it to |
| 125 // a text file so setup.exe can use it as an inner frame. | 124 // a text file so setup.exe can use it as an inner frame. |
| 126 FilePath inner_html; | 125 FilePath inner_html; |
| 127 if (WriteEULAtoTempFile(&inner_html)) { | 126 if (WriteEULAtoTempFile(&inner_html)) { |
| 128 int retcode = 0; | 127 int retcode = 0; |
| 129 if (!LaunchSetupWithParam(installer_util::switches::kShowEula, | 128 if (!LaunchSetupWithParam(installer_util::switches::kShowEula, |
| 130 inner_html.ToWStringHack(), &retcode) || | 129 inner_html.ToWStringHack(), &retcode) || |
| 131 (retcode == installer_util::EULA_REJECTED)) { | 130 (retcode == installer_util::EULA_REJECTED)) { |
| 132 LOG(WARNING) << "EULA rejected. Fast exit."; | 131 LOG(WARNING) << "EULA rejected. Fast exit."; |
| 133 ::ExitProcess(1); | 132 ::ExitProcess(1); |
| 134 } | 133 } |
| 135 if (retcode == installer_util::EULA_ACCEPTED) { | 134 if (retcode == installer_util::EULA_ACCEPTED) { |
| 136 VLOG(1) << "EULA : no collection"; | 135 VLOG(1) << "EULA : no collection"; |
| 137 GoogleUpdateSettings::SetCollectStatsConsent(false); | 136 GoogleUpdateSettings::SetCollectStatsConsent(false); |
| 138 } else if (retcode == installer_util::EULA_ACCEPTED_OPT_IN) { | 137 } else if (retcode == installer_util::EULA_ACCEPTED_OPT_IN) { |
| 139 VLOG(1) << "EULA : collection consent"; | 138 VLOG(1) << "EULA : collection consent"; |
| 140 GoogleUpdateSettings::SetCollectStatsConsent(true); | 139 GoogleUpdateSettings::SetCollectStatsConsent(true); |
| 141 } | 140 } |
| 142 } | 141 } |
| 143 } | 142 } |
| 144 #endif | 143 #endif |
| 145 | 144 |
| 146 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 145 if (prefs.GetBool(installer_util::master_preferences::kAltFirstRunBubble, |
| 147 installer_util::master_preferences::kAltFirstRunBubble, &value) && value) | 146 &value) && value) { |
| 148 FirstRun::SetOEMFirstRunBubblePref(); | 147 FirstRun::SetOEMFirstRunBubblePref(); |
| 148 } |
| 149 | 149 |
| 150 FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir); | 150 FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir); |
| 151 if (user_prefs.empty()) | 151 if (user_prefs.empty()) |
| 152 return true; | 152 return true; |
| 153 | 153 |
| 154 // The master prefs are regular prefs so we can just copy the file | 154 // The master prefs are regular prefs so we can just copy the file |
| 155 // to the default place and they just work. | 155 // to the default place and they just work. |
| 156 if (!file_util::CopyFile(master_prefs, user_prefs)) | 156 if (!file_util::CopyFile(master_prefs, user_prefs)) |
| 157 return true; | 157 return true; |
| 158 | 158 |
| 159 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 160 DictionaryValue* extensions = 0; | 160 DictionaryValue* extensions = 0; |
| 161 if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) { | 161 if (prefs.GetExtensionsBlock(&extensions)) { |
| 162 VLOG(1) << "Extensions block found in master preferences"; | 162 VLOG(1) << "Extensions block found in master preferences"; |
| 163 DoDelayedInstallExtensions(); | 163 DoDelayedInstallExtensions(); |
| 164 } | 164 } |
| 165 #endif | 165 #endif |
| 166 | 166 |
| 167 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 167 if (prefs.GetBool(installer_util::master_preferences::kDistroImportSearchPref, |
| 168 installer_util::master_preferences::kDistroImportSearchPref, &value)) { | 168 &value)) { |
| 169 if (value) { | 169 if (value) { |
| 170 out_prefs->do_import_items |= importer::SEARCH_ENGINES; | 170 out_prefs->do_import_items |= importer::SEARCH_ENGINES; |
| 171 } else { | 171 } else { |
| 172 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; | 172 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Check to see if search engine logos should be randomized. | 176 // Check to see if search engine logos should be randomized. |
| 177 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 177 if (prefs.GetBool( |
| 178 installer_util::master_preferences::kSearchEngineExperimentRandomizePref, | 178 installer_util::master_preferences:: |
| 179 &value) && value) | 179 kSearchEngineExperimentRandomizePref, |
| 180 &value) && value) { |
| 180 out_prefs->randomize_search_engine_experiment = true; | 181 out_prefs->randomize_search_engine_experiment = true; |
| 182 } |
| 181 | 183 |
| 182 // If we're suppressing the first-run bubble, set that preference now. | 184 // If we're suppressing the first-run bubble, set that preference now. |
| 183 // Otherwise, wait until the user has completed first run to set it, so the | 185 // Otherwise, wait until the user has completed first run to set it, so the |
| 184 // user is guaranteed to see the bubble iff he or she has completed the first | 186 // user is guaranteed to see the bubble iff he or she has completed the first |
| 185 // run process. | 187 // run process. |
| 186 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 188 if (prefs.GetBool( |
| 187 installer_util::master_preferences::kDistroSuppressFirstRunBubble, | 189 installer_util::master_preferences::kDistroSuppressFirstRunBubble, |
| 188 &value) && value) | 190 &value) && value) |
| 189 FirstRun::SetShowFirstRunBubblePref(false); | 191 FirstRun::SetShowFirstRunBubblePref(false); |
| 190 | 192 |
| 191 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 193 if (prefs.GetBool( |
| 192 installer_util::master_preferences::kDistroImportHistoryPref, &value)) { | 194 installer_util::master_preferences::kDistroImportHistoryPref, |
| 195 &value)) { |
| 193 if (value) { | 196 if (value) { |
| 194 out_prefs->do_import_items |= importer::HISTORY; | 197 out_prefs->do_import_items |= importer::HISTORY; |
| 195 } else { | 198 } else { |
| 196 out_prefs->dont_import_items |= importer::HISTORY; | 199 out_prefs->dont_import_items |= importer::HISTORY; |
| 197 } | 200 } |
| 198 } | 201 } |
| 199 | 202 |
| 200 std::string not_used; | 203 std::string not_used; |
| 201 out_prefs->homepage_defined = prefs->GetString(prefs::kHomePage, ¬_used); | 204 out_prefs->homepage_defined = prefs.GetString(prefs::kHomePage, ¬_used); |
| 202 | 205 |
| 203 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 206 if (prefs.GetBool( |
| 204 installer_util::master_preferences::kDistroImportHomePagePref, &value)) { | 207 installer_util::master_preferences::kDistroImportHomePagePref, |
| 208 &value)) { |
| 205 if (value) { | 209 if (value) { |
| 206 out_prefs->do_import_items |= importer::HOME_PAGE; | 210 out_prefs->do_import_items |= importer::HOME_PAGE; |
| 207 } else { | 211 } else { |
| 208 out_prefs->dont_import_items |= importer::HOME_PAGE; | 212 out_prefs->dont_import_items |= importer::HOME_PAGE; |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 // Bookmarks are never imported unless specifically turned on. | 216 // Bookmarks are never imported unless specifically turned on. |
| 213 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 217 if (prefs.GetBool( |
| 214 installer_util::master_preferences::kDistroImportBookmarksPref, &value) | 218 installer_util::master_preferences::kDistroImportBookmarksPref, |
| 215 && value) { | 219 &value) && value) { |
| 216 out_prefs->do_import_items |= importer::FAVORITES; | 220 out_prefs->do_import_items |= importer::FAVORITES; |
| 217 } | 221 } |
| 218 | 222 |
| 219 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 223 if (prefs.GetBool( |
| 220 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) && | 224 installer_util::master_preferences::kMakeChromeDefaultForUser, |
| 221 value) | 225 &value) && value) { |
| 222 out_prefs->make_chrome_default = true; | 226 out_prefs->make_chrome_default = true; |
| 227 } |
| 223 | 228 |
| 224 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run | 229 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run |
| 225 // import process. http://crbug.com/49647 | 230 // import process. http://crbug.com/49647 |
| 226 // Note we are skipping all other master preferences if skip-first-run-ui | 231 // Note we are skipping all other master preferences if skip-first-run-ui |
| 227 // is *not* specified. (That is, we continue only if skipping first run ui.) | 232 // is *not* specified. (That is, we continue only if skipping first run ui.) |
| 228 if (!installer_util::GetDistroBooleanPreference(prefs.get(), | 233 if (!prefs.GetBool( |
| 229 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || | 234 installer_util::master_preferences::kDistroSkipFirstRunPref, |
| 230 !value) | 235 &value) || !value) { |
| 231 return true; | 236 return true; |
| 237 } |
| 232 | 238 |
| 233 #if !defined(OS_WIN) | 239 #if !defined(OS_WIN) |
| 234 // From here on we won't show first run so we need to do the work to show the | 240 // From here on we won't show first run so we need to do the work to show the |
| 235 // bubble anyway, unless it's already been explicitly suppressed. | 241 // bubble anyway, unless it's already been explicitly suppressed. |
| 236 FirstRun::SetShowFirstRunBubblePref(true); | 242 FirstRun::SetShowFirstRunBubblePref(true); |
| 237 #endif | 243 #endif |
| 238 | 244 |
| 239 // We need to be able to create the first run sentinel or else we cannot | 245 // We need to be able to create the first run sentinel or else we cannot |
| 240 // proceed because ImportSettings will launch the importer process which | 246 // proceed because ImportSettings will launch the importer process which |
| 241 // would end up here if the sentinel is not present. | 247 // would end up here if the sentinel is not present. |
| 242 if (!FirstRun::CreateSentinel()) | 248 if (!FirstRun::CreateSentinel()) |
| 243 return false; | 249 return false; |
| 244 | 250 |
| 245 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 251 if (prefs.GetBool(installer_util::master_preferences::kDistroShowWelcomePage, |
| 246 installer_util::master_preferences::kDistroShowWelcomePage, &value) && | 252 &value) && value) { |
| 247 value) | |
| 248 FirstRun::SetShowWelcomePagePref(); | 253 FirstRun::SetShowWelcomePagePref(); |
| 254 } |
| 249 | 255 |
| 250 std::string import_bookmarks_path; | 256 std::string import_bookmarks_path; |
| 251 installer_util::GetDistroStringPreference(prefs.get(), | 257 prefs.GetString( |
| 252 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, | 258 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, |
| 253 &import_bookmarks_path); | 259 &import_bookmarks_path); |
| 254 | 260 |
| 255 #if defined(OS_WIN) | 261 #if defined(OS_WIN) |
| 256 std::wstring brand; | 262 std::wstring brand; |
| 257 GoogleUpdateSettings::GetBrand(&brand); | 263 GoogleUpdateSettings::GetBrand(&brand); |
| 258 // This should generally be true, as skip_first_run_ui is a setting used for | 264 // This should generally be true, as skip_first_run_ui is a setting used for |
| 259 // non-organic builds. | 265 // non-organic builds. |
| 260 if (!GoogleUpdateSettings::IsOrganic(brand)) { | 266 if (!GoogleUpdateSettings::IsOrganic(brand)) { |
| 261 // If search engines aren't explicitly imported, don't import. | 267 // If search engines aren't explicitly imported, don't import. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 288 if (!import_bookmarks_path.empty()) { | 294 if (!import_bookmarks_path.empty()) { |
| 289 // There are bookmarks to import from a file. | 295 // There are bookmarks to import from a file. |
| 290 FilePath path = FilePath::FromWStringHack(UTF8ToWide( | 296 FilePath path = FilePath::FromWStringHack(UTF8ToWide( |
| 291 import_bookmarks_path)); | 297 import_bookmarks_path)); |
| 292 if (!FirstRun::ImportBookmarks(path)) { | 298 if (!FirstRun::ImportBookmarks(path)) { |
| 293 LOG(WARNING) << "silent bookmark import failed"; | 299 LOG(WARNING) << "silent bookmark import failed"; |
| 294 } | 300 } |
| 295 } | 301 } |
| 296 #endif | 302 #endif |
| 297 | 303 |
| 298 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 304 if (prefs.GetBool( |
| 299 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) && | 305 installer_util::master_preferences::kMakeChromeDefaultForUser, |
| 300 value) | 306 &value) && value) { |
| 301 ShellIntegration::SetAsDefaultBrowser(); | 307 ShellIntegration::SetAsDefaultBrowser(); |
| 308 } |
| 302 | 309 |
| 303 return false; | 310 return false; |
| 304 } | 311 } |
| 305 | 312 |
| 306 // static | 313 // static |
| 307 bool FirstRun::IsChromeFirstRun() { | 314 bool FirstRun::IsChromeFirstRun() { |
| 308 if (first_run_ != FIRST_RUN_UNKNOWN) | 315 if (first_run_ != FIRST_RUN_UNKNOWN) |
| 309 return first_run_ == FIRST_RUN_TRUE; | 316 return first_run_ == FIRST_RUN_TRUE; |
| 310 | 317 |
| 311 FilePath first_run_sentinel; | 318 FilePath first_run_sentinel; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 if (!observer->ended()) { | 660 if (!observer->ended()) { |
| 654 observer->set_should_quit_message_loop(); | 661 observer->set_should_quit_message_loop(); |
| 655 MessageLoop::current()->Run(); | 662 MessageLoop::current()->Run(); |
| 656 } | 663 } |
| 657 | 664 |
| 658 // Unfortunately there's no success/fail signal in ImporterHost. | 665 // Unfortunately there's no success/fail signal in ImporterHost. |
| 659 return true; | 666 return true; |
| 660 } | 667 } |
| 661 | 668 |
| 662 #endif // OS_POSIX | 669 #endif // OS_POSIX |
| OLD | NEW |