Chromium Code Reviews| 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 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1302 #if defined(OS_MACOSX) | 1302 #if defined(OS_MACOSX) |
| 1303 // Get the Keychain API to register for distributed notifications on the main | 1303 // Get the Keychain API to register for distributed notifications on the main |
| 1304 // thread, which has a proper CFRunloop, instead of later on the I/O thread, | 1304 // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
| 1305 // which doesn't. This ensures those notifications will get delivered | 1305 // which doesn't. This ensures those notifications will get delivered |
| 1306 // properly. See issue 37766. | 1306 // properly. See issue 37766. |
| 1307 // (Note that the callback mask here is empty. I don't want to register for | 1307 // (Note that the callback mask here is empty. I don't want to register for |
| 1308 // any callbacks, I just want to initialize the mechanism.) | 1308 // any callbacks, I just want to initialize the mechanism.) |
| 1309 SecKeychainAddCallback(&KeychainCallback, 0, NULL); | 1309 SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
| 1310 #endif | 1310 #endif |
| 1311 | 1311 |
| 1312 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | |
| 1313 browser_process_->PreCreateThreads(); | |
|
Finnur
2012/01/18 17:11:06
I believe this CL caused a crasher in the toast co
| |
| 1314 | |
| 1312 return content::RESULT_CODE_NORMAL_EXIT; | 1315 return content::RESULT_CODE_NORMAL_EXIT; |
| 1313 } | 1316 } |
| 1314 | 1317 |
| 1315 void ChromeBrowserMainParts::PreStartThread( | |
| 1316 content::BrowserThread::ID thread_id) { | |
| 1317 browser_process_->PreStartThread(thread_id); | |
| 1318 } | |
| 1319 | |
| 1320 void ChromeBrowserMainParts::PostStartThread( | |
| 1321 content::BrowserThread::ID thread_id) { | |
| 1322 browser_process_->PostStartThread(thread_id); | |
| 1323 switch (thread_id) { | |
| 1324 case BrowserThread::FILE: | |
| 1325 // Now the command line has been mutated based on about:flags, | |
| 1326 // and the file thread has been started, we can set up metrics | |
| 1327 // and initialize field trials. | |
| 1328 metrics_ = SetupMetricsAndFieldTrials(local_state_); | |
| 1329 | |
| 1330 #if defined(USE_LINUX_BREAKPAD) | |
| 1331 // Needs to be called after we have chrome::DIR_USER_DATA and | |
| 1332 // g_browser_process. This happens in PreCreateThreads. | |
| 1333 BrowserThread::PostTask(BrowserThread::FILE, | |
| 1334 FROM_HERE, | |
| 1335 base::Bind(&GetLinuxDistroCallback)); | |
| 1336 | |
| 1337 if (IsCrashReportingEnabled(local_state_)) | |
| 1338 InitCrashReporter(); | |
| 1339 #endif | |
| 1340 break; | |
| 1341 | |
| 1342 default: | |
| 1343 break; | |
| 1344 } | |
| 1345 } | |
| 1346 | |
| 1347 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1318 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
| 1348 result_code_ = PreMainMessageLoopRunImpl(); | 1319 result_code_ = PreMainMessageLoopRunImpl(); |
| 1349 | 1320 |
| 1350 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1321 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1351 chrome_extra_parts_[i]->PreMainMessageLoopRun(); | 1322 chrome_extra_parts_[i]->PreMainMessageLoopRun(); |
| 1352 } | 1323 } |
| 1353 | 1324 |
| 1354 // PreMainMessageLoopRun calls these extra stages in the following order: | 1325 // PreMainMessageLoopRun calls these extra stages in the following order: |
| 1355 // PreMainMessageLoopRunImpl() | 1326 // PreMainMessageLoopRunImpl() |
| 1356 // ... initial setup, including browser_process_ setup. | 1327 // ... initial setup, including browser_process_ setup. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1376 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1347 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1377 chrome_extra_parts_[i]->PreBrowserStart(); | 1348 chrome_extra_parts_[i]->PreBrowserStart(); |
| 1378 } | 1349 } |
| 1379 | 1350 |
| 1380 void ChromeBrowserMainParts::PostBrowserStart() { | 1351 void ChromeBrowserMainParts::PostBrowserStart() { |
| 1381 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1352 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1382 chrome_extra_parts_[i]->PostBrowserStart(); | 1353 chrome_extra_parts_[i]->PostBrowserStart(); |
| 1383 } | 1354 } |
| 1384 | 1355 |
| 1385 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1356 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
| 1357 // Now the command line has been mutated based on about:flags, | |
| 1358 // and the file thread has been started, we can set up metrics | |
| 1359 // and initialize field trials. | |
| 1360 metrics_ = SetupMetricsAndFieldTrials(local_state_); | |
| 1361 | |
| 1362 #if defined(USE_LINUX_BREAKPAD) | |
| 1363 // Needs to be called after we have chrome::DIR_USER_DATA and | |
| 1364 // g_browser_process. This happens in PreCreateThreads. | |
| 1365 BrowserThread::PostTask(BrowserThread::FILE, | |
| 1366 FROM_HERE, | |
| 1367 base::Bind(&GetLinuxDistroCallback)); | |
| 1368 | |
| 1369 if (IsCrashReportingEnabled(local_state_)) | |
| 1370 InitCrashReporter(); | |
| 1371 #endif | |
| 1372 | |
| 1386 // Create watchdog thread after creating all other threads because it will | 1373 // Create watchdog thread after creating all other threads because it will |
| 1387 // watch the other threads and they must be running. | 1374 // watch the other threads and they must be running. |
| 1388 browser_process_->watchdog_thread(); | 1375 browser_process_->watchdog_thread(); |
| 1389 | 1376 |
| 1390 // Do any initializating in the browser process that requires all threads | 1377 // Do any initializating in the browser process that requires all threads |
| 1391 // running. | 1378 // running. |
| 1392 browser_process_->PreMainMessageLoopRun(); | 1379 browser_process_->PreMainMessageLoopRun(); |
| 1393 | 1380 |
| 1394 #if defined(USE_WEBKIT_COMPOSITOR) | |
| 1395 // We need to ensure WebKit has been initialized before we start the WebKit | |
| 1396 // compositor. This is done by the ResourceDispatcherHost on creation. | |
| 1397 browser_process_->resource_dispatcher_host(); | |
| 1398 #endif | |
| 1399 | |
| 1400 // Record last shutdown time into a histogram. | 1381 // Record last shutdown time into a histogram. |
| 1401 browser_shutdown::ReadLastShutdownInfo(); | 1382 browser_shutdown::ReadLastShutdownInfo(); |
| 1402 | 1383 |
| 1403 #if defined(OS_WIN) | 1384 #if defined(OS_WIN) |
| 1404 // On Windows, we use our startup as an opportunity to do upgrade/uninstall | 1385 // On Windows, we use our startup as an opportunity to do upgrade/uninstall |
| 1405 // tasks. Those care whether the browser is already running. On Linux/Mac, | 1386 // tasks. Those care whether the browser is already running. On Linux/Mac, |
| 1406 // upgrade/uninstall happen separately. | 1387 // upgrade/uninstall happen separately. |
| 1407 bool already_running = browser_util::IsBrowserAlreadyRunning(); | 1388 bool already_running = browser_util::IsBrowserAlreadyRunning(); |
| 1408 | 1389 |
| 1409 // If the command line specifies 'uninstall' then we need to work here | 1390 // If the command line specifies 'uninstall' then we need to work here |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1923 | 1904 |
| 1924 // Stop all tasks that might run on WatchDogThread. | 1905 // Stop all tasks that might run on WatchDogThread. |
| 1925 ThreadWatcherList::StopWatchingAll(); | 1906 ThreadWatcherList::StopWatchingAll(); |
| 1926 | 1907 |
| 1927 browser_process_->metrics_service()->Stop(); | 1908 browser_process_->metrics_service()->Stop(); |
| 1928 | 1909 |
| 1929 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); | 1910 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); |
| 1930 browser_process_->StartTearDown(); | 1911 browser_process_->StartTearDown(); |
| 1931 } | 1912 } |
| 1932 | 1913 |
| 1933 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) { | |
| 1934 browser_process_->PreStopThread(identifier); | |
| 1935 } | |
| 1936 | |
| 1937 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) { | |
| 1938 browser_process_->PostStopThread(identifier); | |
| 1939 } | |
| 1940 | |
| 1941 void ChromeBrowserMainParts::PostDestroyThreads() { | 1914 void ChromeBrowserMainParts::PostDestroyThreads() { |
| 1915 browser_process_->PostDestroyThreads(); | |
| 1942 // browser_shutdown takes care of deleting browser_process, so we need to | 1916 // browser_shutdown takes care of deleting browser_process, so we need to |
| 1943 // release it. | 1917 // release it. |
| 1944 ignore_result(browser_process_.release()); | 1918 ignore_result(browser_process_.release()); |
| 1945 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); | 1919 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); |
| 1946 master_prefs_.reset(); | 1920 master_prefs_.reset(); |
| 1947 process_singleton_.reset(); | 1921 process_singleton_.reset(); |
| 1948 | 1922 |
| 1949 // We need to do this check as late as possible, but due to modularity, this | 1923 // We need to do this check as late as possible, but due to modularity, this |
| 1950 // may be the last point in Chrome. This would be more effective if done at | 1924 // may be the last point in Chrome. This would be more effective if done at |
| 1951 // a higher level on the stack, so that it is impossible for an early return | 1925 // a higher level on the stack, so that it is impossible for an early return |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1988 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1962 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 1989 uma_name += "_XP"; | 1963 uma_name += "_XP"; |
| 1990 | 1964 |
| 1991 uma_name += "_PreRead"; | 1965 uma_name += "_PreRead"; |
| 1992 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 1966 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
| 1993 AddPreReadHistogramTime(uma_name.c_str(), time); | 1967 AddPreReadHistogramTime(uma_name.c_str(), time); |
| 1994 } | 1968 } |
| 1995 #endif | 1969 #endif |
| 1996 #endif | 1970 #endif |
| 1997 } | 1971 } |
| OLD | NEW |