| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shell/shell_browser_main.h" | 5 #include "content/shell/shell_browser_main.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "content/browser/browser_process_sub_thread.h" | 10 #include "content/browser/browser_process_sub_thread.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 ShellBrowserMainParts::ShellBrowserMainParts( | 22 ShellBrowserMainParts::ShellBrowserMainParts( |
| 23 const content::MainFunctionParams& parameters) | 23 const content::MainFunctionParams& parameters) |
| 24 : BrowserMainParts() { | 24 : BrowserMainParts() { |
| 25 ShellContentBrowserClient* shell_browser_client = | 25 ShellContentBrowserClient* shell_browser_client = |
| 26 static_cast<ShellContentBrowserClient*>( | 26 static_cast<ShellContentBrowserClient*>( |
| 27 content::GetContentClient()->browser()); | 27 content::GetContentClient()->browser()); |
| 28 shell_browser_client->set_shell_browser_main_parts(this); | 28 shell_browser_client->set_shell_browser_main_parts(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 ShellBrowserMainParts::~ShellBrowserMainParts() { | 31 ShellBrowserMainParts::~ShellBrowserMainParts() { |
| 32 base::ThreadRestrictions::SetIOAllowed(true); | |
| 33 io_thread()->message_loop()->PostTask( | |
| 34 FROM_HERE, | |
| 35 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true)); | |
| 36 | |
| 37 browser_context_.reset(); | |
| 38 | |
| 39 resource_dispatcher_host_->download_file_manager()->Shutdown(); | |
| 40 resource_dispatcher_host_->save_file_manager()->Shutdown(); | |
| 41 resource_dispatcher_host_->Shutdown(); | |
| 42 io_thread_.reset(); | |
| 43 cache_thread_.reset(); | |
| 44 process_launcher_thread_.reset(); | |
| 45 file_thread_.reset(); | |
| 46 resource_dispatcher_host_.reset(); // Kills WebKit thread. | |
| 47 db_thread_.reset(); | |
| 48 } | 32 } |
| 49 | 33 |
| 50 void ShellBrowserMainParts::PreMainMessageLoopRun() { | 34 content::IOThreadDelegate* ShellBrowserMainParts::PreMainMessageLoopRun() { |
| 51 db_thread_.reset(new BrowserProcessSubThread(BrowserThread::DB)); | |
| 52 db_thread_->Start(); | |
| 53 file_thread_.reset(new BrowserProcessSubThread(BrowserThread::FILE)); | |
| 54 file_thread_->Start(); | |
| 55 process_launcher_thread_.reset( | |
| 56 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER)); | |
| 57 process_launcher_thread_->Start(); | |
| 58 | |
| 59 base::Thread::Options options; | |
| 60 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 61 | |
| 62 cache_thread_.reset(new BrowserProcessSubThread(BrowserThread::CACHE)); | |
| 63 cache_thread_->StartWithOptions(options); | |
| 64 io_thread_.reset(new BrowserProcessSubThread(BrowserThread::IO)); | |
| 65 io_thread_->StartWithOptions(options); | |
| 66 | |
| 67 browser_context_.reset(new ShellBrowserContext(this)); | 35 browser_context_.reset(new ShellBrowserContext(this)); |
| 68 | 36 |
| 69 Shell::PlatformInitialize(); | 37 Shell::PlatformInitialize(); |
| 70 net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); | 38 net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); |
| 71 | 39 |
| 72 Shell::CreateNewWindow(browser_context_.get(), | 40 Shell::CreateNewWindow(browser_context_.get(), |
| 73 GURL("http://www.google.com"), | 41 GURL("http://www.google.com"), |
| 74 NULL, | 42 NULL, |
| 75 MSG_ROUTING_NONE, | 43 MSG_ROUTING_NONE, |
| 76 NULL); | 44 NULL); |
| 45 return NULL; |
| 46 } |
| 77 | 47 |
| 48 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
| 49 browser_context_.reset(); |
| 50 |
| 51 resource_dispatcher_host_->download_file_manager()->Shutdown(); |
| 52 resource_dispatcher_host_->save_file_manager()->Shutdown(); |
| 53 resource_dispatcher_host_->Shutdown(); |
| 54 } |
| 55 |
| 56 void ShellBrowserMainParts::PreStopThread(BrowserThread::ID id) { |
| 57 if (id == BrowserThread::WEBKIT) { |
| 58 // It remains the embedder's responsibility to kill the WebKit |
| 59 // thread. This happens when RDH is destroyed. |
| 60 resource_dispatcher_host_.reset(); |
| 61 } |
| 78 } | 62 } |
| 79 | 63 |
| 80 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 64 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 81 return false; | 65 return false; |
| 82 } | 66 } |
| 83 | 67 |
| 84 ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() { | 68 ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() { |
| 85 if (!resource_dispatcher_host_.get()) { | 69 if (!resource_dispatcher_host_.get()) { |
| 86 ResourceQueue::DelegateSet resource_queue_delegates; | 70 ResourceQueue::DelegateSet resource_queue_delegates; |
| 87 resource_dispatcher_host_.reset( | 71 resource_dispatcher_host_.reset( |
| 88 new ResourceDispatcherHost(resource_queue_delegates)); | 72 new ResourceDispatcherHost(resource_queue_delegates)); |
| 89 resource_dispatcher_host_->Initialize(); | 73 resource_dispatcher_host_->Initialize(); |
| 90 } | 74 } |
| 91 return resource_dispatcher_host_.get(); | 75 return resource_dispatcher_host_.get(); |
| 92 } | 76 } |
| 93 | 77 |
| 94 ui::Clipboard* ShellBrowserMainParts::GetClipboard() { | 78 ui::Clipboard* ShellBrowserMainParts::GetClipboard() { |
| 95 if (!clipboard_.get()) | 79 if (!clipboard_.get()) |
| 96 clipboard_.reset(new ui::Clipboard()); | 80 clipboard_.reset(new ui::Clipboard()); |
| 97 return clipboard_.get(); | 81 return clipboard_.get(); |
| 98 } | 82 } |
| 99 | 83 |
| 100 } // namespace | 84 } // namespace |
| OLD | NEW |