OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/updater/extension_updater.h" | 22 #include "chrome/browser/extensions/updater/extension_updater.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "content/public/browser/user_metrics.h" | 57 #include "content/public/browser/user_metrics.h" |
57 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
58 #include "google_apis/gaia/gaia_auth_util.h" | 59 #include "google_apis/gaia/gaia_auth_util.h" |
59 #include "googleurl/src/gurl.h" | 60 #include "googleurl/src/gurl.h" |
60 | 61 |
61 using content::UserMetricsAction; | 62 using content::UserMetricsAction; |
62 | 63 |
63 namespace { | 64 namespace { |
64 | 65 |
65 // Flags for functions of similar name. | 66 // Flags for functions of similar name. |
66 bool should_show_welcome_page_ = false; | 67 bool g_should_show_welcome_page = false; |
67 bool should_do_autofill_personal_data_manager_first_run_ = false; | 68 bool g_should_do_autofill_personal_data_manager_first_run = false; |
68 | 69 |
69 // Flags indicating whether a first-run profile auto import was performed, and | 70 // Flags indicating whether a first-run profile auto import was performed, and |
70 // whether the importer process exited successfully. | 71 // whether the importer process exited successfully. |
71 bool did_perform_profile_import = false; | 72 bool did_perform_profile_import = false; |
72 bool profile_import_exited_successfully = false; | 73 bool profile_import_exited_successfully = false; |
73 | 74 |
74 // Helper class that performs delayed first-run tasks that need more of the | 75 // Helper class that performs delayed first-run tasks that need more of the |
75 // chrome infrastructure to be up and running before they can be attempted. | 76 // chrome infrastructure to be up and running before they can be attempted. |
76 class FirstRunDelayedTasks : public content::NotificationObserver { | 77 class FirstRunDelayedTasks : public content::NotificationObserver { |
77 public: | 78 public: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return ProfileManager::GetProfilePrefsPath(default_pref_dir); | 144 return ProfileManager::GetProfilePrefsPath(default_pref_dir); |
144 } | 145 } |
145 | 146 |
146 // Sets the |items| bitfield according to whether the import data specified by | 147 // Sets the |items| bitfield according to whether the import data specified by |
147 // |import_type| should be be auto imported or not. | 148 // |import_type| should be be auto imported or not. |
148 void SetImportItem(PrefService* user_prefs, | 149 void SetImportItem(PrefService* user_prefs, |
149 const char* pref_path, | 150 const char* pref_path, |
150 int import_items, | 151 int import_items, |
151 int dont_import_items, | 152 int dont_import_items, |
152 importer::ImportItem import_type, | 153 importer::ImportItem import_type, |
153 int& items) { | 154 int* items) { |
154 // Work out whether an item is to be imported according to what is specified | 155 // Work out whether an item is to be imported according to what is specified |
155 // in master preferences. | 156 // in master preferences. |
156 bool should_import = false; | 157 bool should_import = false; |
157 bool master_pref_set = | 158 bool master_pref_set = |
158 ((import_items | dont_import_items) & import_type) != 0; | 159 ((import_items | dont_import_items) & import_type) != 0; |
159 bool master_pref = ((import_items & ~dont_import_items) & import_type) != 0; | 160 bool master_pref = ((import_items & ~dont_import_items) & import_type) != 0; |
160 | 161 |
161 if (import_type == importer::HISTORY || | 162 if (import_type == importer::HISTORY || |
162 ((import_type != importer::FAVORITES) && | 163 (import_type != importer::FAVORITES && |
163 first_run::internal::IsOrganicFirstRun())) { | 164 first_run::internal::IsOrganicFirstRun())) { |
164 // History is always imported unless turned off in master_preferences. | 165 // History is always imported unless turned off in master_preferences. |
165 // Search engines are only imported in certain builds unless overridden | 166 // Search engines and home page are imported in organic builds only |
166 // in master_preferences.Home page is imported in organic builds only unless | 167 // unless turned off in master_preferences. |
167 // turned off in master_preferences. | |
168 should_import = !master_pref_set || master_pref; | 168 should_import = !master_pref_set || master_pref; |
169 } else { | 169 } else { |
170 // Bookmarks are never imported, unless turned on in master_preferences. | 170 // Bookmarks are never imported, unless turned on in master_preferences. |
171 // Search engine and home page import behaviour is similar in non organic | 171 // Search engine and home page import behaviour is similar in non organic |
172 // builds. | 172 // builds. |
173 should_import = master_pref_set && master_pref; | 173 should_import = master_pref_set && master_pref; |
174 } | 174 } |
175 | 175 |
176 // If an import policy is set, import items according to policy. If no master | 176 // If an import policy is set, import items according to policy. If no master |
177 // preference is set, but a corresponding recommended policy is set, import | 177 // preference is set, but a corresponding recommended policy is set, import |
178 // item according to recommended policy. If both a master preference and a | 178 // item according to recommended policy. If both a master preference and a |
179 // recommended policy is set, the master preference wins. If neither | 179 // recommended policy is set, the master preference wins. If neither |
180 // recommended nor managed policies are set, import item according to what we | 180 // recommended nor managed policies are set, import item according to what we |
181 // worked out above. | 181 // worked out above. |
182 if (master_pref_set) | 182 if (master_pref_set) |
183 user_prefs->SetBoolean(pref_path, should_import); | 183 user_prefs->SetBoolean(pref_path, should_import); |
184 | 184 |
185 if (!user_prefs->FindPreference(pref_path)->IsDefaultValue()) { | 185 if (!user_prefs->FindPreference(pref_path)->IsDefaultValue()) { |
186 if (user_prefs->GetBoolean(pref_path)) | 186 if (user_prefs->GetBoolean(pref_path)) |
187 items |= import_type; | 187 *items |= import_type; |
188 } else { // no policy (recommended or managed) is set | 188 } else { // no policy (recommended or managed) is set |
189 if (should_import) | 189 if (should_import) |
190 items |= import_type; | 190 *items |= import_type; |
191 } | 191 } |
192 | 192 |
193 user_prefs->ClearPref(pref_path); | 193 user_prefs->ClearPref(pref_path); |
194 } | 194 } |
195 | 195 |
196 // Imports bookmarks from an html file. The path to the file is provided in | 196 // Imports bookmarks from an html file. The path to the file is provided in |
197 // the command line. | 197 // the command line. |
198 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { | 198 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { |
199 base::FilePath file_path = | 199 base::FilePath file_path = |
200 cmdline.GetSwitchValuePath(switches::kImportFromFile); | 200 cmdline.GetSwitchValuePath(switches::kImportFromFile); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return false; | 276 return false; |
277 | 277 |
278 // The master prefs are regular prefs so we can just copy the file | 278 // The master prefs are regular prefs so we can just copy the file |
279 // to the default place and they just work. | 279 // to the default place and they just work. |
280 return file_util::CopyFile(master_prefs_path, user_prefs); | 280 return file_util::CopyFile(master_prefs_path, user_prefs); |
281 } | 281 } |
282 | 282 |
283 void SetupMasterPrefsFromInstallPrefs( | 283 void SetupMasterPrefsFromInstallPrefs( |
284 const installer::MasterPreferences& install_prefs, | 284 const installer::MasterPreferences& install_prefs, |
285 MasterPrefs* out_prefs) { | 285 MasterPrefs* out_prefs) { |
| 286 ConvertStringVectorToGURLVector( |
| 287 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); |
| 288 |
| 289 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay, |
| 290 &out_prefs->ping_delay); |
| 291 |
286 bool value = false; | 292 bool value = false; |
287 if (install_prefs.GetBool( | 293 if (install_prefs.GetBool( |
288 installer::master_preferences::kDistroImportSearchPref, &value)) { | 294 installer::master_preferences::kDistroImportSearchPref, &value)) { |
289 if (value) { | 295 if (value) { |
290 out_prefs->do_import_items |= importer::SEARCH_ENGINES; | 296 out_prefs->do_import_items |= importer::SEARCH_ENGINES; |
291 } else { | 297 } else { |
292 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; | 298 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; |
293 } | 299 } |
294 } | 300 } |
295 | 301 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 ShellIntegration::SetAsDefaultBrowser(); | 373 ShellIntegration::SetAsDefaultBrowser(); |
368 } | 374 } |
369 } else { | 375 } else { |
370 if (g_browser_process->local_state()->GetBoolean( | 376 if (g_browser_process->local_state()->GetBoolean( |
371 prefs::kDefaultBrowserSettingEnabled)) { | 377 prefs::kDefaultBrowserSettingEnabled)) { |
372 ShellIntegration::SetAsDefaultBrowser(); | 378 ShellIntegration::SetAsDefaultBrowser(); |
373 } | 379 } |
374 } | 380 } |
375 } | 381 } |
376 | 382 |
377 void SetRLZPref(first_run::MasterPrefs* out_prefs, | |
378 installer::MasterPreferences* install_prefs) { | |
379 if (!install_prefs->GetInt(installer::master_preferences::kDistroPingDelay, | |
380 &out_prefs->ping_delay)) { | |
381 // Default value in case master preferences is missing or corrupt, | |
382 // or ping_delay is missing. | |
383 out_prefs->ping_delay = 90; | |
384 } | |
385 } | |
386 | |
387 // -- Platform-specific functions -- | 383 // -- Platform-specific functions -- |
388 | 384 |
389 #if !defined(OS_LINUX) && !defined(OS_BSD) | 385 #if !defined(OS_LINUX) && !defined(OS_BSD) |
390 bool IsOrganicFirstRun() { | 386 bool IsOrganicFirstRun() { |
391 std::string brand; | 387 std::string brand; |
392 google_util::GetBrand(&brand); | 388 google_util::GetBrand(&brand); |
393 return google_util::IsOrganicFirstRun(brand); | 389 return google_util::IsOrganicFirstRun(brand); |
394 } | 390 } |
395 #endif | 391 #endif |
396 | 392 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { | 466 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { |
471 // Set the new state as long as the bubble wasn't explicitly suppressed | 467 // Set the new state as long as the bubble wasn't explicitly suppressed |
472 // already. | 468 // already. |
473 local_state->SetInteger(prefs::kShowFirstRunBubbleOption, | 469 local_state->SetInteger(prefs::kShowFirstRunBubbleOption, |
474 show_bubble_option); | 470 show_bubble_option); |
475 } | 471 } |
476 return true; | 472 return true; |
477 } | 473 } |
478 | 474 |
479 void SetShouldShowWelcomePage() { | 475 void SetShouldShowWelcomePage() { |
480 should_show_welcome_page_ = true; | 476 g_should_show_welcome_page = true; |
481 } | 477 } |
482 | 478 |
483 bool ShouldShowWelcomePage() { | 479 bool ShouldShowWelcomePage() { |
484 bool retval = should_show_welcome_page_; | 480 bool retval = g_should_show_welcome_page; |
485 should_show_welcome_page_ = false; | 481 g_should_show_welcome_page = false; |
486 return retval; | 482 return retval; |
487 } | 483 } |
488 | 484 |
489 void SetShouldDoPersonalDataManagerFirstRun() { | 485 void SetShouldDoPersonalDataManagerFirstRun() { |
490 should_do_autofill_personal_data_manager_first_run_ = true; | 486 g_should_do_autofill_personal_data_manager_first_run = true; |
491 } | 487 } |
492 | 488 |
493 bool ShouldDoPersonalDataManagerFirstRun() { | 489 bool ShouldDoPersonalDataManagerFirstRun() { |
494 bool retval = should_do_autofill_personal_data_manager_first_run_; | 490 bool retval = g_should_do_autofill_personal_data_manager_first_run; |
495 should_do_autofill_personal_data_manager_first_run_ = false; | 491 g_should_do_autofill_personal_data_manager_first_run = false; |
496 return retval; | 492 return retval; |
497 } | 493 } |
498 | 494 |
499 void LogFirstRunMetric(FirstRunBubbleMetric metric) { | 495 void LogFirstRunMetric(FirstRunBubbleMetric metric) { |
500 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, | 496 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, |
501 NUM_FIRST_RUN_BUBBLE_METRICS); | 497 NUM_FIRST_RUN_BUBBLE_METRICS); |
502 } | 498 } |
503 | 499 |
504 namespace { | 500 namespace { |
505 CommandLine* GetExtraArgumentsInstance() { | 501 CommandLine* GetExtraArgumentsInstance() { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 #if defined(OS_CHROMEOS) | 611 #if defined(OS_CHROMEOS) |
616 // Chrome OS has its own out-of-box-experience code. Create the sentinel to | 612 // Chrome OS has its own out-of-box-experience code. Create the sentinel to |
617 // mark the fact that we've run once but skip the full first-run flow. | 613 // mark the fact that we've run once but skip the full first-run flow. |
618 CreateSentinel(); | 614 CreateSentinel(); |
619 return SKIP_FIRST_RUN_TASKS; | 615 return SKIP_FIRST_RUN_TASKS; |
620 #endif | 616 #endif |
621 | 617 |
622 base::FilePath master_prefs_path; | 618 base::FilePath master_prefs_path; |
623 scoped_ptr<installer::MasterPreferences> | 619 scoped_ptr<installer::MasterPreferences> |
624 install_prefs(internal::LoadMasterPrefs(&master_prefs_path)); | 620 install_prefs(internal::LoadMasterPrefs(&master_prefs_path)); |
625 if (!install_prefs.get()) | |
626 return DO_FIRST_RUN_TASKS; | |
627 | 621 |
628 ConvertStringVectorToGURLVector( | 622 // Default value in case master preferences is missing or corrupt, or |
629 install_prefs->GetFirstRunTabs(), &out_prefs->new_tabs); | 623 // ping_delay is missing. |
| 624 out_prefs->ping_delay = 90; |
| 625 if (install_prefs.get()) { |
| 626 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) |
| 627 return EULA_EXIT_NOW; |
630 | 628 |
631 internal::SetRLZPref(out_prefs, install_prefs.get()); | 629 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) |
| 630 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; |
632 | 631 |
633 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) | 632 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); |
634 return EULA_EXIT_NOW; | |
635 | 633 |
636 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) | 634 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); |
637 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; | |
638 | 635 |
639 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); | 636 internal::SetImportPreferencesAndLaunchImport(out_prefs, |
| 637 install_prefs.get()); |
640 | 638 |
641 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); | 639 internal::SetDefaultBrowser(install_prefs.get()); |
642 | 640 } |
643 internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get()); | |
644 internal::SetDefaultBrowser(install_prefs.get()); | |
645 | 641 |
646 return DO_FIRST_RUN_TASKS; | 642 return DO_FIRST_RUN_TASKS; |
647 } | 643 } |
648 | 644 |
649 void AutoImport( | 645 void AutoImport( |
650 Profile* profile, | 646 Profile* profile, |
651 bool homepage_defined, | 647 bool homepage_defined, |
652 int import_items, | 648 int import_items, |
653 int dont_import_items) { | 649 int dont_import_items) { |
654 #if !defined(USE_AURA) | 650 #if !defined(USE_AURA) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 689 } |
694 } | 690 } |
695 | 691 |
696 PrefService* user_prefs = profile->GetPrefs(); | 692 PrefService* user_prefs = profile->GetPrefs(); |
697 | 693 |
698 SetImportItem(user_prefs, | 694 SetImportItem(user_prefs, |
699 prefs::kImportHistory, | 695 prefs::kImportHistory, |
700 import_items, | 696 import_items, |
701 dont_import_items, | 697 dont_import_items, |
702 importer::HISTORY, | 698 importer::HISTORY, |
703 items); | 699 &items); |
704 SetImportItem(user_prefs, | 700 SetImportItem(user_prefs, |
705 prefs::kImportHomepage, | 701 prefs::kImportHomepage, |
706 import_items, | 702 import_items, |
707 dont_import_items, | 703 dont_import_items, |
708 importer::HOME_PAGE, | 704 importer::HOME_PAGE, |
709 items); | 705 &items); |
710 SetImportItem(user_prefs, | 706 SetImportItem(user_prefs, |
711 prefs::kImportSearchEngine, | 707 prefs::kImportSearchEngine, |
712 import_items, | 708 import_items, |
713 dont_import_items, | 709 dont_import_items, |
714 importer::SEARCH_ENGINES, | 710 importer::SEARCH_ENGINES, |
715 items); | 711 &items); |
716 SetImportItem(user_prefs, | 712 SetImportItem(user_prefs, |
717 prefs::kImportBookmarks, | 713 prefs::kImportBookmarks, |
718 import_items, | 714 import_items, |
719 dont_import_items, | 715 dont_import_items, |
720 importer::FAVORITES, | 716 importer::FAVORITES, |
721 items); | 717 &items); |
722 | 718 |
723 importer::LogImporterUseToMetrics( | 719 importer::LogImporterUseToMetrics( |
724 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); | 720 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); |
725 | 721 |
726 profile_import_exited_successfully = | 722 profile_import_exited_successfully = |
727 internal::ImportSettings(profile, importer_host, importer_list, items); | 723 internal::ImportSettings(profile, importer_host, importer_list, items); |
728 DCHECK(profile_import_exited_successfully); | 724 DCHECK(profile_import_exited_successfully); |
729 } | 725 } |
730 | 726 |
731 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 727 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
732 | 728 |
733 first_run::CreateSentinel(); | |
734 #endif // !defined(USE_AURA) | 729 #endif // !defined(USE_AURA) |
735 did_perform_profile_import = true; | 730 did_perform_profile_import = true; |
736 } | 731 } |
737 | 732 |
738 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { | 733 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { |
739 if (make_chrome_default && | 734 if (make_chrome_default && |
740 ShellIntegration::CanSetAsDefaultBrowser() == | 735 ShellIntegration::CanSetAsDefaultBrowser() == |
741 ShellIntegration::SET_DEFAULT_UNATTENDED) { | 736 ShellIntegration::SET_DEFAULT_UNATTENDED) { |
742 ShellIntegration::SetAsDefaultBrowser(); | 737 ShellIntegration::SetAsDefaultBrowser(); |
743 } | 738 } |
(...skipping 19 matching lines...) Expand all Loading... |
763 internal::DoPostImportPlatformSpecificTasks(); | 758 internal::DoPostImportPlatformSpecificTasks(); |
764 } | 759 } |
765 | 760 |
766 bool DidPerformProfileImport(bool* exited_successfully) { | 761 bool DidPerformProfileImport(bool* exited_successfully) { |
767 if (exited_successfully) | 762 if (exited_successfully) |
768 *exited_successfully = profile_import_exited_successfully; | 763 *exited_successfully = profile_import_exited_successfully; |
769 return did_perform_profile_import; | 764 return did_perform_profile_import; |
770 } | 765 } |
771 | 766 |
772 } // namespace first_run | 767 } // namespace first_run |
OLD | NEW |