[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] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 7 | #include "base/debug/leak_tracker.h" |
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame] | 8 | #include "base/threading/thread_restrictions.h" |
reveman | 84c4caf9 | 2015-05-01 20:10:22 | [diff] [blame] | 9 | #include "base/trace_event/memory_dump_manager.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 4c01d499 | 2012-01-23 23:33:01 | [diff] [blame] | 11 | #include "content/browser/browser_child_process_host_impl.h" |
reveman | 84c4caf9 | 2015-05-01 20:10:22 | [diff] [blame] | 12 | #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 13 | #include "content/browser/notification_service_impl.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 14 | #include "net/url_request/url_fetcher.h" |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 15 | #include "net/url_request/url_request.h" |
16 | |||||
[email protected] | 451fd90 | 2012-10-03 17:14:48 | [diff] [blame] | 17 | #if defined(OS_WIN) |
18 | #include "base/win/scoped_com_initializer.h" | ||||
19 | #endif | ||||
20 | |||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 21 | namespace content { |
22 | |||||
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 23 | BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) |
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame] | 24 | : BrowserThreadImpl(identifier) { |
[email protected] | 5abe630 | 2011-12-20 23:44:32 | [diff] [blame] | 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) | ||||
[email protected] | 451fd90 | 2012-10-03 17:14:48 | [diff] [blame] | 33 | com_initializer_.reset(new base::win::ScopedCOMInitializer()); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 34 | #endif |
35 | |||||
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame] | 36 | notification_service_.reset(new NotificationServiceImpl()); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 37 | |
38 | BrowserThreadImpl::Init(); | ||||
[email protected] | 3a7b66d | 2012-04-26 16:34:16 | [diff] [blame] | 39 | |
40 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | ||||
41 | // Though this thread is called the "IO" thread, it actually just routes | ||||
42 | // messages around; it shouldn't be allowed to perform any blocking disk | ||||
43 | // I/O. | ||||
44 | base::ThreadRestrictions::SetIOAllowed(false); | ||||
45 | base::ThreadRestrictions::DisallowWaiting(); | ||||
46 | } | ||||
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 47 | } |
48 | |||||
[email protected] | 569c760 | 2011-03-03 20:40:32 | [diff] [blame] | 49 | void BrowserProcessSubThread::CleanUp() { |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 50 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
51 | IOThreadPreCleanUp(); | ||||
52 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 53 | BrowserThreadImpl::CleanUp(); |
54 | |||||
[email protected] | 435756b | 2012-10-01 21:19:36 | [diff] [blame] | 55 | notification_service_.reset(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 56 | |
57 | #if defined(OS_WIN) | ||||
[email protected] | 451fd90 | 2012-10-03 17:14:48 | [diff] [blame] | 58 | com_initializer_.reset(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 59 | #endif |
60 | } | ||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 61 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 62 | void BrowserProcessSubThread::IOThreadPreCleanUp() { |
63 | // Kill all things that might be holding onto | ||||
64 | // net::URLRequest/net::URLRequestContexts. | ||||
65 | |||||
66 | // Destroy all URLRequests started by URLFetchers. | ||||
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 67 | net::URLFetcher::CancelAll(); |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 68 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 69 | // If any child processes are still running, terminate them and |
70 | // and delete the BrowserChildProcessHost instances to release whatever | ||||
71 | // IO thread only resources they are referencing. | ||||
[email protected] | 4c01d499 | 2012-01-23 23:33:01 | [diff] [blame] | 72 | BrowserChildProcessHostImpl::TerminateAll(); |
reveman | 84c4caf9 | 2015-05-01 20:10:22 | [diff] [blame] | 73 | |
74 | // Unregister GpuMemoryBuffer dump provider before IO thread is shut down. | ||||
75 | base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | ||||
76 | BrowserGpuMemoryBufferManager::current()); | ||||
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 77 | } |
78 | |||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 79 | } // namespace content |