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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "chrome/browser/signin/signin_manager_factory.h" | 40 #include "chrome/browser/signin/signin_manager_factory.h" |
41 #include "chrome/browser/signin/signin_promo.h" | 41 #include "chrome/browser/signin/signin_promo.h" |
42 #include "chrome/browser/signin/signin_tracker.h" | 42 #include "chrome/browser/signin/signin_tracker.h" |
43 #include "chrome/browser/ui/browser.h" | 43 #include "chrome/browser/ui/browser.h" |
44 #include "chrome/browser/ui/browser_finder.h" | 44 #include "chrome/browser/ui/browser_finder.h" |
45 #include "chrome/browser/ui/chrome_pages.h" | 45 #include "chrome/browser/ui/chrome_pages.h" |
46 #include "chrome/browser/ui/global_error/global_error_service.h" | 46 #include "chrome/browser/ui/global_error/global_error_service.h" |
47 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 47 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 48 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
49 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 49 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 50 #include "chrome/common/chrome_constants.h" |
50 #include "chrome/common/chrome_paths.h" | 51 #include "chrome/common/chrome_paths.h" |
51 #include "chrome/common/chrome_switches.h" | 52 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
53 #include "chrome/common/url_constants.h" | 54 #include "chrome/common/url_constants.h" |
54 #include "chrome/installer/util/master_preferences.h" | 55 #include "chrome/installer/util/master_preferences.h" |
55 #include "chrome/installer/util/master_preferences_constants.h" | 56 #include "chrome/installer/util/master_preferences_constants.h" |
56 #include "chrome/installer/util/util_constants.h" | 57 #include "chrome/installer/util/util_constants.h" |
57 #include "components/user_prefs/pref_registry_syncable.h" | 58 #include "components/user_prefs/pref_registry_syncable.h" |
58 #include "content/public/browser/notification_observer.h" | 59 #include "content/public/browser/notification_observer.h" |
59 #include "content/public/browser/notification_registrar.h" | 60 #include "content/public/browser/notification_registrar.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 if (g_browser_process->local_state()->GetBoolean( | 442 if (g_browser_process->local_state()->GetBoolean( |
442 prefs::kDefaultBrowserSettingEnabled)) { | 443 prefs::kDefaultBrowserSettingEnabled)) { |
443 ShellIntegration::SetAsDefaultBrowser(); | 444 ShellIntegration::SetAsDefaultBrowser(); |
444 } | 445 } |
445 } else if (make_chrome_default_for_user) { | 446 } else if (make_chrome_default_for_user) { |
446 ShellIntegration::SetAsDefaultBrowser(); | 447 ShellIntegration::SetAsDefaultBrowser(); |
447 } | 448 } |
448 } | 449 } |
449 } | 450 } |
450 | 451 |
451 bool IsFirstRunSentinelPresent() { | |
452 base::FilePath first_run_sentinel; | |
453 // Treat sentinel as being present if the path can't be obtained. | |
454 if (!first_run::internal::GetFirstRunSentinelFilePath(&first_run_sentinel) || | |
455 base::PathExists(first_run_sentinel)) { | |
456 return true; | |
457 } | |
458 // Sentinel is truly absent if there's no legacy path or legacy doesn't exist. | |
459 base::FilePath legacy_first_run_sentinel; | |
460 if (!first_run::internal::GetLegacyFirstRunSentinelFilePath( | |
461 &legacy_first_run_sentinel) || | |
462 !base::PathExists(legacy_first_run_sentinel)) { | |
463 return false; | |
464 } | |
465 // Migrate the legacy sentinel to the new location if it was found. This does | |
466 // a copy instead of a move to avoid breaking the developer build case where | |
467 // the First Run sentinel is dropped beside chrome.exe by a build action | |
468 // (i.e., at the legacy path). | |
469 bool migrated = base::CopyFile(legacy_first_run_sentinel, first_run_sentinel); | |
470 DPCHECK(migrated); | |
471 // Sentinel is present regardless of whether or not it was migrated. | |
472 return true; | |
473 } | |
474 | |
475 } // namespace | 452 } // namespace |
476 | 453 |
477 namespace first_run { | 454 namespace first_run { |
478 namespace internal { | 455 namespace internal { |
479 | 456 |
480 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; | 457 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; |
481 | 458 |
482 void SetupMasterPrefsFromInstallPrefs( | 459 void SetupMasterPrefsFromInstallPrefs( |
483 const installer::MasterPreferences& install_prefs, | 460 const installer::MasterPreferences& install_prefs, |
484 MasterPrefs* out_prefs) { | 461 MasterPrefs* out_prefs) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 536 |
560 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); | 537 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); |
561 out_prefs->variations_seed_signature = | 538 out_prefs->variations_seed_signature = |
562 install_prefs.GetVariationsSeedSignature(); | 539 install_prefs.GetVariationsSeedSignature(); |
563 | 540 |
564 install_prefs.GetString( | 541 install_prefs.GetString( |
565 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, | 542 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, |
566 &out_prefs->suppress_default_browser_prompt_for_version); | 543 &out_prefs->suppress_default_browser_prompt_for_version); |
567 } | 544 } |
568 | 545 |
| 546 bool GetFirstRunSentinelFilePath(base::FilePath* path) { |
| 547 base::FilePath user_data_dir; |
| 548 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 549 return false; |
| 550 *path = user_data_dir.Append(chrome::kFirstRunSentinel); |
| 551 return true; |
| 552 } |
| 553 |
569 bool CreateSentinel() { | 554 bool CreateSentinel() { |
570 base::FilePath first_run_sentinel; | 555 base::FilePath first_run_sentinel; |
571 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) | 556 return GetFirstRunSentinelFilePath(&first_run_sentinel) && |
572 return false; | 557 base::WriteFile(first_run_sentinel, "", 0) != -1; |
573 return base::WriteFile(first_run_sentinel, "", 0) != -1; | |
574 } | 558 } |
575 | 559 |
576 // -- Platform-specific functions -- | 560 // -- Platform-specific functions -- |
577 | 561 |
578 #if !defined(OS_LINUX) && !defined(OS_BSD) | 562 #if !defined(OS_LINUX) && !defined(OS_BSD) |
579 bool IsOrganicFirstRun() { | 563 bool IsOrganicFirstRun() { |
580 std::string brand; | 564 std::string brand; |
581 google_util::GetBrand(&brand); | 565 google_util::GetBrand(&brand); |
582 return google_util::IsOrganicFirstRun(brand); | 566 return google_util::IsOrganicFirstRun(brand); |
583 } | 567 } |
584 #endif | 568 #endif |
585 | 569 |
586 } // namespace internal | 570 } // namespace internal |
587 | 571 |
588 MasterPrefs::MasterPrefs() | 572 MasterPrefs::MasterPrefs() |
589 : ping_delay(0), | 573 : ping_delay(0), |
590 homepage_defined(false), | 574 homepage_defined(false), |
591 do_import_items(0), | 575 do_import_items(0), |
592 dont_import_items(0), | 576 dont_import_items(0), |
593 make_chrome_default_for_user(false), | 577 make_chrome_default_for_user(false), |
594 suppress_first_run_default_browser_prompt(false) { | 578 suppress_first_run_default_browser_prompt(false) { |
595 } | 579 } |
596 | 580 |
597 MasterPrefs::~MasterPrefs() {} | 581 MasterPrefs::~MasterPrefs() {} |
598 | 582 |
599 bool IsChromeFirstRun() { | 583 bool IsChromeFirstRun() { |
600 if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN) | 584 if (internal::first_run_ == internal::FIRST_RUN_UNKNOWN) { |
601 return internal::first_run_ == internal::FIRST_RUN_TRUE; | 585 internal::first_run_ = internal::FIRST_RUN_FALSE; |
602 | 586 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
603 internal::first_run_ = internal::FIRST_RUN_FALSE; | 587 if (command_line->HasSwitch(switches::kForceFirstRun) || |
604 | 588 (!command_line->HasSwitch(switches::kNoFirstRun) && |
605 base::FilePath first_run_sentinel; | 589 !internal::IsFirstRunSentinelPresent())) { |
606 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 590 internal::first_run_ = internal::FIRST_RUN_TRUE; |
607 if (command_line->HasSwitch(switches::kForceFirstRun)) { | 591 } |
608 internal::first_run_ = internal::FIRST_RUN_TRUE; | |
609 } else if (!command_line->HasSwitch(switches::kNoFirstRun) && | |
610 !IsFirstRunSentinelPresent()) { | |
611 internal::first_run_ = internal::FIRST_RUN_TRUE; | |
612 } | 592 } |
613 | |
614 return internal::first_run_ == internal::FIRST_RUN_TRUE; | 593 return internal::first_run_ == internal::FIRST_RUN_TRUE; |
615 } | 594 } |
616 | 595 |
617 bool IsFirstRunSuppressed(const CommandLine& command_line) { | 596 bool IsFirstRunSuppressed(const CommandLine& command_line) { |
618 return command_line.HasSwitch(switches::kNoFirstRun); | 597 return command_line.HasSwitch(switches::kNoFirstRun); |
619 } | 598 } |
620 | 599 |
621 void CreateSentinelIfNeeded() { | 600 void CreateSentinelIfNeeded() { |
622 if (IsChromeFirstRun()) | 601 if (IsChromeFirstRun()) |
623 internal::CreateSentinel(); | 602 internal::CreateSentinel(); |
624 } | 603 } |
625 | 604 |
626 std::string GetPingDelayPrefName() { | 605 std::string GetPingDelayPrefName() { |
627 return base::StringPrintf("%s.%s", | 606 return base::StringPrintf("%s.%s", |
628 installer::master_preferences::kDistroDict, | 607 installer::master_preferences::kDistroDict, |
629 installer::master_preferences::kDistroPingDelay); | 608 installer::master_preferences::kDistroPingDelay); |
630 } | 609 } |
631 | 610 |
632 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 611 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
633 registry->RegisterIntegerPref( | 612 registry->RegisterIntegerPref( |
634 GetPingDelayPrefName().c_str(), | 613 GetPingDelayPrefName().c_str(), |
635 0, | 614 0, |
636 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 615 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
637 } | 616 } |
638 | 617 |
639 bool RemoveSentinel() { | 618 bool RemoveSentinel() { |
640 base::FilePath first_run_sentinel; | 619 base::FilePath first_run_sentinel; |
641 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) | 620 return internal::GetFirstRunSentinelFilePath(&first_run_sentinel) && |
642 return false; | 621 base::DeleteFile(first_run_sentinel, false); |
643 return base::DeleteFile(first_run_sentinel, false); | |
644 } | 622 } |
645 | 623 |
646 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { | 624 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { |
647 PrefService* local_state = g_browser_process->local_state(); | 625 PrefService* local_state = g_browser_process->local_state(); |
648 if (!local_state) | 626 if (!local_state) |
649 return false; | 627 return false; |
650 if (local_state->GetInteger( | 628 if (local_state->GetInteger( |
651 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { | 629 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { |
652 // Set the new state as long as the bubble wasn't explicitly suppressed | 630 // Set the new state as long as the bubble wasn't explicitly suppressed |
653 // already. | 631 // already. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 SetShouldDoPersonalDataManagerFirstRun(); | 794 SetShouldDoPersonalDataManagerFirstRun(); |
817 | 795 |
818 internal::DoPostImportPlatformSpecificTasks(profile); | 796 internal::DoPostImportPlatformSpecificTasks(profile); |
819 } | 797 } |
820 | 798 |
821 uint16 auto_import_state() { | 799 uint16 auto_import_state() { |
822 return g_auto_import_state; | 800 return g_auto_import_state; |
823 } | 801 } |
824 | 802 |
825 } // namespace first_run | 803 } // namespace first_run |
OLD | NEW |