Chromium Code Reviews| 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" | 17 #include "chrome/browser/importer/importer_host.h" |
| 18 #include "chrome/browser/importer/importer_list.h" | 18 #include "chrome/browser/importer/importer_list.h" |
| 19 #include "chrome/browser/importer/importer_progress_dialog.h" | 19 #include "chrome/browser/importer/importer_progress_dialog.h" |
| 20 #include "chrome/browser/importer/importer_progress_observer.h" | 20 #include "chrome/browser/importer/importer_progress_observer.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | |
| 22 #include "chrome/browser/process_singleton.h" | 21 #include "chrome/browser/process_singleton.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/search_engines/template_url_service.h" | 23 #include "chrome/browser/search_engines/template_url_service.h" |
| 25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 26 #include "chrome/browser/shell_integration.h" | 25 #include "chrome/browser/shell_integration.h" |
| 27 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/installer/util/master_preferences.h" | 29 #include "chrome/installer/util/master_preferences.h" |
| 31 #include "chrome/installer/util/master_preferences_constants.h" | 30 #include "chrome/installer/util/master_preferences_constants.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // static | 97 // static |
| 99 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, | 98 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, |
| 100 MasterPrefs* out_prefs) { | 99 MasterPrefs* out_prefs) { |
| 101 DCHECK(!user_data_dir.empty()); | 100 DCHECK(!user_data_dir.empty()); |
| 102 | 101 |
| 103 // The standard location of the master prefs is next to the chrome binary. | 102 // The standard location of the master prefs is next to the chrome binary. |
| 104 FilePath master_prefs; | 103 FilePath master_prefs; |
| 105 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 104 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
| 106 return true; | 105 return true; |
| 107 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 106 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
| 108 | |
| 109 installer::MasterPreferences prefs(master_prefs); | 107 installer::MasterPreferences prefs(master_prefs); |
| 110 if (!prefs.read_from_file()) | 108 if (!prefs.read_from_file()) |
| 111 return true; | 109 return true; |
| 112 | 110 |
| 113 out_prefs->new_tabs = prefs.GetFirstRunTabs(); | 111 out_prefs->new_tabs = prefs.GetFirstRunTabs(); |
| 114 | 112 |
| 115 bool value = false; | 113 bool value = false; |
| 116 | 114 |
| 117 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
| 118 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ | 116 // 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) { | 218 if (value) { |
| 221 out_prefs->do_import_items |= importer::HOME_PAGE; | 219 out_prefs->do_import_items |= importer::HOME_PAGE; |
| 222 } else { | 220 } else { |
| 223 out_prefs->dont_import_items |= importer::HOME_PAGE; | 221 out_prefs->dont_import_items |= importer::HOME_PAGE; |
| 224 } | 222 } |
| 225 } | 223 } |
| 226 | 224 |
| 227 // Bookmarks are never imported unless specifically turned on. | 225 // Bookmarks are never imported unless specifically turned on. |
| 228 if (prefs.GetBool( | 226 if (prefs.GetBool( |
| 229 installer::master_preferences::kDistroImportBookmarksPref, | 227 installer::master_preferences::kDistroImportBookmarksPref, |
| 230 &value) && value) { | 228 &value)) { |
| 231 out_prefs->do_import_items |= importer::FAVORITES; | 229 if (value) { |
| 230 out_prefs->do_import_items |= importer::FAVORITES; | |
| 231 } else { | |
| 232 out_prefs->dont_import_items |= importer::FAVORITES; | |
| 233 } | |
| 232 } | 234 } |
| 233 | 235 |
| 234 if (prefs.GetBool( | 236 if (prefs.GetBool( |
| 235 installer::master_preferences::kMakeChromeDefaultForUser, | 237 installer::master_preferences::kMakeChromeDefaultForUser, |
| 236 &value) && value) { | 238 &value) && value) { |
| 237 out_prefs->make_chrome_default = true; | 239 out_prefs->make_chrome_default = true; |
| 238 } | 240 } |
| 239 | 241 |
| 240 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run | 242 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run |
| 241 // import process. http://crbug.com/49647 | 243 // import process. http://crbug.com/49647 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 | 518 |
| 517 scoped_refptr<ImporterList> importer_list(new ImporterList); | 519 scoped_refptr<ImporterList> importer_list(new ImporterList); |
| 518 importer_list->DetectSourceProfilesHack(); | 520 importer_list->DetectSourceProfilesHack(); |
| 519 | 521 |
| 520 // Do import if there is an available profile for us to import. | 522 // Do import if there is an available profile for us to import. |
| 521 if (importer_list->count() > 0) { | 523 if (importer_list->count() > 0) { |
| 522 // Don't show the warning dialog if import fails. | 524 // Don't show the warning dialog if import fails. |
| 523 importer_host->set_headless(); | 525 importer_host->set_headless(); |
| 524 int items = 0; | 526 int items = 0; |
| 525 | 527 |
| 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()) { | 528 if (IsOrganicFirstRun()) { |
| 532 if (!(dont_import_items & importer::HOME_PAGE) && !homepage_defined) | 529 // Home page is imported in organic builds only unless turned off or |
| 533 items = items | importer::HOME_PAGE; | 530 // defined in master_preferences. |
| 534 } else { | 531 if (homepage_defined) { |
| 535 if (import_items & importer::HOME_PAGE) | 532 dont_import_items |= importer::HOME_PAGE; |
| 536 items = items | importer::HOME_PAGE; | 533 if (import_items & importer::HOME_PAGE) |
| 537 } | 534 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 } | 535 } |
| 546 } else if (import_items & importer::SEARCH_ENGINES) { | 536 // Search engines are not imported automatically in organic builds if the |
| 547 items = items | importer::SEARCH_ENGINES; | 537 // user already has a user preferences directory. |
| 538 if (local_state_file_exists) { | |
| 539 dont_import_items |= importer::SEARCH_ENGINES; | |
| 540 if (import_items & importer::SEARCH_ENGINES) | |
| 541 import_items &= ~importer::SEARCH_ENGINES; | |
| 542 } | |
| 548 } | 543 } |
| 549 | 544 |
| 550 // Bookmarks are never imported, unless turned on in master_preferences. | 545 PrefService* user_prefs = profile->GetPrefs(); |
| 551 if (import_items & importer::FAVORITES) | 546 |
| 552 items = items | importer::FAVORITES; | 547 SetImportItem(user_prefs, |
| 548 prefs::kImportHistory, | |
| 549 import_items, | |
| 550 dont_import_items, | |
| 551 importer::HISTORY, | |
| 552 items); | |
| 553 SetImportItem(user_prefs, | |
| 554 prefs::kImportHomepage, | |
| 555 import_items, | |
| 556 dont_import_items, | |
| 557 importer::HOME_PAGE, | |
| 558 items); | |
| 559 SetImportItem(user_prefs, | |
| 560 prefs::kImportSearchEngine, | |
| 561 import_items, | |
| 562 dont_import_items, | |
| 563 importer::SEARCH_ENGINES, | |
| 564 items); | |
| 565 SetImportItem(user_prefs, | |
| 566 prefs::kImportBookmarks, | |
| 567 import_items, | |
| 568 dont_import_items, | |
| 569 importer::FAVORITES, | |
| 570 items); | |
| 553 | 571 |
| 554 ImportSettings(profile, importer_host, importer_list, items); | 572 ImportSettings(profile, importer_host, importer_list, items); |
| 555 } | 573 } |
| 556 | 574 |
| 557 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 575 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
| 558 | 576 |
| 559 // Launch the search engine dialog only for certain builds, and only if the | 577 // Launch the search engine dialog only for certain builds, and only if the |
| 560 // user has not already set preferences. | 578 // user has not already set preferences. |
| 561 if (IsOrganicFirstRun() && !local_state_file_exists) { | 579 if (IsOrganicFirstRun() && !local_state_file_exists) { |
| 562 // The home page string may be set in the preferences, but the user should | 580 // 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. | 595 // Set the first run bubble to minimal. |
| 578 FirstRun::SetMinimalFirstRunBubblePref(); | 596 FirstRun::SetMinimalFirstRunBubblePref(); |
| 579 } | 597 } |
| 580 FirstRun::SetShowWelcomePagePref(); | 598 FirstRun::SetShowWelcomePagePref(); |
| 581 FirstRun::SetPersonalDataManagerFirstRunPref(); | 599 FirstRun::SetPersonalDataManagerFirstRunPref(); |
| 582 | 600 |
| 583 process_singleton->Unlock(); | 601 process_singleton->Unlock(); |
| 584 FirstRun::CreateSentinel(); | 602 FirstRun::CreateSentinel(); |
| 585 } | 603 } |
| 586 | 604 |
| 605 // static | |
| 606 void FirstRun::SetImportItem(PrefService* user_prefs, | |
| 607 const char* pref_path, | |
| 608 int import_items, | |
| 609 int dont_import_items, | |
| 610 int import_type, | |
|
Mattias Nissler (ping if slow)
2011/07/25 11:12:36
should be enum ImportItem
| |
| 611 int& items) { | |
| 612 | |
| 613 // Work out whether an item is to be imported according to what is specified | |
| 614 // in master preferences. | |
| 615 bool should_import = false; | |
| 616 bool master_pref_set = (import_items | dont_import_items) & import_type; | |
| 617 bool master_pref = (import_items & ~dont_import_items) & import_type; | |
| 618 | |
| 619 if (import_type == importer::HISTORY | |
| 620 || ((import_type != importer::FAVORITES) && IsOrganicFirstRun())) { | |
| 621 // History is always imported unless turned off in master_preferences. | |
| 622 // Search engines are only imported in certain builds unless overridden | |
| 623 // in master_preferences. | |
| 624 // Home page is imported in organic builds only unless turned off in | |
| 625 // master_preferences. | |
| 626 should_import = !master_pref_set || master_pref; | |
| 627 } else { | |
| 628 // Bookmarks are never imported, unless turned on in master_preferences. | |
| 629 // Search engine and home page import behaviour is similar in non organic | |
| 630 // builds. | |
| 631 should_import = master_pref_set && master_pref; | |
| 632 } | |
|
Mattias Nissler (ping if slow)
2011/07/25 11:12:36
newline before comment
| |
| 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 |