OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_process_sub_thread.h" | 5 #include "content/browser/browser_process_sub_thread.h" |
6 | 6 |
7 #if defined(OS_WIN) | |
8 #include <Objbase.h> | |
9 #endif | |
10 | |
11 #include "base/debug/leak_tracker.h" | 7 #include "base/debug/leak_tracker.h" |
12 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
13 #include "build/build_config.h" | 9 #include "build/build_config.h" |
14 #include "content/browser/browser_child_process_host_impl.h" | 10 #include "content/browser/browser_child_process_host_impl.h" |
15 #include "content/browser/notification_service_impl.h" | 11 #include "content/browser/notification_service_impl.h" |
16 #include "net/url_request/url_fetcher.h" | 12 #include "net/url_request/url_fetcher.h" |
17 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
18 | 14 |
| 15 #if defined(OS_WIN) |
| 16 #include "base/win/scoped_com_initializer.h" |
| 17 #endif |
| 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) | 21 BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) |
22 : BrowserThreadImpl(identifier) { | 22 : BrowserThreadImpl(identifier) { |
23 } | 23 } |
24 | 24 |
25 BrowserProcessSubThread::~BrowserProcessSubThread() { | 25 BrowserProcessSubThread::~BrowserProcessSubThread() { |
26 Stop(); | 26 Stop(); |
27 } | 27 } |
28 | 28 |
29 void BrowserProcessSubThread::Init() { | 29 void BrowserProcessSubThread::Init() { |
30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
31 // Initializes the COM library on the current thread. | 31 com_initializer_.reset(new base::win::ScopedCOMInitializer()); |
32 CoInitialize(NULL); | |
33 #endif | 32 #endif |
34 | 33 |
35 notification_service_.reset(new NotificationServiceImpl()); | 34 notification_service_.reset(new NotificationServiceImpl()); |
36 | 35 |
37 BrowserThreadImpl::Init(); | 36 BrowserThreadImpl::Init(); |
38 | 37 |
39 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 38 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
40 // Though this thread is called the "IO" thread, it actually just routes | 39 // 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 | 40 // messages around; it shouldn't be allowed to perform any blocking disk |
42 // I/O. | 41 // I/O. |
43 base::ThreadRestrictions::SetIOAllowed(false); | 42 base::ThreadRestrictions::SetIOAllowed(false); |
44 base::ThreadRestrictions::DisallowWaiting(); | 43 base::ThreadRestrictions::DisallowWaiting(); |
45 } | 44 } |
46 } | 45 } |
47 | 46 |
48 void BrowserProcessSubThread::CleanUp() { | 47 void BrowserProcessSubThread::CleanUp() { |
49 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) | 48 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
50 IOThreadPreCleanUp(); | 49 IOThreadPreCleanUp(); |
51 | 50 |
52 BrowserThreadImpl::CleanUp(); | 51 BrowserThreadImpl::CleanUp(); |
53 | 52 |
54 notification_service_.reset(); | 53 notification_service_.reset(); |
55 | 54 |
56 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
57 // Closes the COM library on the current thread. CoInitialize must | 56 com_initializer_.reset(); |
58 // be balanced by a corresponding call to CoUninitialize. | |
59 CoUninitialize(); | |
60 #endif | 57 #endif |
61 } | 58 } |
62 | 59 |
63 void BrowserProcessSubThread::IOThreadPreCleanUp() { | 60 void BrowserProcessSubThread::IOThreadPreCleanUp() { |
64 // Kill all things that might be holding onto | 61 // Kill all things that might be holding onto |
65 // net::URLRequest/net::URLRequestContexts. | 62 // net::URLRequest/net::URLRequestContexts. |
66 | 63 |
67 // Destroy all URLRequests started by URLFetchers. | 64 // Destroy all URLRequests started by URLFetchers. |
68 net::URLFetcher::CancelAll(); | 65 net::URLFetcher::CancelAll(); |
69 | 66 |
70 // If any child processes are still running, terminate them and | 67 // If any child processes are still running, terminate them and |
71 // and delete the BrowserChildProcessHost instances to release whatever | 68 // and delete the BrowserChildProcessHost instances to release whatever |
72 // IO thread only resources they are referencing. | 69 // IO thread only resources they are referencing. |
73 BrowserChildProcessHostImpl::TerminateAll(); | 70 BrowserChildProcessHostImpl::TerminateAll(); |
74 } | 71 } |
75 | 72 |
76 } // namespace content | 73 } // namespace content |
OLD | NEW |