[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 5 | #include "content/browser/browser_process_sub_thread.h" |
6 | |||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 7 | #if defined(OS_WIN) |
8 | #include <Objbase.h> | ||||
9 | #endif | ||||
10 | |||||
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 11 | #include "base/debug/leak_tracker.h" |
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame^] | 12 | #include "base/threading/thread_restrictions.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 4c01d499 | 2012-01-23 23:33:01 | [diff] [blame] | 14 | #include "content/browser/browser_child_process_host_impl.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 15 | #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] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 20 | namespace content { |
21 | |||||
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 22 | BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) |
[email protected] | 5abe630 | 2011-12-20 23:44:32 | [diff] [blame] | 23 | : BrowserThreadImpl(identifier), |
24 | notification_service_(NULL) { | ||||
25 | } | ||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 26 | |
27 | BrowserProcessSubThread::~BrowserProcessSubThread() { | ||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 28 | Stop(); |
29 | } | ||||
30 | |||||
31 | void BrowserProcessSubThread::Init() { | ||||
32 | #if defined(OS_WIN) | ||||
33 | // Initializes the COM library on the current thread. | ||||
34 | CoInitialize(NULL); | ||||
35 | #endif | ||||
36 | |||||
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 37 | notification_service_ = new NotificationServiceImpl; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 38 | |
39 | BrowserThreadImpl::Init(); | ||||
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame^] | 40 | |
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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | 569c760 | 2011-03-03 20:40:32 | [diff] [blame] | 50 | void BrowserProcessSubThread::CleanUp() { |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 51 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
52 | IOThreadPreCleanUp(); | ||||
53 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 54 | BrowserThreadImpl::CleanUp(); |
55 | |||||
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 56 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
57 | IOThreadPostCleanUp(); | ||||
58 | |||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 59 | 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] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 68 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 69 | void 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] | 4c01d499 | 2012-01-23 23:33:01 | [diff] [blame] | 81 | BrowserChildProcessHostImpl::TerminateAll(); |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 82 | } |
83 | |||||
84 | void BrowserProcessSubThread::IOThreadPostCleanUp() { | ||||
85 | // net::URLRequest instances must NOT outlive the IO thread. | ||||
86 | base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); | ||||
87 | } | ||||
88 | |||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 89 | } // namespace content |