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.h" | 5 #include "chrome/browser/first_run.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (terms.empty()) | 156 if (terms.empty()) |
157 return false; | 157 return false; |
158 FilePath temp_dir; | 158 FilePath temp_dir; |
159 if (!file_util::GetTempDir(&temp_dir)) | 159 if (!file_util::GetTempDir(&temp_dir)) |
160 return false; | 160 return false; |
161 *eula_path = temp_dir.Append(L"chrome_eula_iframe.html"); | 161 *eula_path = temp_dir.Append(L"chrome_eula_iframe.html"); |
162 return (file_util::WriteFile(*eula_path, terms.data(), terms.size()) > 0); | 162 return (file_util::WriteFile(*eula_path, terms.data(), terms.size()) > 0); |
163 } | 163 } |
164 | 164 |
165 // Helper class that performs delayed first-run tasks that need more of the | 165 // Helper class that performs delayed first-run tasks that need more of the |
166 // chrome infrastructure to be up and running before they can be attempted. | 166 // chrome infrastructure to be up an running before they can be attempted. |
167 class FirstRunDelayedTasks : public NotificationObserver { | 167 class FirsRunDelayedTasks : public NotificationObserver { |
168 public: | 168 public: |
169 enum Tasks { | 169 enum Tasks { |
170 NO_TASK, | 170 NO_TASK, |
171 INSTALL_EXTENSIONS | 171 INSTALL_EXTENSIONS |
172 }; | 172 }; |
173 | 173 |
174 explicit FirstRunDelayedTasks(Tasks task) { | 174 explicit FirsRunDelayedTasks(Tasks task) { |
175 if (task == INSTALL_EXTENSIONS) { | 175 if (task == INSTALL_EXTENSIONS) { |
176 registrar_.Add(this, NotificationType::EXTENSIONS_READY, | 176 registrar_.Add(this, NotificationType::EXTENSIONS_READY, |
177 NotificationService::AllSources()); | 177 NotificationService::AllSources()); |
178 } | 178 } |
179 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 179 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
180 NotificationService::AllSources()); | 180 NotificationService::AllSources()); |
181 } | 181 } |
182 | 182 |
183 virtual void Observe(NotificationType type, | 183 virtual void Observe(NotificationType type, |
184 const NotificationSource& source, | 184 const NotificationSource& source, |
185 const NotificationDetails& details) { | 185 const NotificationDetails& details) { |
186 // After processing the notification we always delete ourselves. | 186 // After processing the notification we always delete ourselves. |
187 if (type.value == NotificationType::EXTENSIONS_READY) | 187 if (type.value == NotificationType::EXTENSIONS_READY) |
188 DoExtensionWork(Source<Profile>(source).ptr()->GetExtensionsService()); | 188 DoExtensionWork(Source<Profile>(source).ptr()->GetExtensionsService()); |
189 delete this; | 189 delete this; |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 private: | 193 private: |
194 // Private ctor forces it to be created only in the heap. | 194 // Private ctor forces it to be created only in the heap. |
195 ~FirstRunDelayedTasks() {} | 195 ~FirsRunDelayedTasks() {} |
196 | 196 |
197 // The extension work is to basically trigger an extension update check. | 197 // The extension work is to basically trigger an extension update check. |
198 // If the extension specified in the master pref is older than the live | 198 // If the extension specified in the master pref is older than the live |
199 // extension it will get updated which is the same as get it installed. | 199 // extension it will get updated which is the same as get it installed. |
200 void DoExtensionWork(ExtensionsService* service) { | 200 void DoExtensionWork(ExtensionsService* service) { |
201 if (!service) | 201 if (!service) |
202 return; | 202 return; |
203 service->updater()->CheckNow(); | 203 service->updater()->CheckNow(); |
204 return; | 204 return; |
205 } | 205 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 return true; | 297 return true; |
298 | 298 |
299 // The master prefs are regular prefs so we can just copy the file | 299 // The master prefs are regular prefs so we can just copy the file |
300 // to the default place and they just work. | 300 // to the default place and they just work. |
301 if (!file_util::CopyFile(master_prefs, user_prefs)) | 301 if (!file_util::CopyFile(master_prefs, user_prefs)) |
302 return true; | 302 return true; |
303 | 303 |
304 DictionaryValue* extensions = 0; | 304 DictionaryValue* extensions = 0; |
305 if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) { | 305 if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) { |
306 LOG(INFO) << "Extensions block found in master preferences"; | 306 LOG(INFO) << "Extensions block found in master preferences"; |
307 new FirstRunDelayedTasks(FirstRunDelayedTasks::INSTALL_EXTENSIONS); | 307 new FirsRunDelayedTasks(FirsRunDelayedTasks::INSTALL_EXTENSIONS); |
308 } | 308 } |
309 | 309 |
310 // If the search engine dialog is not shown, the search engine is set to | 310 // Add a special exception for import_search_engine preference. |
311 // Google unless master_preferences specifically turns on search engine | 311 // Even though we skip all other import_* preferences below, if |
312 // import. | 312 // skip-first-run-ui is not specified, we make exception for this one |
| 313 // preference. |
313 int import_items = 0; | 314 int import_items = 0; |
314 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 315 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
315 installer_util::master_preferences::kDistroImportSearchPref, &value) | 316 installer_util::master_preferences::kDistroImportSearchPref, &value)) { |
316 && value) { | 317 if (value) { |
317 import_items |= importer::SEARCH_ENGINES; | 318 import_items += importer::SEARCH_ENGINES; |
318 out_prefs->do_import_items |= importer::SEARCH_ENGINES; | 319 out_prefs->do_import_items += importer::SEARCH_ENGINES; |
| 320 } else { |
| 321 out_prefs->dont_import_items += importer::SEARCH_ENGINES; |
| 322 } |
319 } | 323 } |
320 | 324 |
321 // Check to see if search engine logos should be randomized. | |
322 if (installer_util::GetDistroBooleanPreference(prefs.get(), | |
323 installer_util::master_preferences::kSearchEngineExperimentRandomizePref, | |
324 &value) && value) | |
325 out_prefs->randomize_search_engine_experiment = true; | |
326 | |
327 // If we're suppressing the first-run bubble, set that preference now. | 325 // If we're suppressing the first-run bubble, set that preference now. |
328 // Otherwise, wait until the user has completed first run to set it, so the | 326 // Otherwise, wait until the user has completed first run to set it, so the |
329 // user is guaranteed to see the bubble iff he or she has completed the first | 327 // user is guaranteed to see the bubble iff he or she has completed the first |
330 // run process. | 328 // run process. |
331 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 329 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
332 installer_util::master_preferences::kDistroSuppressFirstRunBubble, | 330 installer_util::master_preferences::kDistroSuppressFirstRunBubble, |
333 &value) && value) | 331 &value) && value) |
334 FirstRun::SetShowFirstRunBubblePref(false); | 332 FirstRun::SetShowFirstRunBubblePref(false); |
335 | 333 |
336 | 334 if (InSearchExperimentLocale() && |
337 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 335 installer_util::GetDistroBooleanPreference(prefs.get(), |
338 installer_util::master_preferences::kDistroImportHistoryPref, &value)) { | 336 installer_util::master_preferences::kSearchEngineExperimentPref, |
339 if (value) { | 337 &value) && value) { |
340 import_items |= importer::HISTORY; | 338 // Set the first run dialog to include the search choice window. |
341 } else { | 339 out_prefs->run_search_engine_experiment = true; |
342 // Automatic history import can be turned off in master_prefs. | 340 // Check to see if search engine logos should be randomized. |
343 out_prefs->dont_import_items |= importer::HISTORY; | 341 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
| 342 installer_util::master_preferences:: |
| 343 kSearchEngineExperimentRandomizePref, |
| 344 &value) && value) { |
| 345 out_prefs->randomize_search_engine_experiment = true; |
344 } | 346 } |
| 347 // Set the first run bubble to minimal. |
| 348 FirstRun::SetMinimalFirstRunBubblePref(); |
345 } | 349 } |
346 | 350 |
| 351 // History is imported automatically, unless turned off in master_prefs. |
347 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 352 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
348 installer_util::master_preferences::kDistroImportHomePagePref, &value)) { | 353 installer_util::master_preferences::kDistroImportHistoryPref, &value) |
349 if (value) { | 354 && !value) { |
350 import_items |= importer::HOME_PAGE; | 355 out_prefs->dont_import_items |= importer::HISTORY; |
351 } else { | 356 } |
352 // Automatic home page import can be turned off in master_prefs. | 357 |
353 out_prefs->dont_import_items |= importer::HOME_PAGE; | 358 // Home page is imported automatically only in organic builds, and can be |
354 } | 359 // turned off in master_prefs. |
| 360 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
| 361 installer_util::master_preferences::kDistroImportHomePagePref, &value) |
| 362 && !value) { |
| 363 out_prefs->dont_import_items |= importer::HOME_PAGE; |
355 } | 364 } |
356 | 365 |
357 // Bookmarks are never imported unless specifically turned on. | 366 // Bookmarks are never imported unless specifically turned on. |
358 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 367 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
359 installer_util::master_preferences::kDistroImportBookmarksPref, &value) | 368 installer_util::master_preferences::kDistroImportBookmarksPref, &value) |
360 && value) { | 369 && value) { |
361 import_items |= importer::FAVORITES; | |
362 out_prefs->do_import_items |= importer::FAVORITES; | 370 out_prefs->do_import_items |= importer::FAVORITES; |
363 } | 371 } |
364 | 372 |
365 if (installer_util::GetDistroBooleanPreference(prefs.get(), | |
366 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) && | |
367 value) | |
368 ShellIntegration::SetAsDefaultBrowser(); | |
369 | |
370 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run | |
371 // import process. http://crbug.com/49647 | |
372 // Note we are skipping all other master preferences if skip-first-run-ui | 373 // Note we are skipping all other master preferences if skip-first-run-ui |
373 // is *not* specified. (That is, we continue only if skipping first run ui.) | 374 // is *not* specified. (That is, we continue only if skipping first run ui.) |
374 if (!installer_util::GetDistroBooleanPreference(prefs.get(), | 375 if (!installer_util::GetDistroBooleanPreference(prefs.get(), |
375 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || | 376 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || |
376 !value) | 377 !value) |
377 return true; | 378 return true; |
378 | 379 |
| 380 // From here on we won't show first run so we need to do the work to show the |
| 381 // bubble anyway, unless it's already been explicitly suppressed. |
| 382 FirstRun::SetShowFirstRunBubblePref(true); |
| 383 |
379 // We need to be able to create the first run sentinel or else we cannot | 384 // We need to be able to create the first run sentinel or else we cannot |
380 // proceed because ImportSettings will launch the importer process which | 385 // proceed because ImportSettings will launch the importer process which |
381 // would end up here if the sentinel is not present. | 386 // would end up here if the sentinel is not present. |
382 if (!FirstRun::CreateSentinel()) | 387 if (!FirstRun::CreateSentinel()) |
383 return false; | 388 return false; |
384 | 389 |
385 if (installer_util::GetDistroBooleanPreference(prefs.get(), | 390 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
386 installer_util::master_preferences::kDistroShowWelcomePage, &value) && | 391 installer_util::master_preferences::kDistroShowWelcomePage, &value) && |
387 value) | 392 value) |
388 FirstRun::SetShowWelcomePagePref(); | 393 FirstRun::SetShowWelcomePagePref(); |
389 | 394 |
390 std::wstring import_bookmarks_path; | 395 std::wstring import_bookmarks_path; |
391 installer_util::GetDistroStringPreference(prefs.get(), | 396 installer_util::GetDistroStringPreference(prefs.get(), |
392 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, | 397 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, |
393 &import_bookmarks_path); | 398 &import_bookmarks_path); |
394 | 399 |
395 if (import_items || !import_bookmarks_path.empty()) { | 400 if (import_items || !import_bookmarks_path.empty()) { |
396 // There is something to import from the default browser. This launches | 401 // There is something to import from the default browser. This launches |
397 // the importer process and blocks until done or until it fails. | 402 // the importer process and blocks until done or until it fails. |
398 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); | 403 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); |
399 if (!FirstRun::ImportSettings(NULL, | 404 if (!FirstRun::ImportSettings(NULL, |
400 importer_host->GetSourceProfileInfoAt(0).browser_type, | 405 importer_host->GetSourceProfileInfoAt(0).browser_type, |
401 import_items, import_bookmarks_path, NULL)) { | 406 import_items, import_bookmarks_path, NULL)) { |
402 LOG(WARNING) << "silent import failed"; | 407 LOG(WARNING) << "silent import failed"; |
403 } | 408 } |
404 } | 409 } |
405 | 410 |
| 411 if (installer_util::GetDistroBooleanPreference(prefs.get(), |
| 412 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) && |
| 413 value) |
| 414 ShellIntegration::SetAsDefaultBrowser(); |
| 415 |
406 return false; | 416 return false; |
407 } | 417 } |
408 | 418 |
409 bool Upgrade::IsBrowserAlreadyRunning() { | 419 bool Upgrade::IsBrowserAlreadyRunning() { |
410 static HANDLE handle = NULL; | 420 static HANDLE handle = NULL; |
411 std::wstring exe; | 421 std::wstring exe; |
412 PathService::Get(base::FILE_EXE, &exe); | 422 PathService::Get(base::FILE_EXE, &exe); |
413 std::replace(exe.begin(), exe.end(), '\\', '!'); | 423 std::replace(exe.begin(), exe.end(), '\\', '!'); |
414 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); | 424 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); |
415 exe = L"Global\\" + exe; | 425 exe = L"Global\\" + exe; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 randomize_search_engine_experiment)); | 671 randomize_search_engine_experiment)); |
662 DCHECK(search_engine_dialog); | 672 DCHECK(search_engine_dialog); |
663 | 673 |
664 search_engine_dialog->Show(); | 674 search_engine_dialog->Show(); |
665 views::AcceleratorHandler accelerator_handler; | 675 views::AcceleratorHandler accelerator_handler; |
666 MessageLoopForUI::current()->Run(&accelerator_handler); | 676 MessageLoopForUI::current()->Run(&accelerator_handler); |
667 search_engine_dialog->Close(); | 677 search_engine_dialog->Close(); |
668 } | 678 } |
669 } | 679 } |
670 | 680 |
671 FirstRun::SetShowFirstRunBubblePref(true); | |
672 // Set the first run bubble to minimal. | |
673 FirstRun::SetMinimalFirstRunBubblePref(); | |
674 | |
675 process_singleton->Unlock(); | 681 process_singleton->Unlock(); |
676 FirstRun::CreateSentinel(); | 682 FirstRun::CreateSentinel(); |
677 } | 683 } |
678 | 684 |
679 bool FirstRun::ImportSettings(Profile* profile, int browser_type, | 685 bool FirstRun::ImportSettings(Profile* profile, int browser_type, |
680 int items_to_import, | 686 int items_to_import, |
681 const std::wstring& import_bookmarks_path, | 687 const std::wstring& import_bookmarks_path, |
682 HWND parent_window) { | 688 HWND parent_window) { |
683 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 689 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
684 CommandLine import_cmd(cmdline.GetProgram()); | 690 CommandLine import_cmd(cmdline.GetProgram()); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1068 |
1063 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { | 1069 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { |
1064 if (version > 10000) { | 1070 if (version > 10000) { |
1065 // This is a test value. We want to make sure we exercise | 1071 // This is a test value. We want to make sure we exercise |
1066 // returning this early. See EarlyReturnTest test harness. | 1072 // returning this early. See EarlyReturnTest test harness. |
1067 return Upgrade::TD_NOT_NOW; | 1073 return Upgrade::TD_NOT_NOW; |
1068 } | 1074 } |
1069 TryChromeDialog td; | 1075 TryChromeDialog td; |
1070 return td.ShowModal(); | 1076 return td.ShowModal(); |
1071 } | 1077 } |
OLD | NEW |