| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ProfileManager::GetDefaultProfileDir(user_data_dir); | 50 ProfileManager::GetDefaultProfileDir(user_data_dir); |
| 51 if (create_profile_dir) { | 51 if (create_profile_dir) { |
| 52 if (!file_util::PathExists(default_pref_dir)) { | 52 if (!file_util::PathExists(default_pref_dir)) { |
| 53 if (!file_util::CreateDirectory(default_pref_dir)) | 53 if (!file_util::CreateDirectory(default_pref_dir)) |
| 54 return FilePath(); | 54 return FilePath(); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return ProfileManager::GetProfilePrefsPath(default_pref_dir); | 57 return ProfileManager::GetProfilePrefsPath(default_pref_dir); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Sets the |items| bitfield according to whether the import data specified by |
| 61 // |import_type| should be be auto imported or not. |
| 62 void SetImportItem(PrefService* user_prefs, |
| 63 const char* pref_path, |
| 64 int import_items, |
| 65 int dont_import_items, |
| 66 importer::ImportItem import_type, |
| 67 int& items) { |
| 68 // Work out whether an item is to be imported according to what is specified |
| 69 // in master preferences. |
| 70 bool should_import = false; |
| 71 bool master_pref_set = |
| 72 ((import_items | dont_import_items) & import_type) != 0; |
| 73 bool master_pref = ((import_items & ~dont_import_items) & import_type) != 0; |
| 74 |
| 75 if (import_type == importer::HISTORY || |
| 76 ((import_type != importer::FAVORITES) && |
| 77 FirstRun::IsOrganicFirstRun())) { |
| 78 // History is always imported unless turned off in master_preferences. |
| 79 // Search engines are only imported in certain builds unless overridden |
| 80 // in master_preferences.Home page is imported in organic builds only unless |
| 81 // turned off in master_preferences. |
| 82 should_import = !master_pref_set || master_pref; |
| 83 } else { |
| 84 // Bookmarks are never imported, unless turned on in master_preferences. |
| 85 // Search engine and home page import behaviour is similar in non organic |
| 86 // builds. |
| 87 should_import = master_pref_set && master_pref; |
| 88 } |
| 89 |
| 90 // If an import policy is set, import items according to policy. If no master |
| 91 // preference is set, but a corresponding recommended policy is set, import |
| 92 // item according to recommended policy. If both a master preference and a |
| 93 // recommended policy is set, the master preference wins. If neither |
| 94 // recommended nor managed policies are set, import item according to what we |
| 95 // worked out above. |
| 96 if (master_pref_set) |
| 97 user_prefs->SetBoolean(pref_path, should_import); |
| 98 |
| 99 if (!user_prefs->FindPreference(pref_path)->IsDefaultValue()) { |
| 100 if (user_prefs->GetBoolean(pref_path)) |
| 101 items |= import_type; |
| 102 } else { // no policy (recommended or managed) is set |
| 103 if (should_import) |
| 104 items |= import_type; |
| 105 } |
| 106 |
| 107 user_prefs->ClearPref(pref_path); |
| 108 } |
| 109 |
| 60 } // namespace | 110 } // namespace |
| 61 | 111 |
| 62 // FirstRun ------------------------------------------------------------------- | 112 // FirstRun ------------------------------------------------------------------- |
| 63 | 113 |
| 64 FirstRun::FirstRunState FirstRun::first_run_ = FIRST_RUN_UNKNOWN; | 114 FirstRun::FirstRunState FirstRun::first_run_ = FIRST_RUN_UNKNOWN; |
| 65 | 115 |
| 66 FirstRun::MasterPrefs::MasterPrefs() | 116 FirstRun::MasterPrefs::MasterPrefs() |
| 67 : ping_delay(0), | 117 : ping_delay(0), |
| 68 homepage_defined(false), | 118 homepage_defined(false), |
| 69 do_import_items(0), | 119 do_import_items(0), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 98 // static | 148 // static |
| 99 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, | 149 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, |
| 100 MasterPrefs* out_prefs) { | 150 MasterPrefs* out_prefs) { |
| 101 DCHECK(!user_data_dir.empty()); | 151 DCHECK(!user_data_dir.empty()); |
| 102 | 152 |
| 103 // The standard location of the master prefs is next to the chrome binary. | 153 // The standard location of the master prefs is next to the chrome binary. |
| 104 FilePath master_prefs; | 154 FilePath master_prefs; |
| 105 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 155 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
| 106 return true; | 156 return true; |
| 107 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 157 master_prefs = master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
| 108 | |
| 109 installer::MasterPreferences prefs(master_prefs); | 158 installer::MasterPreferences prefs(master_prefs); |
| 110 if (!prefs.read_from_file()) | 159 if (!prefs.read_from_file()) |
| 111 return true; | 160 return true; |
| 112 | 161 |
| 113 out_prefs->new_tabs = prefs.GetFirstRunTabs(); | 162 out_prefs->new_tabs = prefs.GetFirstRunTabs(); |
| 114 | 163 |
| 115 bool value = false; | 164 bool value = false; |
| 116 | 165 |
| 117 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
| 118 // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/ | 167 // 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) { | 269 if (value) { |
| 221 out_prefs->do_import_items |= importer::HOME_PAGE; | 270 out_prefs->do_import_items |= importer::HOME_PAGE; |
| 222 } else { | 271 } else { |
| 223 out_prefs->dont_import_items |= importer::HOME_PAGE; | 272 out_prefs->dont_import_items |= importer::HOME_PAGE; |
| 224 } | 273 } |
| 225 } | 274 } |
| 226 | 275 |
| 227 // Bookmarks are never imported unless specifically turned on. | 276 // Bookmarks are never imported unless specifically turned on. |
| 228 if (prefs.GetBool( | 277 if (prefs.GetBool( |
| 229 installer::master_preferences::kDistroImportBookmarksPref, | 278 installer::master_preferences::kDistroImportBookmarksPref, |
| 230 &value) && value) { | 279 &value)) { |
| 231 out_prefs->do_import_items |= importer::FAVORITES; | 280 if (value) |
| 281 out_prefs->do_import_items |= importer::FAVORITES; |
| 282 else |
| 283 out_prefs->dont_import_items |= importer::FAVORITES; |
| 232 } | 284 } |
| 233 | 285 |
| 234 if (prefs.GetBool( | 286 if (prefs.GetBool( |
| 235 installer::master_preferences::kMakeChromeDefaultForUser, | 287 installer::master_preferences::kMakeChromeDefaultForUser, |
| 236 &value) && value) { | 288 &value) && value) { |
| 237 out_prefs->make_chrome_default = true; | 289 out_prefs->make_chrome_default = true; |
| 238 } | 290 } |
| 239 | 291 |
| 240 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run | 292 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run |
| 241 // import process. http://crbug.com/49647 | 293 // import process. http://crbug.com/49647 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 568 |
| 517 scoped_refptr<ImporterList> importer_list(new ImporterList); | 569 scoped_refptr<ImporterList> importer_list(new ImporterList); |
| 518 importer_list->DetectSourceProfilesHack(); | 570 importer_list->DetectSourceProfilesHack(); |
| 519 | 571 |
| 520 // Do import if there is an available profile for us to import. | 572 // Do import if there is an available profile for us to import. |
| 521 if (importer_list->count() > 0) { | 573 if (importer_list->count() > 0) { |
| 522 // Don't show the warning dialog if import fails. | 574 // Don't show the warning dialog if import fails. |
| 523 importer_host->set_headless(); | 575 importer_host->set_headless(); |
| 524 int items = 0; | 576 int items = 0; |
| 525 | 577 |
| 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()) { | 578 if (IsOrganicFirstRun()) { |
| 532 if (!(dont_import_items & importer::HOME_PAGE) && !homepage_defined) | 579 // Home page is imported in organic builds only unless turned off or |
| 533 items = items | importer::HOME_PAGE; | 580 // defined in master_preferences. |
| 534 } else { | 581 if (homepage_defined) { |
| 535 if (import_items & importer::HOME_PAGE) | 582 dont_import_items |= importer::HOME_PAGE; |
| 536 items = items | importer::HOME_PAGE; | 583 if (import_items & importer::HOME_PAGE) |
| 537 } | 584 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 } | 585 } |
| 546 } else if (import_items & importer::SEARCH_ENGINES) { | 586 // Search engines are not imported automatically in organic builds if the |
| 547 items = items | importer::SEARCH_ENGINES; | 587 // user already has a user preferences directory. |
| 588 if (local_state_file_exists) { |
| 589 dont_import_items |= importer::SEARCH_ENGINES; |
| 590 if (import_items & importer::SEARCH_ENGINES) |
| 591 import_items &= ~importer::SEARCH_ENGINES; |
| 592 } |
| 548 } | 593 } |
| 549 | 594 |
| 550 // Bookmarks are never imported, unless turned on in master_preferences. | 595 PrefService* user_prefs = profile->GetPrefs(); |
| 551 if (import_items & importer::FAVORITES) | 596 |
| 552 items = items | importer::FAVORITES; | 597 SetImportItem(user_prefs, |
| 598 prefs::kImportHistory, |
| 599 import_items, |
| 600 dont_import_items, |
| 601 importer::HISTORY, |
| 602 items); |
| 603 SetImportItem(user_prefs, |
| 604 prefs::kImportHomepage, |
| 605 import_items, |
| 606 dont_import_items, |
| 607 importer::HOME_PAGE, |
| 608 items); |
| 609 SetImportItem(user_prefs, |
| 610 prefs::kImportSearchEngine, |
| 611 import_items, |
| 612 dont_import_items, |
| 613 importer::SEARCH_ENGINES, |
| 614 items); |
| 615 SetImportItem(user_prefs, |
| 616 prefs::kImportBookmarks, |
| 617 import_items, |
| 618 dont_import_items, |
| 619 importer::FAVORITES, |
| 620 items); |
| 553 | 621 |
| 554 ImportSettings(profile, importer_host, importer_list, items); | 622 ImportSettings(profile, importer_host, importer_list, items); |
| 555 } | 623 } |
| 556 | 624 |
| 557 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 625 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
| 558 | 626 |
| 559 // Launch the search engine dialog only for certain builds, and only if the | 627 // Launch the search engine dialog only for certain builds, and only if the |
| 560 // user has not already set preferences. | 628 // user has not already set preferences. |
| 561 if (IsOrganicFirstRun() && !local_state_file_exists) { | 629 if (IsOrganicFirstRun() && !local_state_file_exists) { |
| 562 // The home page string may be set in the preferences, but the user should | 630 // The home page string may be set in the preferences, but the user should |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 if (!observer->ended()) { | 717 if (!observer->ended()) { |
| 650 observer->set_should_quit_message_loop(); | 718 observer->set_should_quit_message_loop(); |
| 651 MessageLoop::current()->Run(); | 719 MessageLoop::current()->Run(); |
| 652 } | 720 } |
| 653 | 721 |
| 654 // Unfortunately there's no success/fail signal in ImporterHost. | 722 // Unfortunately there's no success/fail signal in ImporterHost. |
| 655 return true; | 723 return true; |
| 656 } | 724 } |
| 657 | 725 |
| 658 #endif // OS_POSIX | 726 #endif // OS_POSIX |
| OLD | NEW |