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