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 3// found in the LICENSE file. 4 5#include "content/browser/browser_process_sub_thread.h" 6 7#include "base/debug/leak_tracker.h" 8#include "base/threading/thread_restrictions.h" 9#include "build/build_config.h" 10#include "content/browser/browser_child_process_host_impl.h" 11#include "content/browser/notification_service_impl.h" 12#include "net/url_request/url_fetcher.h" 13#include "net/url_request/url_request.h" 14 15#if defined(OS_WIN) 16#include "base/win/scoped_com_initializer.h" 17#endif 18 19namespace content { 20 21BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) 22 : BrowserThreadImpl(identifier) { 23} 24 25BrowserProcessSubThread::~BrowserProcessSubThread() { 26 Stop(); 27} 28 29void BrowserProcessSubThread::Init() { 30#if defined(OS_WIN) 31 com_initializer_.reset(new base::win::ScopedCOMInitializer()); 32#endif 33 34 notification_service_.reset(new NotificationServiceImpl()); 35 36 BrowserThreadImpl::Init(); 37 38 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 39 // Though this thread is called the "IO" thread, it actually just routes 40 // messages around; it shouldn't be allowed to perform any blocking disk 41 // I/O. 42 base::ThreadRestrictions::SetIOAllowed(false); 43 base::ThreadRestrictions::DisallowWaiting(); 44 } 45} 46 47void BrowserProcessSubThread::CleanUp() { 48 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) 49 IOThreadPreCleanUp(); 50 51 BrowserThreadImpl::CleanUp(); 52 53 notification_service_.reset(); 54 55#if defined(OS_WIN) 56 com_initializer_.reset(); 57#endif 58} 59 60void BrowserProcessSubThread::IOThreadPreCleanUp() { 61 // Kill all things that might be holding onto 62 // net::URLRequest/net::URLRequestContexts. 63 64 // Destroy all URLRequests started by URLFetchers. 65 net::URLFetcher::CancelAll(); 66 67#if !defined(OS_IOS) 68 // If any child processes are still running, terminate them and 69 // and delete the BrowserChildProcessHost instances to release whatever 70 // IO thread only resources they are referencing. 71 BrowserChildProcessHostImpl::TerminateAll(); 72#endif // !defined(OS_IOS) 73} 74 75} // namespace content 76