blob: 19a9e15777a26b4935d92af33c07aa9fa428ade3 [file] [log] [blame]
[email protected]ef2bf422012-05-11 03:27:091// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0ac83682010-01-22 17:46:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b0f146f2011-09-15 22:14:255#include "content/browser/browser_process_sub_thread.h"
6
[email protected]0ac83682010-01-22 17:46:277#if defined(OS_WIN)
8#include <Objbase.h>
9#endif
10
[email protected]af669932012-01-17 19:26:5811#include "base/debug/leak_tracker.h"
[email protected]3a7b66d2012-04-26 16:34:1612#include "base/threading/thread_restrictions.h"
[email protected]af669932012-01-17 19:26:5813#include "build/build_config.h"
[email protected]4c01d4992012-01-23 23:33:0114#include "content/browser/browser_child_process_host_impl.h"
[email protected]af669932012-01-17 19:26:5815#include "content/browser/notification_service_impl.h"
[email protected]3dc1bc42012-06-19 08:20:5316#include "net/url_request/url_fetcher.h"
[email protected]af669932012-01-17 19:26:5817#include "net/url_request/url_request.h"
18
[email protected]c38831a12011-10-28 12:44:4919namespace content {
20
[email protected]d04e7662010-10-10 22:24:4821BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier)
[email protected]435756b2012-10-01 21:19:3622 : BrowserThreadImpl(identifier) {
[email protected]5abe6302011-12-20 23:44:3223}
[email protected]0ac83682010-01-22 17:46:2724
25BrowserProcessSubThread::~BrowserProcessSubThread() {
[email protected]0ac83682010-01-22 17:46:2726 Stop();
27}
28
29void BrowserProcessSubThread::Init() {
30#if defined(OS_WIN)
31 // Initializes the COM library on the current thread.
32 CoInitialize(NULL);
33#endif
34
[email protected]435756b2012-10-01 21:19:3635 notification_service_.reset(new NotificationServiceImpl());
[email protected]2e5b60a22011-11-28 15:56:4136
37 BrowserThreadImpl::Init();
[email protected]3a7b66d2012-04-26 16:34:1638
39 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
40 // Though this thread is called the "IO" thread, it actually just routes
41 // messages around; it shouldn't be allowed to perform any blocking disk
42 // I/O.
43 base::ThreadRestrictions::SetIOAllowed(false);
44 base::ThreadRestrictions::DisallowWaiting();
45 }
[email protected]0ac83682010-01-22 17:46:2746}
47
[email protected]569c7602011-03-03 20:40:3248void BrowserProcessSubThread::CleanUp() {
[email protected]af669932012-01-17 19:26:5849 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
50 IOThreadPreCleanUp();
51
[email protected]2e5b60a22011-11-28 15:56:4152 BrowserThreadImpl::CleanUp();
53
[email protected]435756b2012-10-01 21:19:3654 notification_service_.reset();
[email protected]0ac83682010-01-22 17:46:2755
56#if defined(OS_WIN)
57 // Closes the COM library on the current thread. CoInitialize must
58 // be balanced by a corresponding call to CoUninitialize.
59 CoUninitialize();
60#endif
61}
[email protected]c38831a12011-10-28 12:44:4962
[email protected]af669932012-01-17 19:26:5863void BrowserProcessSubThread::IOThreadPreCleanUp() {
64 // Kill all things that might be holding onto
65 // net::URLRequest/net::URLRequestContexts.
66
67 // Destroy all URLRequests started by URLFetchers.
[email protected]3dc1bc42012-06-19 08:20:5368 net::URLFetcher::CancelAll();
[email protected]af669932012-01-17 19:26:5869
[email protected]af669932012-01-17 19:26:5870 // If any child processes are still running, terminate them and
71 // and delete the BrowserChildProcessHost instances to release whatever
72 // IO thread only resources they are referencing.
[email protected]4c01d4992012-01-23 23:33:0173 BrowserChildProcessHostImpl::TerminateAll();
[email protected]af669932012-01-17 19:26:5874}
75
[email protected]c38831a12011-10-28 12:44:4976} // namespace content