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

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: add comment 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
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"
17 #include "third_party/WebKit/public/web/WebKit.h" 18 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "webkit/plugins/npapi/plugin_list.h" 19 #include "webkit/plugins/npapi/plugin_list.h"
19 20
20 #if defined(TOOLKIT_GTK) 21 #if defined(TOOLKIT_GTK)
21 #include <gtk/gtk.h> 22 #include <gtk/gtk.h>
22 23
23 #include "ui/gfx/gtk_util.h" 24 #include "ui/gfx/gtk_util.h"
24 #endif 25 #endif
25 26
26 namespace content { 27 namespace content {
27 28
28 namespace { 29 namespace {
29 30
30 template<typename SRC, typename DEST> 31 template<typename SRC, typename DEST>
31 void ConvertVector(const SRC& src, DEST* dest) { 32 void ConvertVector(const SRC& src, DEST* dest) {
32 dest->reserve(src.size()); 33 dest->reserve(src.size());
33 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i) 34 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
34 dest->push_back(typename DEST::value_type(*i)); 35 dest->push_back(typename DEST::value_type(*i));
35 } 36 }
36 37
37 } // namespace 38 } // namespace
38 39
39 UtilityThreadImpl::UtilityThreadImpl() 40 UtilityThreadImpl::UtilityThreadImpl() : initialize_webkit_(true) {
40 : batch_mode_(false) { 41 Init();
41 ChildProcess::current()->AddRefProcess(); 42 }
42 webkit_platform_support_.reset(new WebKitPlatformSupportImpl); 43
43 WebKit::initialize(webkit_platform_support_.get()); 44 UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
44 GetContentClient()->utility()->UtilityThreadStarted(); 45 : ChildThread(channel_name),
46 initialize_webkit_(false) {
47 Init();
45 } 48 }
46 49
47 UtilityThreadImpl::~UtilityThreadImpl() { 50 UtilityThreadImpl::~UtilityThreadImpl() {
48 } 51 }
49 52
50 void UtilityThreadImpl::Shutdown() { 53 void UtilityThreadImpl::Shutdown() {
51 WebKit::shutdown(); 54 if (initialize_webkit_)
55 WebKit::shutdown();
52 } 56 }
53 57
54 bool UtilityThreadImpl::Send(IPC::Message* msg) { 58 bool UtilityThreadImpl::Send(IPC::Message* msg) {
55 return ChildThread::Send(msg); 59 return ChildThread::Send(msg);
56 } 60 }
57 61
58 void UtilityThreadImpl::ReleaseProcessIfNeeded() { 62 void UtilityThreadImpl::ReleaseProcessIfNeeded() {
59 if (!batch_mode_) 63 if (batch_mode_)
60 ChildProcess::current()->ReleaseProcess(); 64 return;
65
66 // We don't need to call ChildProcess::current()->ReleaseProcess() here, and
67 // can just quit the message loop directly. This is because the unlike other
68 // kind of child processes, there's no race condition between killing utility
69 // processes. A side benefit is that it makes tests which use this code path
70 // easier to clean up.
71 base::MessageLoop::current()->Quit();
61 } 72 }
62 73
63 #if defined(OS_WIN) 74 #if defined(OS_WIN)
64 75
65 void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) { 76 void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) {
66 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); 77 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
67 } 78 }
68 79
69 void UtilityThreadImpl::ReleaseCachedFonts() { 80 void UtilityThreadImpl::ReleaseCachedFonts() {
70 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); 81 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
71 } 82 }
72 83
73 #endif // OS_WIN 84 #endif // OS_WIN
74 85
86 void UtilityThreadImpl::Init() {
87 batch_mode_ = false;
88 ChildProcess::current()->AddRefProcess();
89 if (initialize_webkit_) {
90 // We can only initialize WebKit on one thread, and in single process mode
91 // we run the utility thread on separate thread. This means that if any code
92 // needs WebKit initialized in the utility process, they need to have
93 // another path to support single process mode.
94 webkit_platform_support_.reset(new WebKitPlatformSupportImpl);
95 WebKit::initialize(webkit_platform_support_.get());
96 }
97 GetContentClient()->utility()->UtilityThreadStarted();
98 }
75 99
76 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { 100 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
77 if (GetContentClient()->utility()->OnMessageReceived(msg)) 101 if (GetContentClient()->utility()->OnMessageReceived(msg))
78 return true; 102 return true;
79 103
80 bool handled = true; 104 bool handled = true;
81 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg) 105 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg)
82 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted) 106 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
83 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished) 107 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
84 #if defined(OS_POSIX) 108 #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])); 151 Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i]));
128 else 152 else
129 Send(new UtilityHostMsg_LoadedPlugin(i, plugin)); 153 Send(new UtilityHostMsg_LoadedPlugin(i, plugin));
130 } 154 }
131 155
132 ReleaseProcessIfNeeded(); 156 ReleaseProcessIfNeeded();
133 } 157 }
134 #endif 158 #endif
135 159
136 } // namespace content 160 } // namespace content
OLDNEW
« content/utility/utility_thread_impl.h ('K') | « content/utility/utility_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698