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

Side by Side Diff: content/utility/utility_thread_impl.cc

Issue 18119009: Make utility process run in-process when running in single-process mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: undo unnecessary changes Created 7 years, 5 months 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
« no previous file with comments | « content/utility/utility_thread_impl.h ('k') | ipc/ipc_channel_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/utility/utility_thread_impl.h" 5 #include "content/utility/utility_thread_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "content/child/child_process.h" 12 #include "content/child/child_process.h"
13 #include "content/child/webkitplatformsupport_impl.h" 13 #include "content/child/webkitplatformsupport_impl.h"
14 #include "content/common/child_process_messages.h" 14 #include "content/common/child_process_messages.h"
15 #include "content/common/utility_messages.h" 15 #include "content/common/utility_messages.h"
16 #include "content/public/common/content_switches.h"
16 #include "content/public/utility/content_utility_client.h" 17 #include "content/public/utility/content_utility_client.h"
18 #include "ipc/ipc_sync_channel.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 19 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "webkit/plugins/npapi/plugin_list.h" 20 #include "webkit/plugins/npapi/plugin_list.h"
19 21
20 #if defined(TOOLKIT_GTK) 22 #if defined(TOOLKIT_GTK)
21 #include <gtk/gtk.h> 23 #include <gtk/gtk.h>
22 24
23 #include "ui/gfx/gtk_util.h" 25 #include "ui/gfx/gtk_util.h"
24 #endif 26 #endif
25 27
26 namespace content { 28 namespace content {
27 29
28 namespace { 30 namespace {
29 31
30 template<typename SRC, typename DEST> 32 template<typename SRC, typename DEST>
31 void ConvertVector(const SRC& src, DEST* dest) { 33 void ConvertVector(const SRC& src, DEST* dest) {
32 dest->reserve(src.size()); 34 dest->reserve(src.size());
33 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) 35 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
34 dest->push_back(typename DEST::value_type(*i)); 36 dest->push_back(typename DEST::value_type(*i));
35 } 37 }
36 38
37 } // namespace 39 } // namespace
38 40
39 UtilityThreadImpl::UtilityThreadImpl() 41 UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
40 : batch_mode_(false) { 42 Init();
41 ChildProcess::current()->AddRefProcess(); 43 }
42 webkit_platform_support_.reset(new WebKitPlatformSupportImpl); 44
43 WebKit::initialize(webkit_platform_support_.get()); 45 UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
44 GetContentClient()->utility()->UtilityThreadStarted(); 46 : ChildThread(channel_name),
47 single_process_(true) {
48 Init();
45 } 49 }
46 50
47 UtilityThreadImpl::~UtilityThreadImpl() { 51 UtilityThreadImpl::~UtilityThreadImpl() {
48 } 52 }
49 53
50 void UtilityThreadImpl::Shutdown() { 54 void UtilityThreadImpl::Shutdown() {
51 WebKit::shutdown(); 55 if (!single_process_)
56 WebKit::shutdown();
52 } 57 }
53 58
54 bool UtilityThreadImpl::Send(IPC::Message* msg) { 59 bool UtilityThreadImpl::Send(IPC::Message* msg) {
55 return ChildThread::Send(msg); 60 return ChildThread::Send(msg);
56 } 61 }
57 62
58 void UtilityThreadImpl::ReleaseProcessIfNeeded() { 63 void UtilityThreadImpl::ReleaseProcessIfNeeded() {
59 if (!batch_mode_) 64 if (batch_mode_)
65 return;
66
67 if (single_process_) {
68 // Just quit the message loop directly so that unit tests don't need to
69 // pump the client message loop again. In normal multi-process mode, need
70 // normal shutdown as the IO thread could still be sending the result IPC.
71 // Also close the IPC channel manually as normally that's done by the child
72 // process exiting, which doesn't happen here.
73 channel()->Close();
74 base::MessageLoop::current()->Quit();
75 } else {
60 ChildProcess::current()->ReleaseProcess(); 76 ChildProcess::current()->ReleaseProcess();
77 }
61 } 78 }
62 79
63 #if defined(OS_WIN) 80 #if defined(OS_WIN)
64 81
65 void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) { 82 void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) {
66 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); 83 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
67 } 84 }
68 85
69 void UtilityThreadImpl::ReleaseCachedFonts() { 86 void UtilityThreadImpl::ReleaseCachedFonts() {
70 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); 87 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
71 } 88 }
72 89
73 #endif // OS_WIN 90 #endif // OS_WIN
74 91
92 void UtilityThreadImpl::Init() {
93 batch_mode_ = false;
94 ChildProcess::current()->AddRefProcess();
95 if (!single_process_) {
96 // We can only initialize WebKit on one thread, and in single process mode
97 // we run the utility thread on separate thread. This means that if any code
98 // needs WebKit initialized in the utility process, they need to have
99 // another path to support single process mode.
100 webkit_platform_support_.reset(new WebKitPlatformSupportImpl);
101 WebKit::initialize(webkit_platform_support_.get());
102 }
103 GetContentClient()->utility()->UtilityThreadStarted();
104 }
75 105
76 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { 106 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
77 if (GetContentClient()->utility()->OnMessageReceived(msg)) 107 if (GetContentClient()->utility()->OnMessageReceived(msg))
78 return true; 108 return true;
79 109
80 bool handled = true; 110 bool handled = true;
81 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg) 111 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg)
82 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted) 112 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
83 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished) 113 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
84 #if defined(OS_POSIX) 114 #if defined(OS_POSIX)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i])); 157 Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i]));
128 else 158 else
129 Send(new UtilityHostMsg_LoadedPlugin(i, plugin)); 159 Send(new UtilityHostMsg_LoadedPlugin(i, plugin));
130 } 160 }
131 161
132 ReleaseProcessIfNeeded(); 162 ReleaseProcessIfNeeded();
133 } 163 }
134 #endif 164 #endif
135 165
136 } // namespace content 166 } // namespace content
OLDNEW
« no previous file with comments | « content/utility/utility_thread_impl.h ('k') | ipc/ipc_channel_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698