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

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

Issue 1251823002: Initialize blink only when needed in utility processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
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/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 .Build()) { 48 .Build()) {
49 Init(); 49 Init();
50 } 50 }
51 51
52 UtilityThreadImpl::~UtilityThreadImpl() { 52 UtilityThreadImpl::~UtilityThreadImpl() {
53 } 53 }
54 54
55 void UtilityThreadImpl::Shutdown() { 55 void UtilityThreadImpl::Shutdown() {
56 ChildThreadImpl::Shutdown(); 56 ChildThreadImpl::Shutdown();
57 57
58 if (!IsInBrowserProcess()) 58 if (blink_platform_impl_)
59 blink::shutdown(); 59 blink::shutdownWithoutV8();
60 } 60 }
61 61
62 void UtilityThreadImpl::ReleaseProcessIfNeeded() { 62 void UtilityThreadImpl::ReleaseProcessIfNeeded() {
63 if (batch_mode_) 63 if (batch_mode_)
64 return; 64 return;
65 65
66 if (IsInBrowserProcess()) { 66 if (IsInBrowserProcess()) {
67 // Close the channel to cause UtilityProcessHostImpl to be deleted. We need 67 // Close the channel to cause UtilityProcessHostImpl to be deleted. We need
68 // to take a different code path than the multi-process case because that 68 // to take a different code path than the multi-process case because that
69 // depends on the child process going away to close the channel, but that 69 // depends on the child process going away to close the channel, but that
70 // can't happen when we're in single process mode. 70 // can't happen when we're in single process mode.
71 channel()->Close(); 71 channel()->Close();
72 } else { 72 } else {
73 ChildProcess::current()->ReleaseProcess(); 73 ChildProcess::current()->ReleaseProcess();
74 } 74 }
75 } 75 }
76 76
77 void UtilityThreadImpl::EnsureBlinkInitialized() {
78 if (blink_platform_impl_ || IsInBrowserProcess()) {
79 // We can only initialize WebKit on one thread, and in single process mode
80 // we run the utility thread on separate thread. This means that if any code
81 // needs WebKit initialized in the utility process, they need to have
82 // another path to support single process mode.
83 return;
84 }
85
86 blink_platform_impl_.reset(new UtilityBlinkPlatformImpl);
87 blink::initializeWithoutV8(blink_platform_impl_.get());
88 }
89
77 void UtilityThreadImpl::Init() { 90 void UtilityThreadImpl::Init() {
78 batch_mode_ = false; 91 batch_mode_ = false;
79 ChildProcess::current()->AddRefProcess(); 92 ChildProcess::current()->AddRefProcess();
80 if (!IsInBrowserProcess()) {
81 // We can only initialize WebKit on one thread, and in single process mode
82 // we run the utility thread on separate thread. This means that if any code
83 // needs WebKit initialized in the utility process, they need to have
84 // another path to support single process mode.
85 blink_platform_impl_.reset(new UtilityBlinkPlatformImpl);
86 blink::initialize(blink_platform_impl_.get());
87 }
88 GetContentClient()->utility()->UtilityThreadStarted(); 93 GetContentClient()->utility()->UtilityThreadStarted();
89 94
90 process_control_.reset(new UtilityProcessControlImpl); 95 process_control_.reset(new UtilityProcessControlImpl);
91 service_registry()->AddService(base::Bind( 96 service_registry()->AddService(base::Bind(
92 &UtilityThreadImpl::BindProcessControlRequest, base::Unretained(this))); 97 &UtilityThreadImpl::BindProcessControlRequest, base::Unretained(this)));
93 98
94 GetContentClient()->utility()->RegisterMojoServices(service_registry()); 99 GetContentClient()->utility()->RegisterMojoServices(service_registry());
95 } 100 }
96 101
97 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { 102 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 146 }
142 #endif 147 #endif
143 148
144 void UtilityThreadImpl::BindProcessControlRequest( 149 void UtilityThreadImpl::BindProcessControlRequest(
145 mojo::InterfaceRequest<ProcessControl> request) { 150 mojo::InterfaceRequest<ProcessControl> request) {
146 DCHECK(process_control_); 151 DCHECK(process_control_);
147 process_control_bindings_.AddBinding(process_control_.get(), request.Pass()); 152 process_control_bindings_.AddBinding(process_control_.get(), request.Pass());
148 } 153 }
149 154
150 } // namespace content 155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698