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 "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 #endif | 1267 #endif |
1268 | 1268 |
1269 if (BrowserGpuChannelHostFactory::instance()) { | 1269 if (BrowserGpuChannelHostFactory::instance()) { |
1270 BrowserGpuChannelHostFactory::instance()->CloseChannel(); | 1270 BrowserGpuChannelHostFactory::instance()->CloseChannel(); |
1271 } | 1271 } |
1272 | 1272 |
1273 // Shutdown the Service Manager and IPC. | 1273 // Shutdown the Service Manager and IPC. |
1274 service_manager_context_.reset(); | 1274 service_manager_context_.reset(); |
1275 mojo_ipc_support_.reset(); | 1275 mojo_ipc_support_.reset(); |
1276 | 1276 |
| 1277 // Must be size_t so we can subtract from it. |
| 1278 for (size_t thread_id = BrowserThread::ID_COUNT - 1; |
| 1279 thread_id >= (BrowserThread::UI + 1); |
| 1280 --thread_id) { |
| 1281 // Find the thread object we want to stop. Looping over all valid |
| 1282 // BrowserThread IDs and DCHECKing on a missing case in the switch |
| 1283 // statement helps avoid a mismatch between this code and the |
| 1284 // BrowserThread::ID enumeration. |
| 1285 // |
| 1286 // The destruction order is the reverse order of occurrence in the |
| 1287 // BrowserThread::ID list. The rationale for the order is as |
| 1288 // follows (need to be filled in a bit): |
| 1289 // |
| 1290 // |
| 1291 // - The IO thread is the only user of the CACHE thread. |
| 1292 // |
| 1293 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
| 1294 // the IO thread posted a task to terminate a process on the |
| 1295 // process launcher thread. |
| 1296 // |
| 1297 // - (Not sure why DB stops last.) |
| 1298 switch (thread_id) { |
| 1299 case BrowserThread::DB: { |
| 1300 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); |
| 1301 ResetThread_DB(std::move(db_thread_)); |
| 1302 break; |
| 1303 } |
| 1304 case BrowserThread::FILE: { |
| 1305 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); |
| 1306 // Clean up state that lives on or uses the FILE thread before it goes |
| 1307 // away. |
| 1308 save_file_manager_->Shutdown(); |
| 1309 ResetThread_FILE(std::move(file_thread_)); |
| 1310 break; |
| 1311 } |
| 1312 case BrowserThread::FILE_USER_BLOCKING: { |
| 1313 TRACE_EVENT0("shutdown", |
| 1314 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); |
| 1315 ResetThread_FILE_USER_BLOCKING(std::move(file_user_blocking_thread_)); |
| 1316 break; |
| 1317 } |
| 1318 case BrowserThread::PROCESS_LAUNCHER: { |
| 1319 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); |
| 1320 ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_)); |
| 1321 break; |
| 1322 } |
| 1323 case BrowserThread::CACHE: { |
| 1324 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); |
| 1325 ResetThread_CACHE(std::move(cache_thread_)); |
| 1326 break; |
| 1327 } |
| 1328 case BrowserThread::IO: { |
| 1329 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); |
| 1330 ResetThread_IO(std::move(io_thread_)); |
| 1331 break; |
| 1332 } |
| 1333 case BrowserThread::UI: |
| 1334 case BrowserThread::ID_COUNT: |
| 1335 NOTREACHED(); |
| 1336 break; |
| 1337 } |
| 1338 } |
1277 { | 1339 { |
1278 base::ThreadRestrictions::ScopedAllowWait allow_wait_for_join; | 1340 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); |
| 1341 ResetThread_IndexedDb(std::move(indexed_db_thread_)); |
| 1342 } |
1279 | 1343 |
1280 // Must be size_t so we can subtract from it. | 1344 // Close the blocking I/O pool after the other threads. Other threads such |
1281 for (size_t thread_id = BrowserThread::ID_COUNT - 1; | 1345 // as the I/O thread may need to schedule work like closing files or flushing |
1282 thread_id >= (BrowserThread::UI + 1); --thread_id) { | 1346 // data during shutdown, so the blocking pool needs to be available. There |
1283 // Find the thread object we want to stop. Looping over all valid | 1347 // may also be slow operations pending that will blcok shutdown, so closing |
1284 // BrowserThread IDs and DCHECKing on a missing case in the switch | 1348 // it here (which will block until required operations are complete) gives |
1285 // statement helps avoid a mismatch between this code and the | 1349 // more head start for those operations to finish. |
1286 // BrowserThread::ID enumeration. | 1350 { |
1287 // | 1351 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool"); |
1288 // The destruction order is the reverse order of occurrence in the | 1352 BrowserThreadImpl::ShutdownThreadPool(); |
1289 // BrowserThread::ID list. The rationale for the order is as follows (need | 1353 } |
1290 // to be filled in a bit): | 1354 { |
1291 // | 1355 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:TaskScheduler"); |
1292 // - The IO thread is the only user of the CACHE thread. | 1356 base::TaskScheduler::GetInstance()->Shutdown(); |
1293 // | |
1294 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | |
1295 // the IO thread posted a task to terminate a process on the | |
1296 // process launcher thread. | |
1297 // | |
1298 // - (Not sure why DB stops last.) | |
1299 switch (thread_id) { | |
1300 case BrowserThread::DB: { | |
1301 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); | |
1302 ResetThread_DB(std::move(db_thread_)); | |
1303 break; | |
1304 } | |
1305 case BrowserThread::FILE: { | |
1306 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); | |
1307 // Clean up state that lives on or uses the FILE thread before it goes | |
1308 // away. | |
1309 save_file_manager_->Shutdown(); | |
1310 ResetThread_FILE(std::move(file_thread_)); | |
1311 break; | |
1312 } | |
1313 case BrowserThread::FILE_USER_BLOCKING: { | |
1314 TRACE_EVENT0("shutdown", | |
1315 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); | |
1316 ResetThread_FILE_USER_BLOCKING(std::move(file_user_blocking_thread_)); | |
1317 break; | |
1318 } | |
1319 case BrowserThread::PROCESS_LAUNCHER: { | |
1320 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); | |
1321 ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_)); | |
1322 break; | |
1323 } | |
1324 case BrowserThread::CACHE: { | |
1325 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); | |
1326 ResetThread_CACHE(std::move(cache_thread_)); | |
1327 break; | |
1328 } | |
1329 case BrowserThread::IO: { | |
1330 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); | |
1331 ResetThread_IO(std::move(io_thread_)); | |
1332 break; | |
1333 } | |
1334 case BrowserThread::UI: | |
1335 case BrowserThread::ID_COUNT: | |
1336 NOTREACHED(); | |
1337 break; | |
1338 } | |
1339 } | |
1340 { | |
1341 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); | |
1342 ResetThread_IndexedDb(std::move(indexed_db_thread_)); | |
1343 } | |
1344 | |
1345 // Close the blocking I/O pool after the other threads. Other threads such | |
1346 // as the I/O thread may need to schedule work like closing files or | |
1347 // flushing data during shutdown, so the blocking pool needs to be | |
1348 // available. There may also be slow operations pending that will blcok | |
1349 // shutdown, so closing it here (which will block until required operations | |
1350 // are complete) gives more head start for those operations to finish. | |
1351 { | |
1352 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool"); | |
1353 BrowserThreadImpl::ShutdownThreadPool(); | |
1354 } | |
1355 { | |
1356 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:TaskScheduler"); | |
1357 base::TaskScheduler::GetInstance()->Shutdown(); | |
1358 } | |
1359 } | 1357 } |
1360 | 1358 |
1361 // Must happen after the IO thread is shutdown since this may be accessed from | 1359 // Must happen after the IO thread is shutdown since this may be accessed from |
1362 // it. | 1360 // it. |
1363 { | 1361 { |
1364 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); | 1362 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); |
1365 if (BrowserGpuChannelHostFactory::instance()) { | 1363 if (BrowserGpuChannelHostFactory::instance()) { |
1366 BrowserGpuChannelHostFactory::Terminate(); | 1364 BrowserGpuChannelHostFactory::Terminate(); |
1367 } | 1365 } |
1368 } | 1366 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1773 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
1776 MediaInternals::GetInstance()); | 1774 MediaInternals::GetInstance()); |
1777 } | 1775 } |
1778 CHECK(audio_manager_); | 1776 CHECK(audio_manager_); |
1779 | 1777 |
1780 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1778 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
1781 CHECK(audio_system_); | 1779 CHECK(audio_system_); |
1782 } | 1780 } |
1783 | 1781 |
1784 } // namespace content | 1782 } // namespace content |
OLD | NEW |