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

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 2790473006: Replace IOAllowed with WaitAllowed in PlatformThread::Join()
Patch Set: allow in IOThreadPreCleanup() Created 3 years, 8 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
« no previous file with comments | « base/threading/thread_restrictions.h ('k') | content/browser/browser_process_sub_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 TRACE_EVENT_ASYNC_END0("toplevel", "BrowserMain:MESSAGE_LOOP", this); 1191 TRACE_EVENT_ASYNC_END0("toplevel", "BrowserMain:MESSAGE_LOOP", this);
1192 } 1192 }
1193 1193
1194 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { 1194 void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
1195 if (!created_threads_) { 1195 if (!created_threads_) {
1196 // Called early, nothing to do 1196 // Called early, nothing to do
1197 return; 1197 return;
1198 } 1198 }
1199 TRACE_EVENT0("shutdown", "BrowserMainLoop::ShutdownThreadsAndCleanUp"); 1199 TRACE_EVENT0("shutdown", "BrowserMainLoop::ShutdownThreadsAndCleanUp");
1200 1200
1201 // Teardown may start in PostMainMessageLoopRun, and during teardown we 1201 // Teardown may start in PostMainMessageLoopRun, and during teardown we need
1202 // need to be able to perform IO. 1202 // to be able to perform IO and perform blocking waits (e.g. joining threads).
1203 base::ThreadRestrictions::SetIOAllowed(true); 1203 base::ThreadRestrictions::SetIOAllowed(true);
1204 base::ThreadRestrictions::SetWaitAllowed(true);
1204 BrowserThread::PostTask( 1205 BrowserThread::PostTask(
1205 BrowserThread::IO, FROM_HERE, 1206 BrowserThread::IO, FROM_HERE,
1206 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 1207 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
1207 true)); 1208 true));
1208 1209
1209 #if defined(OS_ANDROID) 1210 #if defined(OS_ANDROID)
1210 g_browser_main_loop_shutting_down = true; 1211 g_browser_main_loop_shutting_down = true;
1211 #endif 1212 #endif
1212 1213
1213 if (RenderProcessHost::run_renderer_in_process()) 1214 if (RenderProcessHost::run_renderer_in_process())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 #endif 1268 #endif
1268 1269
1269 if (BrowserGpuChannelHostFactory::instance()) { 1270 if (BrowserGpuChannelHostFactory::instance()) {
1270 BrowserGpuChannelHostFactory::instance()->CloseChannel(); 1271 BrowserGpuChannelHostFactory::instance()->CloseChannel();
1271 } 1272 }
1272 1273
1273 // Shutdown the Service Manager and IPC. 1274 // Shutdown the Service Manager and IPC.
1274 service_manager_context_.reset(); 1275 service_manager_context_.reset();
1275 mojo_ipc_support_.reset(); 1276 mojo_ipc_support_.reset();
1276 1277
1278 // Must be size_t so we can subtract from it.
1279 for (size_t thread_id = BrowserThread::ID_COUNT - 1;
1280 thread_id >= (BrowserThread::UI + 1); --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 follows (need
1288 // to be filled in a bit):
1289 //
1290 // - The IO thread is the only user of the CACHE thread.
1291 //
1292 // - The PROCESS_LAUNCHER thread must be stopped after IO in case
1293 // the IO thread posted a task to terminate a process on the
1294 // process launcher thread.
1295 //
1296 // - (Not sure why DB stops last.)
1297 switch (thread_id) {
1298 case BrowserThread::DB: {
1299 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread");
1300 ResetThread_DB(std::move(db_thread_));
1301 break;
1302 }
1303 case BrowserThread::FILE: {
1304 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread");
1305 // Clean up state that lives on or uses the FILE thread before it goes
1306 // away.
1307 save_file_manager_->Shutdown();
1308 ResetThread_FILE(std::move(file_thread_));
1309 break;
1310 }
1311 case BrowserThread::FILE_USER_BLOCKING: {
1312 TRACE_EVENT0("shutdown",
1313 "BrowserMainLoop::Subsystem:FileUserBlockingThread");
1314 ResetThread_FILE_USER_BLOCKING(std::move(file_user_blocking_thread_));
1315 break;
1316 }
1317 case BrowserThread::PROCESS_LAUNCHER: {
1318 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread");
1319 ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_));
1320 break;
1321 }
1322 case BrowserThread::CACHE: {
1323 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread");
1324 ResetThread_CACHE(std::move(cache_thread_));
1325 break;
1326 }
1327 case BrowserThread::IO: {
1328 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread");
1329 ResetThread_IO(std::move(io_thread_));
1330 break;
1331 }
1332 case BrowserThread::UI:
1333 case BrowserThread::ID_COUNT:
1334 NOTREACHED();
1335 break;
1336 }
1337 }
1277 { 1338 {
1278 base::ThreadRestrictions::ScopedAllowWait allow_wait_for_join; 1339 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread");
1340 ResetThread_IndexedDb(std::move(indexed_db_thread_));
1341 }
1279 1342
1280 // Must be size_t so we can subtract from it. 1343 // Close the blocking I/O pool after the other threads. Other threads such
1281 for (size_t thread_id = BrowserThread::ID_COUNT - 1; 1344 // as the I/O thread may need to schedule work like closing files or
1282 thread_id >= (BrowserThread::UI + 1); --thread_id) { 1345 // flushing data during shutdown, so the blocking pool needs to be
1283 // Find the thread object we want to stop. Looping over all valid 1346 // available. There may also be slow operations pending that will blcok
1284 // BrowserThread IDs and DCHECKing on a missing case in the switch 1347 // shutdown, so closing it here (which will block until required operations
1285 // statement helps avoid a mismatch between this code and the 1348 // are complete) gives more head start for those operations to finish.
1286 // BrowserThread::ID enumeration. 1349 {
1287 // 1350 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool");
1288 // The destruction order is the reverse order of occurrence in the 1351 BrowserThreadImpl::ShutdownThreadPool();
1289 // BrowserThread::ID list. The rationale for the order is as follows (need 1352 }
1290 // to be filled in a bit): 1353 {
1291 // 1354 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:TaskScheduler");
1292 // - The IO thread is the only user of the CACHE thread. 1355 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 } 1356 }
1360 1357
1361 // Must happen after the IO thread is shutdown since this may be accessed from 1358 // Must happen after the IO thread is shutdown since this may be accessed from
1362 // it. 1359 // it.
1363 { 1360 {
1364 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); 1361 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory");
1365 if (BrowserGpuChannelHostFactory::instance()) { 1362 if (BrowserGpuChannelHostFactory::instance()) {
1366 BrowserGpuChannelHostFactory::Terminate(); 1363 BrowserGpuChannelHostFactory::Terminate();
1367 } 1364 }
1368 } 1365 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), 1772 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
1776 MediaInternals::GetInstance()); 1773 MediaInternals::GetInstance());
1777 } 1774 }
1778 CHECK(audio_manager_); 1775 CHECK(audio_manager_);
1779 1776
1780 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 1777 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
1781 CHECK(audio_system_); 1778 CHECK(audio_system_);
1782 } 1779 }
1783 1780
1784 } // namespace content 1781 } // namespace content
OLDNEW
« no previous file with comments | « base/threading/thread_restrictions.h ('k') | content/browser/browser_process_sub_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698