Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: content/shell/shell_browser_main.cc

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Temporary - look at browser_list, browser_main_loop, content/p/b/browser_shutdown Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 12 matching lines...) Expand all
23 ShellBrowserMainParts::ShellBrowserMainParts( 23 ShellBrowserMainParts::ShellBrowserMainParts(
24 const content::MainFunctionParams& parameters) 24 const content::MainFunctionParams& parameters)
25 : BrowserMainParts() { 25 : BrowserMainParts() {
26 ShellContentBrowserClient* shell_browser_client = 26 ShellContentBrowserClient* shell_browser_client =
27 static_cast<ShellContentBrowserClient*>( 27 static_cast<ShellContentBrowserClient*>(
28 content::GetContentClient()->browser()); 28 content::GetContentClient()->browser());
29 shell_browser_client->set_shell_browser_main_parts(this); 29 shell_browser_client->set_shell_browser_main_parts(this);
30 } 30 }
31 31
32 ShellBrowserMainParts::~ShellBrowserMainParts() { 32 ShellBrowserMainParts::~ShellBrowserMainParts() {
33 base::ThreadRestrictions::SetIOAllowed(true);
34 io_thread()->message_loop()->PostTask(
35 FROM_HERE, base::IgnoreReturn<bool>(
36 base::Bind(&base::ThreadRestrictions::SetIOAllowed, true)));
37
38 browser_context_.reset();
39
40 resource_dispatcher_host_->download_file_manager()->Shutdown();
41 resource_dispatcher_host_->save_file_manager()->Shutdown();
42 resource_dispatcher_host_->Shutdown();
43 io_thread_.reset();
44 cache_thread_.reset();
45 process_launcher_thread_.reset();
46 file_thread_.reset();
47 resource_dispatcher_host_.reset(); // Kills WebKit thread.
48 db_thread_.reset();
49 } 33 }
50 34
51 void ShellBrowserMainParts::PreMainMessageLoopRun() { 35 void ShellBrowserMainParts::PreMainMessageLoopRun() {
52 db_thread_.reset(new BrowserProcessSubThread(BrowserThread::DB));
53 db_thread_->Start();
54 file_thread_.reset(new BrowserProcessSubThread(BrowserThread::FILE));
55 file_thread_->Start();
56 process_launcher_thread_.reset(
57 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
58 process_launcher_thread_->Start();
59
60 base::Thread::Options options;
61 options.message_loop_type = MessageLoop::TYPE_IO;
62
63 cache_thread_.reset(new BrowserProcessSubThread(BrowserThread::CACHE));
64 cache_thread_->StartWithOptions(options);
65 io_thread_.reset(new BrowserProcessSubThread(BrowserThread::IO));
66 io_thread_->StartWithOptions(options);
67
68 browser_context_.reset(new ShellBrowserContext(this)); 36 browser_context_.reset(new ShellBrowserContext(this));
69 37
70 Shell::PlatformInitialize(); 38 Shell::PlatformInitialize();
71 net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); 39 net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider);
72 40
73 Shell::CreateNewWindow(browser_context_.get(), 41 Shell::CreateNewWindow(browser_context_.get(),
74 GURL("http://www.google.com"), 42 GURL("http://www.google.com"),
75 NULL, 43 NULL,
76 MSG_ROUTING_NONE, 44 MSG_ROUTING_NONE,
77 NULL); 45 NULL);
46 }
78 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 }
79 } 62 }
80 63
81 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { 64 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
82 return false; 65 return false;
83 } 66 }
84 67
85 ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() { 68 ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() {
86 if (!resource_dispatcher_host_.get()) { 69 if (!resource_dispatcher_host_.get()) {
87 ResourceQueue::DelegateSet resource_queue_delegates; 70 ResourceQueue::DelegateSet resource_queue_delegates;
88 resource_dispatcher_host_.reset( 71 resource_dispatcher_host_.reset(
89 new ResourceDispatcherHost(resource_queue_delegates)); 72 new ResourceDispatcherHost(resource_queue_delegates));
90 resource_dispatcher_host_->Initialize(); 73 resource_dispatcher_host_->Initialize();
91 } 74 }
92 return resource_dispatcher_host_.get(); 75 return resource_dispatcher_host_.get();
93 } 76 }
94 77
95 ui::Clipboard* ShellBrowserMainParts::GetClipboard() { 78 ui::Clipboard* ShellBrowserMainParts::GetClipboard() {
96 if (!clipboard_.get()) 79 if (!clipboard_.get())
97 clipboard_.reset(new ui::Clipboard()); 80 clipboard_.reset(new ui::Clipboard());
98 return clipboard_.get(); 81 return clipboard_.get();
99 } 82 }
100 83
101 } // namespace 84 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698