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

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: Mojoify PoweMonitorMessageBroadcaster IPC from browser to child process Created 4 years, 2 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/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"
(...skipping 25 matching lines...) Expand all
36 #include "content/public/browser/browser_child_process_host_delegate.h" 36 #include "content/public/browser/browser_child_process_host_delegate.h"
37 #include "content/public/browser/browser_child_process_observer.h" 37 #include "content/public/browser/browser_child_process_observer.h"
38 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/child_process_data.h" 39 #include "content/public/browser/child_process_data.h"
40 #include "content/public/browser/content_browser_client.h" 40 #include "content/public/browser/content_browser_client.h"
41 #include "content/public/common/content_features.h" 41 #include "content/public/common/content_features.h"
42 #include "content/public/common/content_switches.h" 42 #include "content/public/common/content_switches.h"
43 #include "content/public/common/mojo_channel_switches.h" 43 #include "content/public/common/mojo_channel_switches.h"
44 #include "content/public/common/process_type.h" 44 #include "content/public/common/process_type.h"
45 #include "content/public/common/result_codes.h" 45 #include "content/public/common/result_codes.h"
46 #include "device/power_monitor/public/interfaces/power_monitor.mojom.h"
46 #include "ipc/attachment_broker.h" 47 #include "ipc/attachment_broker.h"
47 #include "ipc/attachment_broker_privileged.h" 48 #include "ipc/attachment_broker_privileged.h"
48 #include "mojo/edk/embedder/embedder.h" 49 #include "mojo/edk/embedder/embedder.h"
49 50
50 #if defined(OS_MACOSX) 51 #if defined(OS_MACOSX)
51 #include "content/browser/mach_broker_mac.h" 52 #include "content/browser/mach_broker_mac.h"
52 #endif 53 #endif
53 54
54 namespace content { 55 namespace content {
55 namespace { 56 namespace {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 g_observers.Get().RemoveObserver(observer); 138 g_observers.Get().RemoveObserver(observer);
138 } 139 }
139 140
140 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( 141 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
141 content::ProcessType process_type, 142 content::ProcessType process_type,
142 BrowserChildProcessHostDelegate* delegate, 143 BrowserChildProcessHostDelegate* delegate,
143 const std::string& service_name) 144 const std::string& service_name)
144 : data_(process_type), 145 : data_(process_type),
145 delegate_(delegate), 146 delegate_(delegate),
146 child_token_(mojo::edk::GenerateRandomToken()), 147 child_token_(mojo::edk::GenerateRandomToken()),
147 power_monitor_message_broadcaster_(this),
148 is_channel_connected_(false), 148 is_channel_connected_(false),
149 notify_child_disconnected_(false), 149 notify_child_disconnected_(false),
150 weak_factory_(this) { 150 weak_factory_(this) {
151 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); 151 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
152 152
153 #if USE_ATTACHMENT_BROKER 153 #if USE_ATTACHMENT_BROKER
154 // Construct the privileged attachment broker early in the life cycle of a 154 // 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 155 // 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 156 // single process modes, the global attachment broker is the privileged
157 // attachment broker, rather than an unprivileged attachment broker. 157 // attachment broker, rather than an unprivileged attachment broker.
158 #if defined(OS_MACOSX) 158 #if defined(OS_MACOSX)
159 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( 159 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(
160 MachBroker::GetInstance()); 160 MachBroker::GetInstance());
161 #else 161 #else
162 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); 162 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
163 #endif // defined(OS_MACOSX) 163 #endif // defined(OS_MACOSX)
164 #endif // USE_ATTACHMENT_BROKER 164 #endif // USE_ATTACHMENT_BROKER
165 165
166 child_process_host_.reset(ChildProcessHost::Create(this)); 166 child_process_host_.reset(ChildProcessHost::Create(this));
167 AddFilter(new TraceMessageFilter(data_.id)); 167 AddFilter(new TraceMessageFilter(data_.id));
168 AddFilter(new ProfilerMessageFilter(process_type)); 168 AddFilter(new ProfilerMessageFilter(process_type));
169 AddFilter(new HistogramMessageFilter); 169 AddFilter(new HistogramMessageFilter);
170 AddFilter(new MemoryMessageFilter(this, process_type)); 170 AddFilter(new MemoryMessageFilter(this, process_type));
171 171
172 g_child_process_list.Get().push_back(this); 172 g_child_process_list.Get().push_back(this);
173 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); 173 GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
174 174
175 power_monitor_message_broadcaster_.Init();
176
177 if (!service_name.empty()) { 175 if (!service_name.empty()) {
178 DCHECK_CURRENTLY_ON(BrowserThread::IO); 176 DCHECK_CURRENTLY_ON(BrowserThread::IO);
179 child_connection_.reset(new ChildConnection( 177 child_connection_.reset(new ChildConnection(
180 service_name, base::StringPrintf("%d", data_.id), child_token_, 178 service_name, base::StringPrintf("%d", data_.id), child_token_,
181 ServiceManagerContext::GetConnectorForIOThread(), 179 ServiceManagerContext::GetConnectorForIOThread(),
182 base::ThreadTaskRunnerHandle::Get())); 180 base::ThreadTaskRunnerHandle::Get()));
183 } 181 }
184 182
183 device::mojom::PowerMonitorClientPtr power_monitor_client;
184 GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&power_monitor_client));
185 power_monitor_message_broadcaster_.Init(power_monitor_client);
186
185 // Create a persistent memory segment for subprocess histograms. 187 // Create a persistent memory segment for subprocess histograms.
186 CreateMetricsAllocator(); 188 CreateMetricsAllocator();
187 } 189 }
188 190
189 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { 191 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
190 g_child_process_list.Get().remove(this); 192 g_child_process_list.Get().remove(this);
191 193
192 if (notify_child_disconnected_) { 194 if (notify_child_disconnected_) {
193 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 195 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
194 base::Bind(&NotifyProcessHostDisconnected, data_)); 196 base::Bind(&NotifyProcessHostDisconnected, data_));
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 600
599 #if defined(OS_WIN) 601 #if defined(OS_WIN)
600 602
601 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { 603 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
602 OnChildDisconnected(); 604 OnChildDisconnected();
603 } 605 }
604 606
605 #endif 607 #endif
606 608
607 } // namespace content 609 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698