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

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

Issue 9150016: Move creation and ownership of ResourceDispatcherHost and PluginService to content. This gives a ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 } 1149 }
1150 1150
1151 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { 1151 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
1152 // User wants to override default tracking status. 1152 // User wants to override default tracking status.
1153 std::string flag = 1153 std::string flag =
1154 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); 1154 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
1155 bool enabled = flag.compare("0") != 0; 1155 bool enabled = flag.compare("0") != 0;
1156 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled); 1156 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled);
1157 } 1157 }
1158 1158
1159 browser_process_->PreCreateThreads();
1160
1159 // This forces the TabCloseableStateWatcher to be created and, on chromeos, 1161 // This forces the TabCloseableStateWatcher to be created and, on chromeos,
1160 // register for the notifications it needs to track the closeable state of 1162 // register for the notifications it needs to track the closeable state of
1161 // tabs. 1163 // tabs.
1162 browser_process_->tab_closeable_state_watcher(); 1164 browser_process_->tab_closeable_state_watcher();
1163 1165
1164 local_state_ = InitializeLocalState(parsed_command_line(), 1166 local_state_ = InitializeLocalState(parsed_command_line(),
1165 is_first_run_); 1167 is_first_run_);
1166 1168
1167 // If we're running tests (ui_task is non-null), then the ResourceBundle 1169 // If we're running tests (ui_task is non-null), then the ResourceBundle
1168 // has already been initialized. 1170 // has already been initialized.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 // which doesn't. This ensures those notifications will get delivered 1307 // which doesn't. This ensures those notifications will get delivered
1306 // properly. See issue 37766. 1308 // properly. See issue 37766.
1307 // (Note that the callback mask here is empty. I don't want to register for 1309 // (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.) 1310 // any callbacks, I just want to initialize the mechanism.)
1309 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1311 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1310 #endif 1312 #endif
1311 1313
1312 return content::RESULT_CODE_NORMAL_EXIT; 1314 return content::RESULT_CODE_NORMAL_EXIT;
1313 } 1315 }
1314 1316
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() { 1317 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1348 result_code_ = PreMainMessageLoopRunImpl(); 1318 result_code_ = PreMainMessageLoopRunImpl();
1349 1319
1350 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1320 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1351 chrome_extra_parts_[i]->PreMainMessageLoopRun(); 1321 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1352 } 1322 }
1353 1323
1354 // PreMainMessageLoopRun calls these extra stages in the following order: 1324 // PreMainMessageLoopRun calls these extra stages in the following order:
1355 // PreMainMessageLoopRunImpl() 1325 // PreMainMessageLoopRunImpl()
1356 // ... initial setup, including browser_process_ setup. 1326 // ... initial setup, including browser_process_ setup.
(...skipping 19 matching lines...) Expand all
1376 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1346 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1377 chrome_extra_parts_[i]->PreBrowserStart(); 1347 chrome_extra_parts_[i]->PreBrowserStart();
1378 } 1348 }
1379 1349
1380 void ChromeBrowserMainParts::PostBrowserStart() { 1350 void ChromeBrowserMainParts::PostBrowserStart() {
1381 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1351 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1382 chrome_extra_parts_[i]->PostBrowserStart(); 1352 chrome_extra_parts_[i]->PostBrowserStart();
1383 } 1353 }
1384 1354
1385 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1355 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1356 // Now the command line has been mutated based on about:flags,
1357 // and the file thread has been started, we can set up metrics
1358 // and initialize field trials.
1359 metrics_ = SetupMetricsAndFieldTrials(local_state_);
1360
1361 #if defined(USE_LINUX_BREAKPAD)
1362 // Needs to be called after we have chrome::DIR_USER_DATA and
1363 // g_browser_process. This happens in PreCreateThreads.
1364 BrowserThread::PostTask(BrowserThread::FILE,
1365 FROM_HERE,
1366 base::Bind(&GetLinuxDistroCallback));
1367
1368 if (IsCrashReportingEnabled(local_state_))
1369 InitCrashReporter();
1370 #endif
1371
1386 // Create watchdog thread after creating all other threads because it will 1372 // Create watchdog thread after creating all other threads because it will
1387 // watch the other threads and they must be running. 1373 // watch the other threads and they must be running.
1388 browser_process_->watchdog_thread(); 1374 browser_process_->watchdog_thread();
1389 1375
1390 // Do any initializating in the browser process that requires all threads 1376 // Do any initializating in the browser process that requires all threads
1391 // running. 1377 // running.
1392 browser_process_->PreMainMessageLoopRun(); 1378 browser_process_->PreMainMessageLoopRun();
1393 1379
1394 #if defined(USE_WEBKIT_COMPOSITOR) 1380 #if defined(USE_WEBKIT_COMPOSITOR)
1395 // We need to ensure WebKit has been initialized before we start the WebKit 1381 // We need to ensure WebKit has been initialized before we start the WebKit
1396 // compositor. This is done by the ResourceDispatcherHost on creation. 1382 // compositor. This is done by the ResourceDispatcherHost on creation.
1397 browser_process_->resource_dispatcher_host(); 1383 ResourceDispatcherHost::Get();
1398 #endif 1384 #endif
1399 1385
1400 // Record last shutdown time into a histogram. 1386 // Record last shutdown time into a histogram.
1401 browser_shutdown::ReadLastShutdownInfo(); 1387 browser_shutdown::ReadLastShutdownInfo();
1402 1388
1403 #if defined(OS_WIN) 1389 #if defined(OS_WIN)
1404 // On Windows, we use our startup as an opportunity to do upgrade/uninstall 1390 // 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, 1391 // tasks. Those care whether the browser is already running. On Linux/Mac,
1406 // upgrade/uninstall happen separately. 1392 // upgrade/uninstall happen separately.
1407 bool already_running = browser_util::IsBrowserAlreadyRunning(); 1393 bool already_running = browser_util::IsBrowserAlreadyRunning();
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 1907
1922 // Stop all tasks that might run on WatchDogThread. 1908 // Stop all tasks that might run on WatchDogThread.
1923 ThreadWatcherList::StopWatchingAll(); 1909 ThreadWatcherList::StopWatchingAll();
1924 1910
1925 browser_process_->metrics_service()->Stop(); 1911 browser_process_->metrics_service()->Stop();
1926 1912
1927 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); 1913 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
1928 browser_process_->StartTearDown(); 1914 browser_process_->StartTearDown();
1929 } 1915 }
1930 1916
1931 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) {
1932 browser_process_->PreStopThread(identifier);
1933 }
1934
1935 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) {
1936 browser_process_->PostStopThread(identifier);
1937 }
1938
1939 void ChromeBrowserMainParts::PostDestroyThreads() { 1917 void ChromeBrowserMainParts::PostDestroyThreads() {
1918 browser_process_->PostDestroyThreads();
1940 // browser_shutdown takes care of deleting browser_process, so we need to 1919 // browser_shutdown takes care of deleting browser_process, so we need to
1941 // release it. 1920 // release it.
1942 ignore_result(browser_process_.release()); 1921 ignore_result(browser_process_.release());
1943 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); 1922 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
1944 master_prefs_.reset(); 1923 master_prefs_.reset();
1945 process_singleton_.reset(); 1924 process_singleton_.reset();
1946 1925
1947 // We need to do this check as late as possible, but due to modularity, this 1926 // We need to do this check as late as possible, but due to modularity, this
1948 // may be the last point in Chrome. This would be more effective if done at 1927 // may be the last point in Chrome. This would be more effective if done at
1949 // a higher level on the stack, so that it is impossible for an early return 1928 // 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
1986 if (base::win::GetVersion() <= base::win::VERSION_XP) 1965 if (base::win::GetVersion() <= base::win::VERSION_XP)
1987 uma_name += "_XP"; 1966 uma_name += "_XP";
1988 1967
1989 uma_name += "_PreRead"; 1968 uma_name += "_PreRead";
1990 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 1969 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
1991 AddPreReadHistogramTime(uma_name.c_str(), time); 1970 AddPreReadHistogramTime(uma_name.c_str(), time);
1992 } 1971 }
1993 #endif 1972 #endif
1994 #endif 1973 #endif
1995 } 1974 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698