blob: c521af2deac40897b5b24757d39633439f778e61 [file] [log] [blame]
[email protected]f20d7332011-03-08 21:11:531// Copyright (c) 2011 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/in_process_webkit/indexed_db_key_utility_client.h"
16#include "content/browser/notification_service_impl.h"
17#include "content/public/common/url_fetcher.h"
18#include "net/url_request/url_request.h"
19
[email protected]c38831a12011-10-28 12:44:4920namespace content {
21
[email protected]d04e7662010-10-10 22:24:4822BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier)
[email protected]5abe6302011-12-20 23:44:3223 : BrowserThreadImpl(identifier),
24 notification_service_(NULL) {
25}
[email protected]0ac83682010-01-22 17:46:2726
27BrowserProcessSubThread::~BrowserProcessSubThread() {
[email protected]0ac83682010-01-22 17:46:2728 Stop();
29}
30
31void BrowserProcessSubThread::Init() {
32#if defined(OS_WIN)
33 // Initializes the COM library on the current thread.
34 CoInitialize(NULL);
35#endif
36
[email protected]ad50def52011-10-19 23:17:0737 notification_service_ = new NotificationServiceImpl;
[email protected]2e5b60a22011-11-28 15:56:4138
39 BrowserThreadImpl::Init();
[email protected]3a7b66d2012-04-26 16:34:1640
41 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
42 // Though this thread is called the "IO" thread, it actually just routes
43 // messages around; it shouldn't be allowed to perform any blocking disk
44 // I/O.
45 base::ThreadRestrictions::SetIOAllowed(false);
46 base::ThreadRestrictions::DisallowWaiting();
47 }
[email protected]0ac83682010-01-22 17:46:2748}
49
[email protected]569c7602011-03-03 20:40:3250void BrowserProcessSubThread::CleanUp() {
[email protected]af669932012-01-17 19:26:5851 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
52 IOThreadPreCleanUp();
53
[email protected]2e5b60a22011-11-28 15:56:4154 BrowserThreadImpl::CleanUp();
55
[email protected]af669932012-01-17 19:26:5856 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
57 IOThreadPostCleanUp();
58
[email protected]0ac83682010-01-22 17:46:2759 delete notification_service_;
60 notification_service_ = NULL;
61
62#if defined(OS_WIN)
63 // Closes the COM library on the current thread. CoInitialize must
64 // be balanced by a corresponding call to CoUninitialize.
65 CoUninitialize();
66#endif
67}
[email protected]c38831a12011-10-28 12:44:4968
[email protected]af669932012-01-17 19:26:5869void BrowserProcessSubThread::IOThreadPreCleanUp() {
70 // Kill all things that might be holding onto
71 // net::URLRequest/net::URLRequestContexts.
72
73 // Destroy all URLRequests started by URLFetchers.
74 content::URLFetcher::CancelAll();
75
76 IndexedDBKeyUtilityClient::Shutdown();
77
78 // If any child processes are still running, terminate them and
79 // and delete the BrowserChildProcessHost instances to release whatever
80 // IO thread only resources they are referencing.
[email protected]4c01d4992012-01-23 23:33:0181 BrowserChildProcessHostImpl::TerminateAll();
[email protected]af669932012-01-17 19:26:5882}
83
84void BrowserProcessSubThread::IOThreadPostCleanUp() {
85 // net::URLRequest instances must NOT outlive the IO thread.
86 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
87}
88
[email protected]c38831a12011-10-28 12:44:4989} // namespace content