Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/first_run/first_run.cc

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

Powered by Google App Engine
This is Rietveld 408576698