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

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

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment clarification. Created 7 years, 8 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/chrome_browser_main.h" 5 #include "chrome/browser/chrome_browser_main.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // CRLSetFetcher attempts to load a CRL set from either the local disk or 459 // CRLSetFetcher attempts to load a CRL set from either the local disk or
460 // network. 460 // network.
461 if (!command_line.HasSwitch(switches::kDisableCRLSets)) 461 if (!command_line.HasSwitch(switches::kDisableCRLSets))
462 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus); 462 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus);
463 463
464 RegisterPnaclComponent(cus, command_line); 464 RegisterPnaclComponent(cus, command_line);
465 465
466 cus->Start(); 466 cus->Start();
467 } 467 }
468 468
469 #if !defined(OS_ANDROID)
469 bool ProcessSingletonNotificationCallback( 470 bool ProcessSingletonNotificationCallback(
470 const CommandLine& command_line, 471 const CommandLine& command_line,
471 const base::FilePath& current_directory) { 472 const base::FilePath& current_directory) {
472 // Drop the request if the browser process is already in shutdown path. 473 // Drop the request if the browser process is already in shutdown path.
473 if (!g_browser_process || g_browser_process->IsShuttingDown()) 474 if (!g_browser_process || g_browser_process->IsShuttingDown())
474 return false; 475 return false;
475 476
476 g_browser_process->PlatformSpecificCommandLineProcessing(command_line); 477 g_browser_process->PlatformSpecificCommandLineProcessing(command_line);
477 478
478 // TODO(erikwright): Consider removing this - AFAIK it is no longer used. 479 // TODO(erikwright): Consider removing this - AFAIK it is no longer used.
(...skipping 19 matching lines...) Expand all
498 499
499 base::FilePath user_data_dir = 500 base::FilePath user_data_dir =
500 g_browser_process->profile_manager()->user_data_dir(); 501 g_browser_process->profile_manager()->user_data_dir();
501 base::FilePath startup_profile_dir = 502 base::FilePath startup_profile_dir =
502 GetStartupProfilePath(user_data_dir, command_line); 503 GetStartupProfilePath(user_data_dir, command_line);
503 504
504 StartupBrowserCreator::ProcessCommandLineAlreadyRunning( 505 StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
505 command_line, current_directory, startup_profile_dir); 506 command_line, current_directory, startup_profile_dir);
506 return true; 507 return true;
507 } 508 }
509 #endif
508 510
509 void LaunchDevToolsHandlerIfNeeded(Profile* profile, 511 void LaunchDevToolsHandlerIfNeeded(Profile* profile,
510 const CommandLine& command_line) { 512 const CommandLine& command_line) {
511 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { 513 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
512 std::string port_str = 514 std::string port_str =
513 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); 515 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort);
514 int port; 516 int port;
515 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { 517 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
516 std::string frontend_str; 518 std::string frontend_str;
517 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) { 519 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 575
574 ChromeBrowserMainParts::ChromeBrowserMainParts( 576 ChromeBrowserMainParts::ChromeBrowserMainParts(
575 const content::MainFunctionParams& parameters) 577 const content::MainFunctionParams& parameters)
576 : parameters_(parameters), 578 : parameters_(parameters),
577 parsed_command_line_(parameters.command_line), 579 parsed_command_line_(parameters.command_line),
578 result_code_(content::RESULT_CODE_NORMAL_EXIT), 580 result_code_(content::RESULT_CODE_NORMAL_EXIT),
579 startup_watcher_(new StartupTimeBomb()), 581 startup_watcher_(new StartupTimeBomb()),
580 shutdown_watcher_(new ShutdownWatcherHelper()), 582 shutdown_watcher_(new ShutdownWatcherHelper()),
581 startup_timer_(new performance_monitor::StartupTimer()), 583 startup_timer_(new performance_monitor::StartupTimer()),
582 browser_field_trials_(parameters.command_line), 584 browser_field_trials_(parameters.command_line),
585 #if !defined(OS_ANDROID)
586 startup_lock_(base::Bind(&ProcessSingletonNotificationCallback)),
587 modal_dialog_lock_(startup_lock_.AsNotificationCallback()),
588 #endif
583 record_search_engine_(false), 589 record_search_engine_(false),
584 translate_manager_(NULL), 590 translate_manager_(NULL),
585 profile_(NULL), 591 profile_(NULL),
586 run_message_loop_(true), 592 run_message_loop_(true),
587 notify_result_(ProcessSingleton::PROCESS_NONE), 593 notify_result_(ProcessSingleton::PROCESS_NONE),
588 do_first_run_tasks_(false), 594 do_first_run_tasks_(false),
589 local_state_(NULL), 595 local_state_(NULL),
590 restart_last_session_(false) { 596 restart_last_session_(false) {
591 // If we're running tests (ui_task is non-null). 597 // If we're running tests (ui_task is non-null).
592 if (parameters.ui_task) { 598 if (parameters.ui_task) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 run_message_loop_ = false; 792 run_message_loop_ = false;
787 user_data_dir_ = chrome::GetUserDataDir(parameters()); 793 user_data_dir_ = chrome::GetUserDataDir(parameters());
788 794
789 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this 795 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this
790 // unless the desire is actually to know whether this is really First Run 796 // unless the desire is actually to know whether this is really First Run
791 // (i.e., even if --no-first-run is passed). 797 // (i.e., even if --no-first-run is passed).
792 bool is_first_run = false; 798 bool is_first_run = false;
793 // Android's first run is done in Java instead of native. 799 // Android's first run is done in Java instead of native.
794 #if !defined(OS_ANDROID) 800 #if !defined(OS_ANDROID)
795 801
802 // Pass command-line invocations through modal_dialog_lock_ and
803 // startup_lock_ before handling them ourselves.
796 process_singleton_.reset(new ProcessSingleton( 804 process_singleton_.reset(new ProcessSingleton(
797 user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback))); 805 user_data_dir_, modal_dialog_lock_.AsNotificationCallback()));
798 // Ensure ProcessSingleton won't process messages too early. It will be
799 // unlocked in PostBrowserStart().
800 process_singleton_->Lock(NULL);
801 806
802 bool force_first_run = 807 bool force_first_run =
803 parsed_command_line().HasSwitch(switches::kForceFirstRun); 808 parsed_command_line().HasSwitch(switches::kForceFirstRun);
804 bool force_skip_first_run_tasks = 809 bool force_skip_first_run_tasks =
805 (!force_first_run && 810 (!force_first_run &&
806 parsed_command_line().HasSwitch(switches::kNoFirstRun)); 811 parsed_command_line().HasSwitch(switches::kNoFirstRun));
807 812
808 is_first_run = 813 is_first_run =
809 (force_first_run || first_run::IsChromeFirstRun()) && 814 (force_first_run || first_run::IsChromeFirstRun()) &&
810 !ProfileManager::IsImportProcess(parsed_command_line()); 815 !ProfileManager::IsImportProcess(parsed_command_line());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 void ChromeBrowserMainParts::PostBrowserStart() { 1045 void ChromeBrowserMainParts::PostBrowserStart() {
1041 #if !defined(OS_ANDROID) 1046 #if !defined(OS_ANDROID)
1042 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) 1047 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs))
1043 RunPageCycler(); 1048 RunPageCycler();
1044 #endif 1049 #endif
1045 1050
1046 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1051 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1047 chrome_extra_parts_[i]->PostBrowserStart(); 1052 chrome_extra_parts_[i]->PostBrowserStart();
1048 #if !defined(OS_ANDROID) 1053 #if !defined(OS_ANDROID)
1049 // Allow ProcessSingleton to process messages. 1054 // Allow ProcessSingleton to process messages.
1050 process_singleton_->Unlock(); 1055 startup_lock_.Unlock();
1051 #endif 1056 #endif
1052 } 1057 }
1053 1058
1054 #if !defined(OS_ANDROID) 1059 #if !defined(OS_ANDROID)
1055 void ChromeBrowserMainParts::RunPageCycler() { 1060 void ChromeBrowserMainParts::RunPageCycler() {
1056 CommandLine* command_line = CommandLine::ForCurrentProcess(); 1061 CommandLine* command_line = CommandLine::ForCurrentProcess();
1057 // We assume a native desktop for tests, but we will need to find a way to 1062 // We assume a native desktop for tests, but we will need to find a way to
1058 // get the proper host desktop type once we start running these tests in ASH. 1063 // get the proper host desktop type once we start running these tests in ASH.
1059 Browser* browser = chrome::FindBrowserWithProfile( 1064 Browser* browser = chrome::FindBrowserWithProfile(
1060 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); 1065 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 std::string try_chrome = 1220 std::string try_chrome =
1216 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); 1221 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
1217 if (!try_chrome.empty()) { 1222 if (!try_chrome.empty()) {
1218 #if defined(OS_WIN) 1223 #if defined(OS_WIN)
1219 // Setup.exe has determined that we need to run a retention experiment 1224 // Setup.exe has determined that we need to run a retention experiment
1220 // and has lauched chrome to show the experiment UI. It is guaranteed that 1225 // and has lauched chrome to show the experiment UI. It is guaranteed that
1221 // no other Chrome is currently running as the process singleton was 1226 // no other Chrome is currently running as the process singleton was
1222 // sucessfully grabbed above. 1227 // sucessfully grabbed above.
1223 int try_chrome_int; 1228 int try_chrome_int;
1224 base::StringToInt(try_chrome, &try_chrome_int); 1229 base::StringToInt(try_chrome, &try_chrome_int);
1225 TryChromeDialogView::Result answer = 1230 TryChromeDialogView::Result answer = TryChromeDialogView::Show(
1226 TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); 1231 try_chrome_int,
1232 base::Bind(
1233 &ProcessSingletonModalDialogLock::SetActiveModalDialog,
1234 base::Unretained(&modal_dialog_lock_)));
1227 if (answer == TryChromeDialogView::NOT_NOW) 1235 if (answer == TryChromeDialogView::NOT_NOW)
1228 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; 1236 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL;
1229 if (answer == TryChromeDialogView::UNINSTALL_CHROME) 1237 if (answer == TryChromeDialogView::UNINSTALL_CHROME)
1230 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; 1238 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2;
1231 // At this point the user is willing to try chrome again. 1239 // At this point the user is willing to try chrome again.
1232 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) { 1240 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) {
1233 // Only set in the unattended case, the interactive case is Windows 8. 1241 // Only set in the unattended case, the interactive case is Windows 8.
1234 if (ShellIntegration::CanSetAsDefaultBrowser() == 1242 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1235 ShellIntegration::SET_DEFAULT_UNATTENDED) 1243 ShellIntegration::SET_DEFAULT_UNATTENDED)
1236 ShellIntegration::SetAsDefaultBrowser(); 1244 ShellIntegration::SetAsDefaultBrowser();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 #if !defined(OS_ANDROID) 1326 #if !defined(OS_ANDROID)
1319 // Show the First Run UI if this is the first time Chrome has been run on 1327 // Show the First Run UI if this is the first time Chrome has been run on
1320 // this computer, or we're being compelled to do so by a command line flag. 1328 // this computer, or we're being compelled to do so by a command line flag.
1321 // Note that this be done _after_ the PrefService is initialized and all 1329 // Note that this be done _after_ the PrefService is initialized and all
1322 // preferences are registered, since some of the code that the importer 1330 // preferences are registered, since some of the code that the importer
1323 // touches reads preferences. 1331 // touches reads preferences.
1324 if (do_first_run_tasks_) { 1332 if (do_first_run_tasks_) {
1325 first_run::AutoImport(profile_, 1333 first_run::AutoImport(profile_,
1326 master_prefs_->homepage_defined, 1334 master_prefs_->homepage_defined,
1327 master_prefs_->do_import_items, 1335 master_prefs_->do_import_items,
1328 master_prefs_->dont_import_items, 1336 master_prefs_->dont_import_items);
1329 process_singleton_.get());
1330 // Note: this can pop the first run consent dialog on linux. 1337 // Note: this can pop the first run consent dialog on linux.
1331 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default); 1338 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default);
1332 1339
1333 browser_process_->profile_manager()->OnImportFinished(profile_); 1340 browser_process_->profile_manager()->OnImportFinished(profile_);
1334 1341
1335 if (!master_prefs_->suppress_first_run_default_browser_prompt) { 1342 if (!master_prefs_->suppress_first_run_default_browser_prompt) {
1336 browser_creator_->set_show_main_browser_window( 1343 browser_creator_->set_show_main_browser_window(
1337 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); 1344 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
1338 } else { 1345 } else {
1339 browser_creator_->set_is_default_browser_dialog_suppressed(true); 1346 browser_creator_->set_is_default_browser_dialog_suppressed(true);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 if (base::win::GetVersion() <= base::win::VERSION_XP) 1799 if (base::win::GetVersion() <= base::win::VERSION_XP)
1793 uma_name += "_XP"; 1800 uma_name += "_XP";
1794 1801
1795 uma_name += "_PreRead_"; 1802 uma_name += "_PreRead_";
1796 uma_name += pre_read_percentage; 1803 uma_name += pre_read_percentage;
1797 AddPreReadHistogramTime(uma_name.c_str(), time); 1804 AddPreReadHistogramTime(uma_name.c_str(), time);
1798 } 1805 }
1799 #endif 1806 #endif
1800 #endif 1807 #endif
1801 } 1808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698