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

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

Issue 20483002: Merge 3 different ways of obtaining first run state into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge up to r214457 -- fix conflict with r214339 -- dcommit since tests pass on previous patch set Created 7 years, 4 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
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 make_chrome_default(false), 462 make_chrome_default(false),
463 suppress_first_run_default_browser_prompt(false) { 463 suppress_first_run_default_browser_prompt(false) {
464 } 464 }
465 465
466 MasterPrefs::~MasterPrefs() {} 466 MasterPrefs::~MasterPrefs() {}
467 467
468 bool IsChromeFirstRun() { 468 bool IsChromeFirstRun() {
469 if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN) 469 if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN)
470 return internal::first_run_ == internal::FIRST_RUN_TRUE; 470 return internal::first_run_ == internal::FIRST_RUN_TRUE;
471 471
472 enum FirstRunState {
473 CANCEL_FIRST_RUN,
474 NOT_FIRST_RUN,
475 IS_FIRST_RUN,
476 };
477
478 FirstRunState first_run_state = NOT_FIRST_RUN;
479
472 base::FilePath first_run_sentinel; 480 base::FilePath first_run_sentinel;
473 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel) || 481 const CommandLine* command_line = CommandLine::ForCurrentProcess();
474 base::PathExists(first_run_sentinel)) { 482 if (command_line->HasSwitch(switches::kForceFirstRun)) {
483 first_run_state = IS_FIRST_RUN;
484 } else if (command_line->HasSwitch(switches::kNoFirstRun)) {
485 first_run_state = CANCEL_FIRST_RUN;
486 } else if (internal::GetFirstRunSentinelFilePath(&first_run_sentinel) &&
487 !base::PathExists(first_run_sentinel)) {
488 first_run_state = IS_FIRST_RUN;
489 }
490
491 if (first_run_state == IS_FIRST_RUN || first_run_state == CANCEL_FIRST_RUN)
492 CreateSentinel();
493
494 if (first_run_state == IS_FIRST_RUN) {
495 internal::first_run_ = internal::FIRST_RUN_TRUE;
496 return true;
497 } else {
475 internal::first_run_ = internal::FIRST_RUN_FALSE; 498 internal::first_run_ = internal::FIRST_RUN_FALSE;
476 return false; 499 return false;
477 } 500 }
478 internal::first_run_ = internal::FIRST_RUN_TRUE;
479 return true;
480 } 501 }
481 502
482 bool CreateSentinel() { 503 bool CreateSentinel() {
483 base::FilePath first_run_sentinel; 504 base::FilePath first_run_sentinel;
484 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) 505 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
485 return false; 506 return false;
486 return file_util::WriteFile(first_run_sentinel, "", 0) != -1; 507 return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
487 } 508 }
488 509
489 std::string GetPingDelayPrefName() { 510 std::string GetPingDelayPrefName() {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 650
630 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) { 651 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) {
631 internal::master_prefs_path_for_testing.Get() = master_prefs; 652 internal::master_prefs_path_for_testing.Get() = master_prefs;
632 } 653 }
633 654
634 ProcessMasterPreferencesResult ProcessMasterPreferences( 655 ProcessMasterPreferencesResult ProcessMasterPreferences(
635 const base::FilePath& user_data_dir, 656 const base::FilePath& user_data_dir,
636 MasterPrefs* out_prefs) { 657 MasterPrefs* out_prefs) {
637 DCHECK(!user_data_dir.empty()); 658 DCHECK(!user_data_dir.empty());
638 659
639 #if defined(OS_CHROMEOS)
640 // Chrome OS has its own out-of-box-experience code. Create the sentinel to
641 // mark the fact that we've run once but skip the full first-run flow.
642 CreateSentinel();
643 return SKIP_FIRST_RUN_TASKS;
644 #endif
645
646 base::FilePath master_prefs_path; 660 base::FilePath master_prefs_path;
647 scoped_ptr<installer::MasterPreferences> 661 scoped_ptr<installer::MasterPreferences>
648 install_prefs(internal::LoadMasterPrefs(&master_prefs_path)); 662 install_prefs(internal::LoadMasterPrefs(&master_prefs_path));
649 663
650 // Default value in case master preferences is missing or corrupt, or 664 // Default value in case master preferences is missing or corrupt, or
651 // ping_delay is missing. 665 // ping_delay is missing.
652 out_prefs->ping_delay = 90; 666 out_prefs->ping_delay = 90;
653 if (install_prefs.get()) { 667 if (install_prefs.get()) {
654 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) 668 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get()))
655 return EULA_EXIT_NOW; 669 return EULA_EXIT_NOW;
656 670
657 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) 671 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path))
658 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; 672 DLOG(ERROR) << "Failed to copy master_preferences to user data dir.";
659 673
660 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); 674 DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
661 675
662 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); 676 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs);
663 677
664 internal::SetDefaultBrowser(install_prefs.get()); 678 internal::SetDefaultBrowser(install_prefs.get());
665 } 679 }
666 680
667 return DO_FIRST_RUN_TASKS; 681 return FIRST_RUN_PROCEED;
668 } 682 }
669 683
670 void AutoImport( 684 void AutoImport(
671 Profile* profile, 685 Profile* profile,
672 bool homepage_defined, 686 bool homepage_defined,
673 int import_items, 687 int import_items,
674 int dont_import_items, 688 int dont_import_items,
675 const std::string& import_bookmarks_path) { 689 const std::string& import_bookmarks_path) {
676 // Deletes itself. 690 // Deletes itself.
677 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost; 691 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 SetShouldDoPersonalDataManagerFirstRun(); 784 SetShouldDoPersonalDataManagerFirstRun();
771 785
772 internal::DoPostImportPlatformSpecificTasks(profile); 786 internal::DoPostImportPlatformSpecificTasks(profile);
773 } 787 }
774 788
775 uint16 auto_import_state() { 789 uint16 auto_import_state() {
776 return g_auto_import_state; 790 return g_auto_import_state;
777 } 791 }
778 792
779 } // namespace first_run 793 } // namespace first_run
OLDNEW
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698