OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/first_run/first_run_dialog.h" | 14 #include "chrome/browser/first_run/first_run_dialog.h" |
15 #include "chrome/browser/first_run/first_run_import_observer.h" | 15 #include "chrome/browser/first_run/first_run_import_observer.h" |
16 #include "chrome/browser/importer/external_process_importer_host.h" | 16 #include "chrome/browser/importer/external_process_importer_host.h" |
17 #include "chrome/browser/importer/importer_host.h" | |
18 #include "chrome/browser/importer/importer_list.h" | 17 #include "chrome/browser/importer/importer_list.h" |
19 #include "chrome/browser/importer/importer_progress_dialog.h" | 18 #include "chrome/browser/importer/importer_progress_dialog.h" |
20 #include "chrome/browser/importer/importer_progress_observer.h" | 19 #include "chrome/browser/importer/importer_progress_observer.h" |
21 #include "chrome/browser/prefs/pref_service.h" | |
22 #include "chrome/browser/process_singleton.h" | 20 #include "chrome/browser/process_singleton.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
26 #include "chrome/browser/shell_integration.h" | 24 #include "chrome/browser/shell_integration.h" |
27 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
30 #include "chrome/installer/util/master_preferences.h" | 28 #include "chrome/installer/util/master_preferences.h" |
31 #include "chrome/installer/util/master_preferences_constants.h" | 29 #include "chrome/installer/util/master_preferences_constants.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 // static | 96 // static |
99 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, | 97 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, |
100 MasterPrefs* out_prefs) { | 98 MasterPrefs* out_prefs) { |
101 DCHECK(!user_data_dir.empty()); | 99 DCHECK(!user_data_dir.empty()); |
102 | 100 |
103 // The standard location of the master prefs is next to the chrome binary. | 101 // The standard location of the master prefs is next to the chrome binary. |
104 FilePath master_prefs; | 102 FilePath master_prefs; |
105 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 103 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
106 return true; | 104 return true; |
107 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 105 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
108 | |
109 installer::MasterPreferences prefs(master_prefs); | 106 installer::MasterPreferences prefs(master_prefs); |
110 if (!prefs.read_from_file()) | 107 if (!prefs.read_from_file()) |
111 return true; | 108 return true; |
112 | 109 |
113 out_prefs->new_tabs = prefs.GetFirstRunTabs(); | 110 out_prefs->new_tabs = prefs.GetFirstRunTabs(); |
114 | 111 |
115 bool value = false; | 112 bool value = false; |
116 | 113 |
117 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
118 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ | 115 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 if (value) { | 217 if (value) { |
221 out_prefs->do_import_items |= importer::HOME_PAGE; | 218 out_prefs->do_import_items |= importer::HOME_PAGE; |
222 } else { | 219 } else { |
223 out_prefs->dont_import_items |= importer::HOME_PAGE; | 220 out_prefs->dont_import_items |= importer::HOME_PAGE; |
224 } | 221 } |
225 } | 222 } |
226 | 223 |
227 // Bookmarks are never imported unless specifically turned on. | 224 // Bookmarks are never imported unless specifically turned on. |
228 if (prefs.GetBool( | 225 if (prefs.GetBool( |
229 installer::master_preferences::kDistroImportBookmarksPref, | 226 installer::master_preferences::kDistroImportBookmarksPref, |
230 &value) && value) { | 227 &value)) { |
231 out_prefs->do_import_items |= importer::FAVORITES; | 228 if (value) { |
James Hawkins
2011/08/01 19:41:51
Optional, but recommended: Don't use braces for on
simo
2011/08/02 09:08:14
Done.
| |
229 out_prefs->do_import_items |= importer::FAVORITES; | |
230 } else { | |
231 out_prefs->dont_import_items |= importer::FAVORITES; | |
232 } | |
232 } | 233 } |
233 | 234 |
234 if (prefs.GetBool( | 235 if (prefs.GetBool( |
235 installer::master_preferences::kMakeChromeDefaultForUser, | 236 installer::master_preferences::kMakeChromeDefaultForUser, |
236 &value) && value) { | 237 &value) && value) { |
237 out_prefs->make_chrome_default = true; | 238 out_prefs->make_chrome_default = true; |
238 } | 239 } |
239 | 240 |
240 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run | 241 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run |
241 // import process. http://crbug.com/49647 | 242 // import process. http://crbug.com/49647 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 | 517 |
517 scoped_refptr<ImporterList> importer_list(new ImporterList); | 518 scoped_refptr<ImporterList> importer_list(new ImporterList); |
518 importer_list->DetectSourceProfilesHack(); | 519 importer_list->DetectSourceProfilesHack(); |
519 | 520 |
520 // Do import if there is an available profile for us to import. | 521 // Do import if there is an available profile for us to import. |
521 if (importer_list->count() > 0) { | 522 if (importer_list->count() > 0) { |
522 // Don't show the warning dialog if import fails. | 523 // Don't show the warning dialog if import fails. |
523 importer_host->set_headless(); | 524 importer_host->set_headless(); |
524 int items = 0; | 525 int items = 0; |
525 | 526 |
526 // History is always imported unless turned off in master_preferences. | |
527 if (!(dont_import_items & importer::HISTORY)) | |
528 items = items | importer::HISTORY; | |
529 // Home page is imported in organic builds only unless turned off or | |
530 // defined in master_preferences. | |
531 if (IsOrganicFirstRun()) { | 527 if (IsOrganicFirstRun()) { |
532 if (!(dont_import_items & importer::HOME_PAGE) && !homepage_defined) | 528 // Home page is imported in organic builds only unless turned off or |
533 items = items | importer::HOME_PAGE; | 529 // defined in master_preferences. |
534 } else { | 530 if (homepage_defined) { |
535 if (import_items & importer::HOME_PAGE) | 531 dont_import_items |= importer::HOME_PAGE; |
536 items = items | importer::HOME_PAGE; | 532 if (import_items & importer::HOME_PAGE) |
537 } | 533 import_items &= ~importer::HOME_PAGE; |
538 // Search engines are only imported in certain builds unless overridden | |
539 // in master_preferences. Search engines are not imported automatically | |
540 // if the user already has a user preferences directory. | |
541 if (IsOrganicFirstRun()) { | |
542 if (!(dont_import_items & importer::SEARCH_ENGINES) && | |
543 !local_state_file_exists) { | |
544 items = items | importer::SEARCH_ENGINES; | |
545 } | 534 } |
546 } else if (import_items & importer::SEARCH_ENGINES) { | 535 // Search engines are not imported automatically in organic builds if the |
547 items = items | importer::SEARCH_ENGINES; | 536 // user already has a user preferences directory. |
537 if (local_state_file_exists) { | |
538 dont_import_items |= importer::SEARCH_ENGINES; | |
539 if (import_items & importer::SEARCH_ENGINES) | |
540 import_items &= ~importer::SEARCH_ENGINES; | |
541 } | |
548 } | 542 } |
549 | 543 |
550 // Bookmarks are never imported, unless turned on in master_preferences. | 544 PrefService* user_prefs = profile->GetPrefs(); |
551 if (import_items & importer::FAVORITES) | 545 |
552 items = items | importer::FAVORITES; | 546 SetImportItem(user_prefs, |
547 prefs::kImportHistory, | |
548 import_items, | |
549 dont_import_items, | |
550 importer::HISTORY, | |
551 items); | |
552 SetImportItem(user_prefs, | |
553 prefs::kImportHomepage, | |
554 import_items, | |
555 dont_import_items, | |
556 importer::HOME_PAGE, | |
557 items); | |
558 SetImportItem(user_prefs, | |
559 prefs::kImportSearchEngine, | |
560 import_items, | |
561 dont_import_items, | |
562 importer::SEARCH_ENGINES, | |
563 items); | |
564 SetImportItem(user_prefs, | |
565 prefs::kImportBookmarks, | |
566 import_items, | |
567 dont_import_items, | |
568 importer::FAVORITES, | |
569 items); | |
553 | 570 |
554 ImportSettings(profile, importer_host, importer_list, items); | 571 ImportSettings(profile, importer_host, importer_list, items); |
555 } | 572 } |
556 | 573 |
557 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 574 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
558 | 575 |
559 // Launch the search engine dialog only for certain builds, and only if the | 576 // Launch the search engine dialog only for certain builds, and only if the |
560 // user has not already set preferences. | 577 // user has not already set preferences. |
561 if (IsOrganicFirstRun() && !local_state_file_exists) { | 578 if (IsOrganicFirstRun() && !local_state_file_exists) { |
562 // The home page string may be set in the preferences, but the user should | 579 // The home page string may be set in the preferences, but the user should |
(...skipping 14 matching lines...) Expand all Loading... | |
577 // Set the first run bubble to minimal. | 594 // Set the first run bubble to minimal. |
578 FirstRun::SetMinimalFirstRunBubblePref(); | 595 FirstRun::SetMinimalFirstRunBubblePref(); |
579 } | 596 } |
580 FirstRun::SetShowWelcomePagePref(); | 597 FirstRun::SetShowWelcomePagePref(); |
581 FirstRun::SetPersonalDataManagerFirstRunPref(); | 598 FirstRun::SetPersonalDataManagerFirstRunPref(); |
582 | 599 |
583 process_singleton->Unlock(); | 600 process_singleton->Unlock(); |
584 FirstRun::CreateSentinel(); | 601 FirstRun::CreateSentinel(); |
585 } | 602 } |
586 | 603 |
604 // static | |
605 void FirstRun::SetImportItem(PrefService* user_prefs, | |
606 const char* pref_path, | |
607 int import_items, | |
608 int dont_import_items, | |
609 importer::ImportItem import_type, | |
610 int& items) { | |
611 | |
612 // Work out whether an item is to be imported according to what is specified | |
613 // in master preferences. | |
614 bool should_import = false; | |
615 bool master_pref_set = (import_items | dont_import_items) & import_type; | |
616 bool master_pref = (import_items & ~dont_import_items) & import_type; | |
617 | |
618 if (import_type == importer::HISTORY | |
619 || ((import_type != importer::FAVORITES) && IsOrganicFirstRun())) { | |
620 // History is always imported unless turned off in master_preferences. | |
621 // Search engines are only imported in certain builds unless overridden | |
622 // in master_preferences. | |
623 // Home page is imported in organic builds only unless turned off in | |
624 // master_preferences. | |
625 should_import = !master_pref_set || master_pref; | |
626 } else { | |
627 // Bookmarks are never imported, unless turned on in master_preferences. | |
628 // Search engine and home page import behaviour is similar in non organic | |
629 // builds. | |
630 should_import = master_pref_set && master_pref; | |
631 } | |
632 | |
633 // If an import policy is set, import items according to policy. | |
634 // If no master preference is set, but a corresponding recommended policy is | |
635 // set, import item according to recommended policy. | |
636 // If both a master preference and a recommended policy is set, the master | |
637 // preference wins. | |
638 // If neither recommended nor managed policies are set, import item according | |
639 // to what we worked out above. | |
640 if (master_pref_set) | |
641 user_prefs->SetBoolean(pref_path, should_import); | |
642 | |
643 if (!user_prefs->FindPreference(pref_path)->IsDefaultValue()) { | |
644 if (user_prefs->GetBoolean(pref_path)) | |
645 items |= import_type; | |
646 } else { // no policy (recommended or managed) is set | |
647 if (should_import) | |
648 items |= import_type; | |
649 } | |
650 | |
651 user_prefs->ClearPref(pref_path); | |
652 } | |
653 | |
587 #if defined(OS_POSIX) | 654 #if defined(OS_POSIX) |
588 namespace { | 655 namespace { |
589 | 656 |
590 // This class acts as an observer for the ImporterProgressObserver::ImportEnded | 657 // This class acts as an observer for the ImporterProgressObserver::ImportEnded |
591 // callback. When the import process is started, certain errors may cause | 658 // callback. When the import process is started, certain errors may cause |
592 // ImportEnded() to be called synchronously, but the typical case is that | 659 // ImportEnded() to be called synchronously, but the typical case is that |
593 // ImportEnded() is called asynchronously. Thus we have to handle both cases. | 660 // ImportEnded() is called asynchronously. Thus we have to handle both cases. |
594 class ImportEndedObserver : public importer::ImporterProgressObserver { | 661 class ImportEndedObserver : public importer::ImporterProgressObserver { |
595 public: | 662 public: |
596 ImportEndedObserver() : ended_(false), | 663 ImportEndedObserver() : ended_(false), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 if (!observer->ended()) { | 716 if (!observer->ended()) { |
650 observer->set_should_quit_message_loop(); | 717 observer->set_should_quit_message_loop(); |
651 MessageLoop::current()->Run(); | 718 MessageLoop::current()->Run(); |
652 } | 719 } |
653 | 720 |
654 // Unfortunately there's no success/fail signal in ImporterHost. | 721 // Unfortunately there's no success/fail signal in ImporterHost. |
655 return true; | 722 return true; |
656 } | 723 } |
657 | 724 |
658 #endif // OS_POSIX | 725 #endif // OS_POSIX |
OLD | NEW |