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/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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 // CRLSetFetcher attempts to load a CRL set from either the local disk or | 487 // CRLSetFetcher attempts to load a CRL set from either the local disk or |
488 // network. | 488 // network. |
489 if (!command_line.HasSwitch(switches::kDisableCRLSets)) | 489 if (!command_line.HasSwitch(switches::kDisableCRLSets)) |
490 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus); | 490 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus); |
491 | 491 |
492 RegisterPnaclComponent(cus, command_line); | 492 RegisterPnaclComponent(cus, command_line); |
493 | 493 |
494 cus->Start(); | 494 cus->Start(); |
495 } | 495 } |
496 | 496 |
497 #if !defined(OS_ANDROID) | |
497 bool ProcessSingletonNotificationCallback( | 498 bool ProcessSingletonNotificationCallback( |
498 const CommandLine& command_line, | 499 const CommandLine& command_line, |
499 const base::FilePath& current_directory) { | 500 const base::FilePath& current_directory) { |
500 // Drop the request if the browser process is already in shutdown path. | 501 // Drop the request if the browser process is already in shutdown path. |
501 if (!g_browser_process || g_browser_process->IsShuttingDown()) | 502 if (!g_browser_process || g_browser_process->IsShuttingDown()) |
502 return false; | 503 return false; |
503 | 504 |
504 g_browser_process->PlatformSpecificCommandLineProcessing(command_line); | 505 g_browser_process->PlatformSpecificCommandLineProcessing(command_line); |
505 | 506 |
506 // TODO(erikwright): Consider removing this - AFAIK it is no longer used. | 507 // TODO(erikwright): Consider removing this - AFAIK it is no longer used. |
(...skipping 19 matching lines...) Expand all Loading... | |
526 | 527 |
527 base::FilePath user_data_dir = | 528 base::FilePath user_data_dir = |
528 g_browser_process->profile_manager()->user_data_dir(); | 529 g_browser_process->profile_manager()->user_data_dir(); |
529 base::FilePath startup_profile_dir = | 530 base::FilePath startup_profile_dir = |
530 GetStartupProfilePath(user_data_dir, command_line); | 531 GetStartupProfilePath(user_data_dir, command_line); |
531 | 532 |
532 StartupBrowserCreator::ProcessCommandLineAlreadyRunning( | 533 StartupBrowserCreator::ProcessCommandLineAlreadyRunning( |
533 command_line, current_directory, startup_profile_dir); | 534 command_line, current_directory, startup_profile_dir); |
534 return true; | 535 return true; |
535 } | 536 } |
537 #endif | |
536 | 538 |
537 void LaunchDevToolsHandlerIfNeeded(Profile* profile, | 539 void LaunchDevToolsHandlerIfNeeded(Profile* profile, |
538 const CommandLine& command_line) { | 540 const CommandLine& command_line) { |
539 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { | 541 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
540 std::string port_str = | 542 std::string port_str = |
541 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); | 543 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); |
542 int port; | 544 int port; |
543 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { | 545 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { |
544 std::string frontend_str; | 546 std::string frontend_str; |
545 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) { | 547 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 | 603 |
602 ChromeBrowserMainParts::ChromeBrowserMainParts( | 604 ChromeBrowserMainParts::ChromeBrowserMainParts( |
603 const content::MainFunctionParams& parameters) | 605 const content::MainFunctionParams& parameters) |
604 : parameters_(parameters), | 606 : parameters_(parameters), |
605 parsed_command_line_(parameters.command_line), | 607 parsed_command_line_(parameters.command_line), |
606 result_code_(content::RESULT_CODE_NORMAL_EXIT), | 608 result_code_(content::RESULT_CODE_NORMAL_EXIT), |
607 startup_watcher_(new StartupTimeBomb()), | 609 startup_watcher_(new StartupTimeBomb()), |
608 shutdown_watcher_(new ShutdownWatcherHelper()), | 610 shutdown_watcher_(new ShutdownWatcherHelper()), |
609 startup_timer_(new performance_monitor::StartupTimer()), | 611 startup_timer_(new performance_monitor::StartupTimer()), |
610 browser_field_trials_(parameters.command_line), | 612 browser_field_trials_(parameters.command_line), |
613 #if !defined(OS_ANDROID) | |
614 startup_lock_(base::Bind(&ProcessSingletonNotificationCallback)), | |
615 modal_dialog_lock_(startup_lock_.AsNotificationCallback()), | |
616 #endif | |
611 record_search_engine_(false), | 617 record_search_engine_(false), |
612 translate_manager_(NULL), | 618 translate_manager_(NULL), |
613 profile_(NULL), | 619 profile_(NULL), |
614 run_message_loop_(true), | 620 run_message_loop_(true), |
615 notify_result_(ProcessSingleton::PROCESS_NONE), | 621 notify_result_(ProcessSingleton::PROCESS_NONE), |
616 do_first_run_tasks_(false), | 622 do_first_run_tasks_(false), |
617 local_state_(NULL), | 623 local_state_(NULL), |
618 restart_last_session_(false) { | 624 restart_last_session_(false) { |
619 // If we're running tests (ui_task is non-null). | 625 // If we're running tests (ui_task is non-null). |
620 if (parameters.ui_task) { | 626 if (parameters.ui_task) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 << "Must be able to get user data directory!"; | 826 << "Must be able to get user data directory!"; |
821 #endif | 827 #endif |
822 | 828 |
823 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this | 829 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this |
824 // unless the desire is actually to know whether this is really First Run | 830 // unless the desire is actually to know whether this is really First Run |
825 // (i.e., even if --no-first-run is passed). | 831 // (i.e., even if --no-first-run is passed). |
826 bool is_first_run = false; | 832 bool is_first_run = false; |
827 // Android's first run is done in Java instead of native. | 833 // Android's first run is done in Java instead of native. |
828 #if !defined(OS_ANDROID) | 834 #if !defined(OS_ANDROID) |
829 | 835 |
836 // Pass command-line invocations through modal_dialog_lock_ and | |
837 // startup_lock_ before handling them ourselves. | |
830 process_singleton_.reset(new ProcessSingleton( | 838 process_singleton_.reset(new ProcessSingleton( |
831 user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback))); | 839 user_data_dir_, modal_dialog_lock_.AsNotificationCallback())); |
832 // Ensure ProcessSingleton won't process messages too early. It will be | |
833 // unlocked in PostBrowserStart(). | |
834 process_singleton_->Lock(NULL); | |
835 | 840 |
836 bool force_first_run = | 841 bool force_first_run = |
837 parsed_command_line().HasSwitch(switches::kForceFirstRun); | 842 parsed_command_line().HasSwitch(switches::kForceFirstRun); |
838 bool force_skip_first_run_tasks = | 843 bool force_skip_first_run_tasks = |
839 (!force_first_run && | 844 (!force_first_run && |
840 parsed_command_line().HasSwitch(switches::kNoFirstRun)); | 845 parsed_command_line().HasSwitch(switches::kNoFirstRun)); |
841 | 846 |
842 is_first_run = | 847 is_first_run = |
843 (force_first_run || first_run::IsChromeFirstRun()) && | 848 (force_first_run || first_run::IsChromeFirstRun()) && |
844 !ProfileManager::IsImportProcess(parsed_command_line()); | 849 !ProfileManager::IsImportProcess(parsed_command_line()); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1062 void ChromeBrowserMainParts::PostBrowserStart() { | 1067 void ChromeBrowserMainParts::PostBrowserStart() { |
1063 #if !defined(OS_ANDROID) | 1068 #if !defined(OS_ANDROID) |
1064 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) | 1069 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) |
1065 RunPageCycler(); | 1070 RunPageCycler(); |
1066 #endif | 1071 #endif |
1067 | 1072 |
1068 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1073 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
1069 chrome_extra_parts_[i]->PostBrowserStart(); | 1074 chrome_extra_parts_[i]->PostBrowserStart(); |
1070 #if !defined(OS_ANDROID) | 1075 #if !defined(OS_ANDROID) |
1071 // Allow ProcessSingleton to process messages. | 1076 // Allow ProcessSingleton to process messages. |
1072 process_singleton_->Unlock(); | 1077 startup_lock_.Unlock(); |
1073 #endif | 1078 #endif |
1074 } | 1079 } |
1075 | 1080 |
1076 #if !defined(OS_ANDROID) | 1081 #if !defined(OS_ANDROID) |
1077 void ChromeBrowserMainParts::RunPageCycler() { | 1082 void ChromeBrowserMainParts::RunPageCycler() { |
1078 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1083 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1079 // We assume a native desktop for tests, but we will need to find a way to | 1084 // We assume a native desktop for tests, but we will need to find a way to |
1080 // get the proper host desktop type once we start running these tests in ASH. | 1085 // get the proper host desktop type once we start running these tests in ASH. |
1081 Browser* browser = chrome::FindBrowserWithProfile( | 1086 Browser* browser = chrome::FindBrowserWithProfile( |
1082 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); | 1087 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 std::string try_chrome = | 1242 std::string try_chrome = |
1238 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); | 1243 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); |
1239 if (!try_chrome.empty()) { | 1244 if (!try_chrome.empty()) { |
1240 #if defined(OS_WIN) | 1245 #if defined(OS_WIN) |
1241 // Setup.exe has determined that we need to run a retention experiment | 1246 // Setup.exe has determined that we need to run a retention experiment |
1242 // and has lauched chrome to show the experiment UI. It is guaranteed that | 1247 // and has lauched chrome to show the experiment UI. It is guaranteed that |
1243 // no other Chrome is currently running as the process singleton was | 1248 // no other Chrome is currently running as the process singleton was |
1244 // sucessfully grabbed above. | 1249 // sucessfully grabbed above. |
1245 int try_chrome_int; | 1250 int try_chrome_int; |
1246 base::StringToInt(try_chrome, &try_chrome_int); | 1251 base::StringToInt(try_chrome, &try_chrome_int); |
1247 TryChromeDialogView::Result answer = | 1252 TryChromeDialogView::Result answer = TryChromeDialogView::Show( |
1248 TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); | 1253 try_chrome_int, |
1254 base::Bind( | |
1255 &ProcessSingletonModalDialogLock::SetActiveModalDialog, | |
1256 base::Unretained(&modal_dialog_lock_))); | |
1249 if (answer == TryChromeDialogView::NOT_NOW) | 1257 if (answer == TryChromeDialogView::NOT_NOW) |
1250 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; | 1258 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; |
1251 if (answer == TryChromeDialogView::UNINSTALL_CHROME) | 1259 if (answer == TryChromeDialogView::UNINSTALL_CHROME) |
1252 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; | 1260 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; |
1253 // At this point the user is willing to try chrome again. | 1261 // At this point the user is willing to try chrome again. |
1254 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) { | 1262 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) { |
1255 // Only set in the unattended case, the interactive case is Windows 8. | 1263 // Only set in the unattended case, the interactive case is Windows 8. |
1256 if (ShellIntegration::CanSetAsDefaultBrowser() == | 1264 if (ShellIntegration::CanSetAsDefaultBrowser() == |
1257 ShellIntegration::SET_DEFAULT_UNATTENDED) | 1265 ShellIntegration::SET_DEFAULT_UNATTENDED) |
1258 ShellIntegration::SetAsDefaultBrowser(); | 1266 ShellIntegration::SetAsDefaultBrowser(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 // Create an instance of GpuModeManager to watch gpu mode pref change. | 1345 // Create an instance of GpuModeManager to watch gpu mode pref change. |
1338 g_browser_process->gpu_mode_manager(); | 1346 g_browser_process->gpu_mode_manager(); |
1339 | 1347 |
1340 #if !defined(OS_ANDROID) | 1348 #if !defined(OS_ANDROID) |
1341 // Show the First Run UI if this is the first time Chrome has been run on | 1349 // Show the First Run UI if this is the first time Chrome has been run on |
1342 // this computer, or we're being compelled to do so by a command line flag. | 1350 // this computer, or we're being compelled to do so by a command line flag. |
1343 // Note that this be done _after_ the PrefService is initialized and all | 1351 // Note that this be done _after_ the PrefService is initialized and all |
1344 // preferences are registered, since some of the code that the importer | 1352 // preferences are registered, since some of the code that the importer |
1345 // touches reads preferences. | 1353 // touches reads preferences. |
1346 if (do_first_run_tasks_) { | 1354 if (do_first_run_tasks_) { |
1355 DCHECK(startup_lock_.locked()); | |
Nico
2013/03/28 04:50:09
How bad is it if this fails? Should this be a CHEC
gab
2013/03/28 13:45:53
The process singleton is already locked all the wa
erikwright (departed)
2013/04/04 01:39:51
I added this because I wanted to demonstrate that
| |
1347 first_run::AutoImport(profile_, | 1356 first_run::AutoImport(profile_, |
1348 master_prefs_->homepage_defined, | 1357 master_prefs_->homepage_defined, |
1349 master_prefs_->do_import_items, | 1358 master_prefs_->do_import_items, |
1350 master_prefs_->dont_import_items, | 1359 master_prefs_->dont_import_items); |
1351 process_singleton_.get()); | |
1352 // Note: this can pop the first run consent dialog on linux. | 1360 // Note: this can pop the first run consent dialog on linux. |
1353 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default); | 1361 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default); |
1354 | 1362 |
1355 browser_process_->profile_manager()->OnImportFinished(profile_); | 1363 browser_process_->profile_manager()->OnImportFinished(profile_); |
1356 | 1364 |
1357 if (!master_prefs_->suppress_first_run_default_browser_prompt) { | 1365 if (!master_prefs_->suppress_first_run_default_browser_prompt) { |
1358 browser_creator_->set_show_main_browser_window( | 1366 browser_creator_->set_show_main_browser_window( |
1359 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); | 1367 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); |
1360 } else { | 1368 } else { |
1361 browser_creator_->set_is_default_browser_dialog_suppressed(true); | 1369 browser_creator_->set_is_default_browser_dialog_suppressed(true); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1814 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1822 if (base::win::GetVersion() <= base::win::VERSION_XP) |
1815 uma_name += "_XP"; | 1823 uma_name += "_XP"; |
1816 | 1824 |
1817 uma_name += "_PreRead_"; | 1825 uma_name += "_PreRead_"; |
1818 uma_name += pre_read_percentage; | 1826 uma_name += pre_read_percentage; |
1819 AddPreReadHistogramTime(uma_name.c_str(), time); | 1827 AddPreReadHistogramTime(uma_name.c_str(), time); |
1820 } | 1828 } |
1821 #endif | 1829 #endif |
1822 #endif | 1830 #endif |
1823 } | 1831 } |
OLD | NEW |