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