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

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

Issue 20743002: Do not CreateSentinel until after the process singleton has been grabbed by the current process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge latest version of https://codereview.chromium.org/20483002/ 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') | chrome/browser/first_run/first_run_internal.h » ('j') | 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 ShellIntegration::SetAsDefaultBrowser(); 435 ShellIntegration::SetAsDefaultBrowser();
436 } 436 }
437 } else { 437 } else {
438 if (g_browser_process->local_state()->GetBoolean( 438 if (g_browser_process->local_state()->GetBoolean(
439 prefs::kDefaultBrowserSettingEnabled)) { 439 prefs::kDefaultBrowserSettingEnabled)) {
440 ShellIntegration::SetAsDefaultBrowser(); 440 ShellIntegration::SetAsDefaultBrowser();
441 } 441 }
442 } 442 }
443 } 443 }
444 444
445 bool CreateSentinel() {
446 base::FilePath first_run_sentinel;
447 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
448 return false;
449 return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
450 }
451
445 // -- Platform-specific functions -- 452 // -- Platform-specific functions --
446 453
447 #if !defined(OS_LINUX) && !defined(OS_BSD) 454 #if !defined(OS_LINUX) && !defined(OS_BSD)
448 bool IsOrganicFirstRun() { 455 bool IsOrganicFirstRun() {
449 std::string brand; 456 std::string brand;
450 google_util::GetBrand(&brand); 457 google_util::GetBrand(&brand);
451 return google_util::IsOrganicFirstRun(brand); 458 return google_util::IsOrganicFirstRun(brand);
452 } 459 }
453 #endif 460 #endif
454 461
455 } // namespace internal 462 } // namespace internal
456 463
457 MasterPrefs::MasterPrefs() 464 MasterPrefs::MasterPrefs()
458 : ping_delay(0), 465 : ping_delay(0),
459 homepage_defined(false), 466 homepage_defined(false),
460 do_import_items(0), 467 do_import_items(0),
461 dont_import_items(0), 468 dont_import_items(0),
462 make_chrome_default(false), 469 make_chrome_default(false),
463 suppress_first_run_default_browser_prompt(false) { 470 suppress_first_run_default_browser_prompt(false) {
464 } 471 }
465 472
466 MasterPrefs::~MasterPrefs() {} 473 MasterPrefs::~MasterPrefs() {}
467 474
468 bool IsChromeFirstRun() { 475 bool IsChromeFirstRun() {
469 if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN) 476 if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN)
470 return internal::first_run_ == internal::FIRST_RUN_TRUE; 477 return internal::first_run_ == internal::FIRST_RUN_TRUE;
471 478
472 enum FirstRunState { 479 internal::first_run_ = internal::FIRST_RUN_FALSE;
473 CANCEL_FIRST_RUN,
474 NOT_FIRST_RUN,
475 IS_FIRST_RUN,
476 };
477
478 FirstRunState first_run_state = NOT_FIRST_RUN;
479 480
480 base::FilePath first_run_sentinel; 481 base::FilePath first_run_sentinel;
481 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 482 const CommandLine* command_line = CommandLine::ForCurrentProcess();
482 if (command_line->HasSwitch(switches::kForceFirstRun)) { 483 if (command_line->HasSwitch(switches::kForceFirstRun)) {
483 first_run_state = IS_FIRST_RUN; 484 internal::first_run_ = internal::FIRST_RUN_TRUE;
484 } else if (command_line->HasSwitch(switches::kNoFirstRun)) { 485 } else if (command_line->HasSwitch(switches::kNoFirstRun)) {
485 first_run_state = CANCEL_FIRST_RUN; 486 internal::first_run_ = internal::FIRST_RUN_CANCEL;
486 } else if (internal::GetFirstRunSentinelFilePath(&first_run_sentinel) && 487 } else if (internal::GetFirstRunSentinelFilePath(&first_run_sentinel) &&
487 !base::PathExists(first_run_sentinel)) { 488 !base::PathExists(first_run_sentinel)) {
488 first_run_state = IS_FIRST_RUN; 489 internal::first_run_ = internal::FIRST_RUN_TRUE;
489 } 490 }
490 491
491 if (first_run_state == IS_FIRST_RUN || first_run_state == CANCEL_FIRST_RUN) 492 return internal::first_run_ == internal::FIRST_RUN_TRUE;
492 CreateSentinel(); 493 }
493 494
494 if (first_run_state == IS_FIRST_RUN) { 495 void CreateSentinelIfNeeded() {
495 internal::first_run_ = internal::FIRST_RUN_TRUE; 496 if (IsChromeFirstRun() ||
496 return true; 497 internal::first_run_ == internal::FIRST_RUN_CANCEL) {
497 } else { 498 internal::CreateSentinel();
498 internal::first_run_ = internal::FIRST_RUN_FALSE;
499 return false;
500 } 499 }
501 } 500 }
502 501
503 bool CreateSentinel() {
504 base::FilePath first_run_sentinel;
505 if (!internal::GetFirstRunSentinelFilePath(&first_run_sentinel))
506 return false;
507 return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
508 }
509
510 std::string GetPingDelayPrefName() { 502 std::string GetPingDelayPrefName() {
511 return base::StringPrintf("%s.%s", 503 return base::StringPrintf("%s.%s",
512 installer::master_preferences::kDistroDict, 504 installer::master_preferences::kDistroDict,
513 installer::master_preferences::kDistroPingDelay); 505 installer::master_preferences::kDistroPingDelay);
514 } 506 }
515 507
516 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 508 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
517 registry->RegisterIntegerPref( 509 registry->RegisterIntegerPref(
518 GetPingDelayPrefName().c_str(), 510 GetPingDelayPrefName().c_str(),
519 0, 511 0,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 SetShouldDoPersonalDataManagerFirstRun(); 776 SetShouldDoPersonalDataManagerFirstRun();
785 777
786 internal::DoPostImportPlatformSpecificTasks(profile); 778 internal::DoPostImportPlatformSpecificTasks(profile);
787 } 779 }
788 780
789 uint16 auto_import_state() { 781 uint16 auto_import_state() {
790 return g_auto_import_state; 782 return g_auto_import_state;
791 } 783 }
792 784
793 } // namespace first_run 785 } // namespace first_run
OLDNEW
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | chrome/browser/first_run/first_run_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698