OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "chrome/browser/browser_thread.h" | 38 #include "chrome/browser/browser_thread.h" |
39 #include "chrome/browser/extensions/extension_protocols.h" | 39 #include "chrome/browser/extensions/extension_protocols.h" |
40 #include "chrome/browser/extensions/extension_service.h" | 40 #include "chrome/browser/extensions/extension_service.h" |
41 #include "chrome/browser/extensions/extensions_startup.h" | 41 #include "chrome/browser/extensions/extensions_startup.h" |
42 #include "chrome/browser/first_run/first_run.h" | 42 #include "chrome/browser/first_run/first_run.h" |
43 #include "chrome/browser/gpu_data_manager.h" | 43 #include "chrome/browser/gpu_data_manager.h" |
44 #include "chrome/browser/jankometer.h" | 44 #include "chrome/browser/jankometer.h" |
45 #include "chrome/browser/metrics/histogram_synchronizer.h" | 45 #include "chrome/browser/metrics/histogram_synchronizer.h" |
46 #include "chrome/browser/metrics/metrics_log.h" | 46 #include "chrome/browser/metrics/metrics_log.h" |
47 #include "chrome/browser/metrics/metrics_service.h" | 47 #include "chrome/browser/metrics/metrics_service.h" |
| 48 #include "chrome/browser/metrics/thread_watcher.h" |
48 #include "chrome/browser/net/blob_url_request_job_factory.h" | 49 #include "chrome/browser/net/blob_url_request_job_factory.h" |
49 #include "chrome/browser/net/chrome_dns_cert_provenance_checker.h" | 50 #include "chrome/browser/net/chrome_dns_cert_provenance_checker.h" |
50 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" | 51 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" |
51 #include "chrome/browser/net/file_system_url_request_job_factory.h" | 52 #include "chrome/browser/net/file_system_url_request_job_factory.h" |
52 #include "chrome/browser/net/metadata_url_request.h" | 53 #include "chrome/browser/net/metadata_url_request.h" |
53 #include "chrome/browser/net/predictor_api.h" | 54 #include "chrome/browser/net/predictor_api.h" |
54 #include "chrome/browser/net/sdch_dictionary_fetcher.h" | 55 #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
55 #include "chrome/browser/net/websocket_experiment/websocket_experiment_runner.h" | 56 #include "chrome/browser/net/websocket_experiment/websocket_experiment_runner.h" |
56 #include "chrome/browser/plugin_service.h" | 57 #include "chrome/browser/plugin_service.h" |
57 #include "chrome/browser/prefs/browser_prefs.h" | 58 #include "chrome/browser/prefs/browser_prefs.h" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 | 696 |
696 // Creates key child threads. We need to do this explicitly since | 697 // Creates key child threads. We need to do this explicitly since |
697 // BrowserThread::PostTask silently deletes a posted task if the target message | 698 // BrowserThread::PostTask silently deletes a posted task if the target message |
698 // loop isn't created. | 699 // loop isn't created. |
699 void CreateChildThreads(BrowserProcessImpl* process) { | 700 void CreateChildThreads(BrowserProcessImpl* process) { |
700 process->db_thread(); | 701 process->db_thread(); |
701 process->file_thread(); | 702 process->file_thread(); |
702 process->process_launcher_thread(); | 703 process->process_launcher_thread(); |
703 process->cache_thread(); | 704 process->cache_thread(); |
704 process->io_thread(); | 705 process->io_thread(); |
| 706 // Create watchdog thread after creating all other threads because it will |
| 707 // watch the other threads and they must be running. |
| 708 process->watchdog_thread(); |
705 } | 709 } |
706 | 710 |
707 // Returns the new local state object, guaranteed non-NULL. | 711 // Returns the new local state object, guaranteed non-NULL. |
708 PrefService* InitializeLocalState(const CommandLine& parsed_command_line, | 712 PrefService* InitializeLocalState(const CommandLine& parsed_command_line, |
709 bool is_first_run) { | 713 bool is_first_run) { |
710 FilePath local_state_path; | 714 FilePath local_state_path; |
711 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 715 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
712 bool local_state_file_exists = file_util::PathExists(local_state_path); | 716 bool local_state_file_exists = file_util::PathExists(local_state_path); |
713 | 717 |
714 // Load local state. This includes the application locale so we know which | 718 // Load local state. This includes the application locale so we know which |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 | 1350 |
1347 InitializeNetworkOptions(parsed_command_line); | 1351 InitializeNetworkOptions(parsed_command_line); |
1348 | 1352 |
1349 // Initialize histogram synchronizer system. This is a singleton and is used | 1353 // Initialize histogram synchronizer system. This is a singleton and is used |
1350 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of | 1354 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of |
1351 // scope. Even though NewRunnableMethod does AddRef and Release, the object | 1355 // scope. Even though NewRunnableMethod does AddRef and Release, the object |
1352 // will not be deleted after the Task is executed. | 1356 // will not be deleted after the Task is executed. |
1353 scoped_refptr<HistogramSynchronizer> histogram_synchronizer( | 1357 scoped_refptr<HistogramSynchronizer> histogram_synchronizer( |
1354 new HistogramSynchronizer()); | 1358 new HistogramSynchronizer()); |
1355 | 1359 |
| 1360 // Initialize thread watcher system. This is a singleton and is used by |
| 1361 // WatchDogThread to keep track of information about threads that are being |
| 1362 // watched. |
| 1363 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); |
| 1364 |
1356 // Initialize the prefs of the local state. | 1365 // Initialize the prefs of the local state. |
1357 browser::RegisterLocalState(local_state); | 1366 browser::RegisterLocalState(local_state); |
1358 | 1367 |
1359 // Convert active labs into switches. Modifies the current command line. | 1368 // Convert active labs into switches. Modifies the current command line. |
1360 about_flags::ConvertFlagsToSwitches(local_state, | 1369 about_flags::ConvertFlagsToSwitches(local_state, |
1361 CommandLine::ForCurrentProcess()); | 1370 CommandLine::ForCurrentProcess()); |
1362 | 1371 |
1363 // Now the command line has been mutated based on about:flags, we can run some | 1372 // Now the command line has been mutated based on about:flags, we can run some |
1364 // field trials | 1373 // field trials |
1365 parts->SetupFieldTrials(); | 1374 parts->SetupFieldTrials(); |
(...skipping 13 matching lines...) Expand all Loading... |
1379 // thread, which has a proper CFRunloop, instead of later on the I/O thread, | 1388 // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
1380 // which doesn't. This ensures those notifications will get delivered | 1389 // which doesn't. This ensures those notifications will get delivered |
1381 // properly. See issue 37766. | 1390 // properly. See issue 37766. |
1382 // (Note that the callback mask here is empty. I don't want to register for | 1391 // (Note that the callback mask here is empty. I don't want to register for |
1383 // any callbacks, I just want to initialize the mechanism.) | 1392 // any callbacks, I just want to initialize the mechanism.) |
1384 SecKeychainAddCallback(&KeychainCallback, 0, NULL); | 1393 SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
1385 #endif | 1394 #endif |
1386 | 1395 |
1387 CreateChildThreads(browser_process.get()); | 1396 CreateChildThreads(browser_process.get()); |
1388 | 1397 |
| 1398 // Start watching all browser threads for responsiveness. |
| 1399 MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop(); |
| 1400 if (message_loop) |
| 1401 message_loop->PostDelayedTask( |
| 1402 FROM_HERE, |
| 1403 NewRunnableFunction(&WatchDogThread::StartWatchingAll), |
| 1404 base::TimeDelta::FromSeconds(10).InMilliseconds()); |
| 1405 |
1389 #if defined(OS_CHROMEOS) | 1406 #if defined(OS_CHROMEOS) |
1390 // Now that the file thread exists we can record our stats. | 1407 // Now that the file thread exists we can record our stats. |
1391 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); | 1408 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); |
1392 // Change the UI font if necessary. This has to be done after | 1409 // Change the UI font if necessary. This has to be done after |
1393 // InitSharedInstance() is called, as it depends on resource data. | 1410 // InitSharedInstance() is called, as it depends on resource data. |
1394 MaybeChangeUIFont(); | 1411 MaybeChangeUIFont(); |
1395 | 1412 |
1396 // Trigger prefetching of ownership status. | 1413 // Trigger prefetching of ownership status. |
1397 chromeos::OwnershipService::GetSharedInstance(); | 1414 chromeos::OwnershipService::GetSharedInstance(); |
1398 #endif | 1415 #endif |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 search_engine_type, | 1913 search_engine_type, |
1897 SEARCH_ENGINE_MAX); | 1914 SEARCH_ENGINE_MAX); |
1898 } | 1915 } |
1899 } | 1916 } |
1900 #endif | 1917 #endif |
1901 | 1918 |
1902 chrome_browser_net_websocket_experiment::WebSocketExperimentRunner::Stop(); | 1919 chrome_browser_net_websocket_experiment::WebSocketExperimentRunner::Stop(); |
1903 | 1920 |
1904 process_singleton.Cleanup(); | 1921 process_singleton.Cleanup(); |
1905 | 1922 |
| 1923 // Stop all tasks that might run on WatchDogThread. |
| 1924 ThreadWatcherList::StopWatchingAll(); |
| 1925 |
1906 metrics->Stop(); | 1926 metrics->Stop(); |
1907 | 1927 |
1908 // browser_shutdown takes care of deleting browser_process, so we need to | 1928 // browser_shutdown takes care of deleting browser_process, so we need to |
1909 // release it. | 1929 // release it. |
1910 ignore_result(browser_process.release()); | 1930 ignore_result(browser_process.release()); |
1911 browser_shutdown::Shutdown(); | 1931 browser_shutdown::Shutdown(); |
1912 | 1932 |
1913 #if defined(OS_CHROMEOS) | 1933 #if defined(OS_CHROMEOS) |
1914 // To be precise, logout (browser shutdown) is not yet done, but the | 1934 // To be precise, logout (browser shutdown) is not yet done, but the |
1915 // remaining work is negligible, hence we say LogoutDone here. | 1935 // remaining work is negligible, hence we say LogoutDone here. |
1916 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 1936 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
1917 false); | 1937 false); |
1918 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 1938 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
1919 #endif | 1939 #endif |
1920 TRACE_EVENT_END("BrowserMain", 0, 0); | 1940 TRACE_EVENT_END("BrowserMain", 0, 0); |
1921 return result_code; | 1941 return result_code; |
1922 } | 1942 } |
OLD | NEW |