OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/browser_process_impl.h" | 5 #include "chrome/browser/browser_process_impl.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/clipboard.h" | 8 #include "base/clipboard.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // | 51 // |
52 // Applications must initialize the COM library before they can call | 52 // Applications must initialize the COM library before they can call |
53 // COM library functions other than CoGetMalloc and memory allocation | 53 // COM library functions other than CoGetMalloc and memory allocation |
54 // functions, so this class initializes COM for those users. | 54 // functions, so this class initializes COM for those users. |
55 class BrowserProcessSubThread : public ChromeThread { | 55 class BrowserProcessSubThread : public ChromeThread { |
56 public: | 56 public: |
57 explicit BrowserProcessSubThread(ChromeThread::ID identifier) | 57 explicit BrowserProcessSubThread(ChromeThread::ID identifier) |
58 : ChromeThread(identifier) { | 58 : ChromeThread(identifier) { |
59 } | 59 } |
60 | 60 |
61 ~BrowserProcessSubThread() { | 61 virtual ~BrowserProcessSubThread() { |
62 // We cannot rely on our base class to stop the thread since we want our | 62 // We cannot rely on our base class to stop the thread since we want our |
63 // CleanUp function to run. | 63 // CleanUp function to run. |
64 Stop(); | 64 Stop(); |
65 } | 65 } |
66 | 66 |
67 protected: | 67 protected: |
68 virtual void Init() { | 68 virtual void Init() { |
69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
70 // Initializes the COM library on the current thread. | 70 // Initializes the COM library on the current thread. |
71 CoInitialize(NULL); | 71 CoInitialize(NULL); |
(...skipping 13 matching lines...) Expand all Loading... |
85 #endif | 85 #endif |
86 } | 86 } |
87 | 87 |
88 private: | 88 private: |
89 // Each specialized thread has its own notification service. | 89 // Each specialized thread has its own notification service. |
90 // Note: We don't use scoped_ptr because the destructor runs on the wrong | 90 // Note: We don't use scoped_ptr because the destructor runs on the wrong |
91 // thread. | 91 // thread. |
92 NotificationService* notification_service_; | 92 NotificationService* notification_service_; |
93 }; | 93 }; |
94 | 94 |
| 95 class IOThread : public BrowserProcessSubThread { |
| 96 public: |
| 97 IOThread() : BrowserProcessSubThread(ChromeThread::IO) {} |
| 98 |
| 99 virtual ~IOThread() { |
| 100 // We cannot rely on our base class to stop the thread since we want our |
| 101 // CleanUp function to run. |
| 102 Stop(); |
| 103 } |
| 104 |
| 105 protected: |
| 106 virtual void CleanUp() { |
| 107 // URLFetcher and URLRequest instances must NOT outlive the IO thread. |
| 108 base::LeakTracker<URLRequest>::CheckForLeaks(); |
| 109 base::LeakTracker<URLFetcher>::CheckForLeaks(); |
| 110 |
| 111 BrowserProcessSubThread::CleanUp(); |
| 112 } |
| 113 }; |
| 114 |
95 } // namespace | 115 } // namespace |
96 | 116 |
97 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) | 117 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) |
98 : created_resource_dispatcher_host_(false), | 118 : created_resource_dispatcher_host_(false), |
99 created_metrics_service_(false), | 119 created_metrics_service_(false), |
100 created_io_thread_(false), | 120 created_io_thread_(false), |
101 created_file_thread_(false), | 121 created_file_thread_(false), |
102 created_db_thread_(false), | 122 created_db_thread_(false), |
103 created_profile_manager_(false), | 123 created_profile_manager_(false), |
104 created_local_state_(false), | 124 created_local_state_(false), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 if (resource_dispatcher_host_.get()) { | 185 if (resource_dispatcher_host_.get()) { |
166 // Need to tell Safe Browsing Service that the IO thread is going away | 186 // Need to tell Safe Browsing Service that the IO thread is going away |
167 // since it cached a pointer to it. | 187 // since it cached a pointer to it. |
168 if (resource_dispatcher_host()->safe_browsing_service()) | 188 if (resource_dispatcher_host()->safe_browsing_service()) |
169 resource_dispatcher_host()->safe_browsing_service()->ShutDown(); | 189 resource_dispatcher_host()->safe_browsing_service()->ShutDown(); |
170 | 190 |
171 // Cancel pending requests and prevent new requests. | 191 // Cancel pending requests and prevent new requests. |
172 resource_dispatcher_host()->Shutdown(); | 192 resource_dispatcher_host()->Shutdown(); |
173 } | 193 } |
174 | 194 |
175 // Shutdown DNS prefetching now to ensure that network stack objects | |
176 // living on the IO thread get destroyed before the IO thread goes away. | |
177 if (io_thread_.get()) { | |
178 io_thread_->message_loop()->PostTask(FROM_HERE, | |
179 NewRunnableFunction(chrome_browser_net::EnsureDnsPrefetchShutdown)); | |
180 } | |
181 | |
182 #if defined(OS_LINUX) | 195 #if defined(OS_LINUX) |
183 // The IO thread must outlive the BACKGROUND_X11 thread. | 196 // The IO thread must outlive the BACKGROUND_X11 thread. |
184 background_x11_thread_.reset(); | 197 background_x11_thread_.reset(); |
185 #endif | 198 #endif |
186 | 199 |
187 // Need to stop io_thread_ before resource_dispatcher_host_, since | 200 // Need to stop io_thread_ before resource_dispatcher_host_, since |
188 // io_thread_ may still deref ResourceDispatcherHost and handle resource | 201 // io_thread_ may still deref ResourceDispatcherHost and handle resource |
189 // request before going away. | 202 // request before going away. |
190 io_thread_.reset(); | 203 ResetIOThread(); |
191 | 204 |
192 // Clean up state that lives on the file_thread_ before it goes away. | 205 // Clean up state that lives on the file_thread_ before it goes away. |
193 if (resource_dispatcher_host_.get()) { | 206 if (resource_dispatcher_host_.get()) { |
194 resource_dispatcher_host()->download_file_manager()->Shutdown(); | 207 resource_dispatcher_host()->download_file_manager()->Shutdown(); |
195 resource_dispatcher_host()->save_file_manager()->Shutdown(); | 208 resource_dispatcher_host()->save_file_manager()->Shutdown(); |
196 } | 209 } |
197 | 210 |
198 // Need to stop the file_thread_ here to force it to process messages in its | 211 // Need to stop the file_thread_ here to force it to process messages in its |
199 // message loop from the previous call to shutdown the DownloadFileManager, | 212 // message loop from the previous call to shutdown the DownloadFileManager, |
200 // SaveFileManager and SessionService. | 213 // SaveFileManager and SessionService. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 #if defined(OS_LINUX) | 313 #if defined(OS_LINUX) |
301 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so | 314 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so |
302 // we start it now. | 315 // we start it now. |
303 scoped_ptr<base::Thread> background_x11_thread( | 316 scoped_ptr<base::Thread> background_x11_thread( |
304 new BrowserProcessSubThread(ChromeThread::BACKGROUND_X11)); | 317 new BrowserProcessSubThread(ChromeThread::BACKGROUND_X11)); |
305 if (!background_x11_thread->Start()) | 318 if (!background_x11_thread->Start()) |
306 return; | 319 return; |
307 background_x11_thread_.swap(background_x11_thread); | 320 background_x11_thread_.swap(background_x11_thread); |
308 #endif | 321 #endif |
309 | 322 |
310 scoped_ptr<base::Thread> thread( | 323 scoped_ptr<base::Thread> thread(new IOThread); |
311 new BrowserProcessSubThread(ChromeThread::IO)); | |
312 base::Thread::Options options; | 324 base::Thread::Options options; |
313 options.message_loop_type = MessageLoop::TYPE_IO; | 325 options.message_loop_type = MessageLoop::TYPE_IO; |
314 if (!thread->StartWithOptions(options)) | 326 if (!thread->StartWithOptions(options)) |
315 return; | 327 return; |
316 io_thread_.swap(thread); | 328 io_thread_.swap(thread); |
317 } | 329 } |
318 | 330 |
| 331 void BrowserProcessImpl::ResetIOThread() { |
| 332 if (io_thread_.get()) { |
| 333 io_thread_->message_loop()->PostTask(FROM_HERE, |
| 334 NewRunnableFunction(CleanupOnIOThread)); |
| 335 } |
| 336 io_thread_.reset(); |
| 337 } |
| 338 |
| 339 // static |
| 340 void BrowserProcessImpl::CleanupOnIOThread() { |
| 341 // Shutdown DNS prefetching now to ensure that network stack objects |
| 342 // living on the IO thread get destroyed before the IO thread goes away. |
| 343 chrome_browser_net::EnsureDnsPrefetchShutdown(); |
| 344 // TODO(eroman): can this be merged into IOThread::CleanUp() ? |
| 345 } |
| 346 |
319 void BrowserProcessImpl::CreateFileThread() { | 347 void BrowserProcessImpl::CreateFileThread() { |
320 DCHECK(!created_file_thread_ && file_thread_.get() == NULL); | 348 DCHECK(!created_file_thread_ && file_thread_.get() == NULL); |
321 created_file_thread_ = true; | 349 created_file_thread_ = true; |
322 | 350 |
323 scoped_ptr<base::Thread> thread( | 351 scoped_ptr<base::Thread> thread( |
324 new BrowserProcessSubThread(ChromeThread::FILE)); | 352 new BrowserProcessSubThread(ChromeThread::FILE)); |
325 base::Thread::Options options; | 353 base::Thread::Options options; |
326 #if defined(OS_WIN) | 354 #if defined(OS_WIN) |
327 // On Windows, the FILE thread needs to be have a UI message loop which pumps | 355 // On Windows, the FILE thread needs to be have a UI message loop which pumps |
328 // messages in such a way that Google Update can communicate back to us. | 356 // messages in such a way that Google Update can communicate back to us. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 DCHECK(devtools_manager_.get() == NULL); | 415 DCHECK(devtools_manager_.get() == NULL); |
388 created_devtools_manager_ = true; | 416 created_devtools_manager_ = true; |
389 devtools_manager_ = new DevToolsManager(); | 417 devtools_manager_ = new DevToolsManager(); |
390 } | 418 } |
391 | 419 |
392 void BrowserProcessImpl::CreateGoogleURLTracker() { | 420 void BrowserProcessImpl::CreateGoogleURLTracker() { |
393 DCHECK(google_url_tracker_.get() == NULL); | 421 DCHECK(google_url_tracker_.get() == NULL); |
394 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker); | 422 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker); |
395 google_url_tracker_.swap(google_url_tracker); | 423 google_url_tracker_.swap(google_url_tracker); |
396 } | 424 } |
OLD | NEW |