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