[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 1 | // Copyright (c) 2012 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/notification_service_impl.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 16 | #include "net/url_request/url_fetcher.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 17 | #include "net/url_request/url_request.h" |
18 | |||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 19 | namespace content { |
20 | |||||
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 21 | BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) |
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame^] | 22 | : BrowserThreadImpl(identifier) { |
[email protected] | 5abe630 | 2011-12-20 23:44:32 | [diff] [blame] | 23 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 24 | |
25 | BrowserProcessSubThread::~BrowserProcessSubThread() { | ||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 26 | Stop(); |
27 | } | ||||
28 | |||||
29 | void BrowserProcessSubThread::Init() { | ||||
30 | #if defined(OS_WIN) | ||||
31 | // Initializes the COM library on the current thread. | ||||
32 | CoInitialize(NULL); | ||||
33 | #endif | ||||
34 | |||||
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame^] | 35 | notification_service_.reset(new NotificationServiceImpl()); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 36 | |
37 | BrowserThreadImpl::Init(); | ||||
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame] | 38 | |
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] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 46 | } |
47 | |||||
[email protected] | 569c760 | 2011-03-03 20:40:32 | [diff] [blame] | 48 | void BrowserProcessSubThread::CleanUp() { |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 49 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
50 | IOThreadPreCleanUp(); | ||||
51 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 52 | BrowserThreadImpl::CleanUp(); |
53 | |||||
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame^] | 54 | notification_service_.reset(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 55 | |
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] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 62 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 63 | void 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] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 68 | net::URLFetcher::CancelAll(); |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 69 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 70 | // 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] | 4c01d499 | 2012-01-23 23:33:01 | [diff] [blame] | 73 | BrowserChildProcessHostImpl::TerminateAll(); |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 74 | } |
75 | |||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 76 | } // namespace content |