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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 // A bitfield formed from values in AutoImportState to record the state of | 83 // A bitfield formed from values in AutoImportState to record the state of |
84 // AutoImport. This is used in testing to verify import startup actions that | 84 // AutoImport. This is used in testing to verify import startup actions that |
85 // occur before an observer can be registered in the test. | 85 // occur before an observer can be registered in the test. |
86 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE; | 86 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE; |
87 | 87 |
88 // Flags for functions of similar name. | 88 // Flags for functions of similar name. |
89 bool g_should_show_welcome_page = false; | 89 bool g_should_show_welcome_page = false; |
90 bool g_should_do_autofill_personal_data_manager_first_run = false; | 90 bool g_should_do_autofill_personal_data_manager_first_run = false; |
91 | 91 |
| 92 // Indicates whether this is first run. Populated when IsChromeFirstRun |
| 93 // is invoked, then used as a cache on subsequent calls. |
| 94 first_run::internal::FirstRunState g_first_run = |
| 95 first_run::internal::FIRST_RUN_UNKNOWN; |
| 96 |
92 // This class acts as an observer for the ImporterProgressObserver::ImportEnded | 97 // This class acts as an observer for the ImporterProgressObserver::ImportEnded |
93 // callback. When the import process is started, certain errors may cause | 98 // callback. When the import process is started, certain errors may cause |
94 // ImportEnded() to be called synchronously, but the typical case is that | 99 // ImportEnded() to be called synchronously, but the typical case is that |
95 // ImportEnded() is called asynchronously. Thus we have to handle both cases. | 100 // ImportEnded() is called asynchronously. Thus we have to handle both cases. |
96 class ImportEndedObserver : public importer::ImporterProgressObserver { | 101 class ImportEndedObserver : public importer::ImporterProgressObserver { |
97 public: | 102 public: |
98 ImportEndedObserver() : ended_(false) {} | 103 ImportEndedObserver() : ended_(false) {} |
99 ~ImportEndedObserver() override {} | 104 ~ImportEndedObserver() override {} |
100 | 105 |
101 // importer::ImporterProgressObserver: | 106 // importer::ImporterProgressObserver: |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 shell_integration::SetAsDefaultBrowser(); | 493 shell_integration::SetAsDefaultBrowser(); |
489 } | 494 } |
490 } | 495 } |
491 } | 496 } |
492 | 497 |
493 } // namespace | 498 } // namespace |
494 | 499 |
495 namespace first_run { | 500 namespace first_run { |
496 namespace internal { | 501 namespace internal { |
497 | 502 |
498 FirstRunState g_first_run = FIRST_RUN_UNKNOWN; | |
499 | |
500 void SetupMasterPrefsFromInstallPrefs( | 503 void SetupMasterPrefsFromInstallPrefs( |
501 const installer::MasterPreferences& install_prefs, | 504 const installer::MasterPreferences& install_prefs, |
502 MasterPrefs* out_prefs) { | 505 MasterPrefs* out_prefs) { |
503 ConvertStringVectorToGURLVector( | 506 ConvertStringVectorToGURLVector( |
504 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); | 507 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); |
505 | 508 |
506 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay, | 509 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay, |
507 &out_prefs->ping_delay); | 510 &out_prefs->ping_delay); |
508 | 511 |
509 bool value = false; | 512 bool value = false; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // -- Platform-specific functions -- | 613 // -- Platform-specific functions -- |
611 | 614 |
612 #if !defined(OS_LINUX) && !defined(OS_BSD) | 615 #if !defined(OS_LINUX) && !defined(OS_BSD) |
613 bool IsOrganicFirstRun() { | 616 bool IsOrganicFirstRun() { |
614 std::string brand; | 617 std::string brand; |
615 google_brand::GetBrand(&brand); | 618 google_brand::GetBrand(&brand); |
616 return google_brand::IsOrganicFirstRun(brand); | 619 return google_brand::IsOrganicFirstRun(brand); |
617 } | 620 } |
618 #endif | 621 #endif |
619 | 622 |
| 623 FirstRunState DetermineFirstRunState(bool has_sentinel, |
| 624 bool force_first_run, |
| 625 bool no_first_run) { |
| 626 return (force_first_run || (!has_sentinel && !no_first_run)) |
| 627 ? FIRST_RUN_TRUE |
| 628 : FIRST_RUN_FALSE; |
| 629 } |
| 630 |
620 } // namespace internal | 631 } // namespace internal |
621 | 632 |
622 MasterPrefs::MasterPrefs() | 633 MasterPrefs::MasterPrefs() |
623 : ping_delay(0), | 634 : ping_delay(0), |
624 homepage_defined(false), | 635 homepage_defined(false), |
625 do_import_items(0), | 636 do_import_items(0), |
626 dont_import_items(0), | 637 dont_import_items(0), |
627 make_chrome_default_for_user(false), | 638 make_chrome_default_for_user(false), |
628 suppress_first_run_default_browser_prompt(false), | 639 suppress_first_run_default_browser_prompt(false), |
629 welcome_page_on_os_upgrade_enabled(true) { | 640 welcome_page_on_os_upgrade_enabled(true) { |
630 } | 641 } |
631 | 642 |
632 MasterPrefs::~MasterPrefs() {} | 643 MasterPrefs::~MasterPrefs() {} |
633 | 644 |
634 bool IsChromeFirstRun() { | 645 bool IsChromeFirstRun() { |
635 if (internal::g_first_run == internal::FIRST_RUN_UNKNOWN) { | 646 if (g_first_run == internal::FIRST_RUN_UNKNOWN) { |
636 internal::g_first_run = internal::FIRST_RUN_FALSE; | |
637 const base::CommandLine* command_line = | 647 const base::CommandLine* command_line = |
638 base::CommandLine::ForCurrentProcess(); | 648 base::CommandLine::ForCurrentProcess(); |
639 if (command_line->HasSwitch(switches::kForceFirstRun) || | 649 g_first_run = internal::DetermineFirstRunState( |
640 (!command_line->HasSwitch(switches::kNoFirstRun) && | 650 internal::IsFirstRunSentinelPresent(), |
641 !internal::IsFirstRunSentinelPresent())) { | 651 command_line->HasSwitch(switches::kForceFirstRun), |
642 internal::g_first_run = internal::FIRST_RUN_TRUE; | 652 command_line->HasSwitch(switches::kNoFirstRun)); |
643 } | |
644 } | 653 } |
645 return internal::g_first_run == internal::FIRST_RUN_TRUE; | 654 return g_first_run == internal::FIRST_RUN_TRUE; |
646 } | 655 } |
647 | 656 |
648 #if defined(OS_MACOSX) | 657 #if defined(OS_MACOSX) |
649 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { | 658 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { |
650 return command_line.HasSwitch(switches::kNoFirstRun); | 659 return command_line.HasSwitch(switches::kNoFirstRun); |
651 } | 660 } |
652 #endif | 661 #endif |
653 | 662 |
654 bool IsMetricsReportingOptIn() { | 663 bool IsMetricsReportingOptIn() { |
655 // Metrics reporting is opt-out by default for all platforms and channels. | 664 // Metrics reporting is opt-out by default for all platforms and channels. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 SetShouldDoPersonalDataManagerFirstRun(); | 850 SetShouldDoPersonalDataManagerFirstRun(); |
842 | 851 |
843 internal::DoPostImportPlatformSpecificTasks(profile); | 852 internal::DoPostImportPlatformSpecificTasks(profile); |
844 } | 853 } |
845 | 854 |
846 uint16_t auto_import_state() { | 855 uint16_t auto_import_state() { |
847 return g_auto_import_state; | 856 return g_auto_import_state; |
848 } | 857 } |
849 | 858 |
850 } // namespace first_run | 859 } // namespace first_run |
OLD | NEW |