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

Side by Side Diff: content/browser/browser_child_process_host_impl.cc

Issue 2433203003: Mojoify PoweMonitorMessageBroadcaster IPC from browser to child process (Closed)
Patch Set: code rebase Created 4 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
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/browser/browser_child_process_host_impl.h" 5 #include "content/browser/browser_child_process_host_impl.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/dump_without_crashing.h" 10 #include "base/debug/dump_without_crashing.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/metrics/persistent_histogram_allocator.h" 18 #include "base/metrics/persistent_histogram_allocator.h"
19 #include "base/metrics/persistent_memory_allocator.h" 19 #include "base/metrics/persistent_memory_allocator.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "components/tracing/common/tracing_switches.h" 26 #include "components/tracing/common/tracing_switches.h"
27 #include "content/browser/histogram_message_filter.h" 27 #include "content/browser/histogram_message_filter.h"
28 #include "content/browser/loader/resource_message_filter.h" 28 #include "content/browser/loader/resource_message_filter.h"
29 #include "content/browser/memory/memory_message_filter.h" 29 #include "content/browser/memory/memory_message_filter.h"
30 #include "content/browser/power_monitor_message_broadcaster.h"
30 #include "content/browser/profiler_message_filter.h" 31 #include "content/browser/profiler_message_filter.h"
31 #include "content/browser/service_manager/service_manager_context.h" 32 #include "content/browser/service_manager/service_manager_context.h"
32 #include "content/browser/tracing/trace_message_filter.h" 33 #include "content/browser/tracing/trace_message_filter.h"
33 #include "content/common/child_process_host_impl.h" 34 #include "content/common/child_process_host_impl.h"
34 #include "content/common/child_process_messages.h" 35 #include "content/common/child_process_messages.h"
35 #include "content/common/service_manager/child_connection.h" 36 #include "content/common/service_manager/child_connection.h"
36 #include "content/public/browser/browser_child_process_host_delegate.h" 37 #include "content/public/browser/browser_child_process_host_delegate.h"
37 #include "content/public/browser/browser_child_process_observer.h" 38 #include "content/public/browser/browser_child_process_observer.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/child_process_data.h" 40 #include "content/public/browser/child_process_data.h"
40 #include "content/public/browser/content_browser_client.h" 41 #include "content/public/browser/content_browser_client.h"
42 #include "content/public/common/connection_filter.h"
41 #include "content/public/common/content_features.h" 43 #include "content/public/common/content_features.h"
42 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
43 #include "content/public/common/mojo_channel_switches.h" 45 #include "content/public/common/mojo_channel_switches.h"
44 #include "content/public/common/process_type.h" 46 #include "content/public/common/process_type.h"
45 #include "content/public/common/result_codes.h" 47 #include "content/public/common/result_codes.h"
48 #include "content/public/common/service_manager_connection.h"
46 #include "ipc/attachment_broker.h" 49 #include "ipc/attachment_broker.h"
47 #include "ipc/attachment_broker_privileged.h" 50 #include "ipc/attachment_broker_privileged.h"
48 #include "mojo/edk/embedder/embedder.h" 51 #include "mojo/edk/embedder/embedder.h"
52 #include "services/service_manager/public/cpp/interface_registry.h"
49 53
50 #if defined(OS_MACOSX) 54 #if defined(OS_MACOSX)
51 #include "content/browser/mach_broker_mac.h" 55 #include "content/browser/mach_broker_mac.h"
52 #endif 56 #endif
53 57
54 namespace content { 58 namespace content {
55 namespace { 59 namespace {
56 60
57 static base::LazyInstance<BrowserChildProcessHostImpl::BrowserChildProcessList> 61 static base::LazyInstance<BrowserChildProcessHostImpl::BrowserChildProcessList>
58 g_child_process_list = LAZY_INSTANCE_INITIALIZER; 62 g_child_process_list = LAZY_INSTANCE_INITIALIZER;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 114 }
111 return nullptr; 115 return nullptr;
112 } 116 }
113 117
114 #if defined(OS_MACOSX) 118 #if defined(OS_MACOSX)
115 base::PortProvider* BrowserChildProcessHost::GetPortProvider() { 119 base::PortProvider* BrowserChildProcessHost::GetPortProvider() {
116 return MachBroker::GetInstance(); 120 return MachBroker::GetInstance();
117 } 121 }
118 #endif 122 #endif
119 123
124 class BrowserChildProcessHostImpl::ConnectionFilterImpl
125 : public ConnectionFilter {
126 public:
127 ConnectionFilterImpl() {}
128
129 private:
130 // ConnectionFilter:
131 bool OnConnect(const service_manager::Identity& remote_identity,
132 service_manager::InterfaceRegistry* registry,
133 service_manager::Connector* connector) override {
134 registry->AddInterface(base::Bind(&PowerMonitorMessageBroadcaster::Create));
135 return true;
136 }
137
138 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
139 };
140
120 // static 141 // static
121 BrowserChildProcessHostImpl::BrowserChildProcessList* 142 BrowserChildProcessHostImpl::BrowserChildProcessList*
122 BrowserChildProcessHostImpl::GetIterator() { 143 BrowserChildProcessHostImpl::GetIterator() {
123 return g_child_process_list.Pointer(); 144 return g_child_process_list.Pointer();
124 } 145 }
125 146
126 // static 147 // static
127 void BrowserChildProcessHostImpl::AddObserver( 148 void BrowserChildProcessHostImpl::AddObserver(
128 BrowserChildProcessObserver* observer) { 149 BrowserChildProcessObserver* observer) {
129 DCHECK_CURRENTLY_ON(BrowserThread::UI); 150 DCHECK_CURRENTLY_ON(BrowserThread::UI);
130 g_observers.Get().AddObserver(observer); 151 g_observers.Get().AddObserver(observer);
131 } 152 }
132 153
133 // static 154 // static
134 void BrowserChildProcessHostImpl::RemoveObserver( 155 void BrowserChildProcessHostImpl::RemoveObserver(
135 BrowserChildProcessObserver* observer) { 156 BrowserChildProcessObserver* observer) {
136 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. 157 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126.
137 g_observers.Get().RemoveObserver(observer); 158 g_observers.Get().RemoveObserver(observer);
138 } 159 }
139 160
140 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( 161 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
141 content::ProcessType process_type, 162 content::ProcessType process_type,
142 BrowserChildProcessHostDelegate* delegate, 163 BrowserChildProcessHostDelegate* delegate,
143 const std::string& service_name) 164 const std::string& service_name)
144 : data_(process_type), 165 : data_(process_type),
145 delegate_(delegate), 166 delegate_(delegate),
146 child_token_(mojo::edk::GenerateRandomToken()), 167 child_token_(mojo::edk::GenerateRandomToken()),
147 power_monitor_message_broadcaster_(this),
148 is_channel_connected_(false), 168 is_channel_connected_(false),
149 notify_child_disconnected_(false), 169 notify_child_disconnected_(false),
150 weak_factory_(this) { 170 weak_factory_(this) {
151 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); 171 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
152 172
153 #if USE_ATTACHMENT_BROKER 173 #if USE_ATTACHMENT_BROKER
154 // Construct the privileged attachment broker early in the life cycle of a 174 // Construct the privileged attachment broker early in the life cycle of a
155 // child process. This ensures that when a test is being run in one of the 175 // child process. This ensures that when a test is being run in one of the
156 // single process modes, the global attachment broker is the privileged 176 // single process modes, the global attachment broker is the privileged
157 // attachment broker, rather than an unprivileged attachment broker. 177 // attachment broker, rather than an unprivileged attachment broker.
158 #if defined(OS_MACOSX) 178 #if defined(OS_MACOSX)
159 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( 179 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(
160 MachBroker::GetInstance()); 180 MachBroker::GetInstance());
161 #else 181 #else
162 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); 182 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
163 #endif // defined(OS_MACOSX) 183 #endif // defined(OS_MACOSX)
164 #endif // USE_ATTACHMENT_BROKER 184 #endif // USE_ATTACHMENT_BROKER
165 185
166 child_process_host_.reset(ChildProcessHost::Create(this)); 186 child_process_host_.reset(ChildProcessHost::Create(this));
167 AddFilter(new TraceMessageFilter(data_.id)); 187 AddFilter(new TraceMessageFilter(data_.id));
168 AddFilter(new ProfilerMessageFilter(process_type)); 188 AddFilter(new ProfilerMessageFilter(process_type));
169 AddFilter(new HistogramMessageFilter); 189 AddFilter(new HistogramMessageFilter);
170 AddFilter(new MemoryMessageFilter(this, process_type)); 190 AddFilter(new MemoryMessageFilter(this, process_type));
171 191
172 g_child_process_list.Get().push_back(this); 192 g_child_process_list.Get().push_back(this);
173 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); 193 GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
174 194
175 power_monitor_message_broadcaster_.Init();
176
177 if (!service_name.empty()) { 195 if (!service_name.empty()) {
178 DCHECK_CURRENTLY_ON(BrowserThread::IO); 196 DCHECK_CURRENTLY_ON(BrowserThread::IO);
179 child_connection_.reset(new ChildConnection( 197 child_connection_.reset(new ChildConnection(
180 service_name, base::StringPrintf("%d", data_.id), child_token_, 198 service_name, base::StringPrintf("%d", data_.id), child_token_,
181 ServiceManagerContext::GetConnectorForIOThread(), 199 ServiceManagerContext::GetConnectorForIOThread(),
182 base::ThreadTaskRunnerHandle::Get())); 200 base::ThreadTaskRunnerHandle::Get()));
183 } 201 }
184 202
203 // May be null during test execution.
204 if (ServiceManagerConnection::GetForProcess()) {
205 ServiceManagerConnection::GetForProcess()->AddConnectionFilter(
206 base::MakeUnique<ConnectionFilterImpl>());
207 }
208
185 // Create a persistent memory segment for subprocess histograms. 209 // Create a persistent memory segment for subprocess histograms.
186 CreateMetricsAllocator(); 210 CreateMetricsAllocator();
187 } 211 }
188 212
189 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { 213 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
190 g_child_process_list.Get().remove(this); 214 g_child_process_list.Get().remove(this);
191 215
192 if (notify_child_disconnected_) { 216 if (notify_child_disconnected_) {
193 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 217 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
194 base::Bind(&NotifyProcessHostDisconnected, data_)); 218 base::Bind(&NotifyProcessHostDisconnected, data_));
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 622
599 #if defined(OS_WIN) 623 #if defined(OS_WIN)
600 624
601 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { 625 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
602 OnChildDisconnected(); 626 OnChildDisconnected();
603 } 627 }
604 628
605 #endif 629 #endif
606 630
607 } // namespace content 631 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698