OLD | NEW |
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/child/child_thread_impl.h" | 5 #include "content/child/child_thread_impl.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "content/child/notifications/notification_dispatcher.h" | 42 #include "content/child/notifications/notification_dispatcher.h" |
43 #include "content/child/power_monitor_broadcast_source.h" | 43 #include "content/child/power_monitor_broadcast_source.h" |
44 #include "content/child/push_messaging/push_dispatcher.h" | 44 #include "content/child/push_messaging/push_dispatcher.h" |
45 #include "content/child/quota_dispatcher.h" | 45 #include "content/child/quota_dispatcher.h" |
46 #include "content/child/quota_message_filter.h" | 46 #include "content/child/quota_message_filter.h" |
47 #include "content/child/resource_dispatcher.h" | 47 #include "content/child/resource_dispatcher.h" |
48 #include "content/child/service_worker/service_worker_message_filter.h" | 48 #include "content/child/service_worker/service_worker_message_filter.h" |
49 #include "content/child/thread_safe_sender.h" | 49 #include "content/child/thread_safe_sender.h" |
50 #include "content/child/websocket_dispatcher.h" | 50 #include "content/child/websocket_dispatcher.h" |
51 #include "content/common/child_process_messages.h" | 51 #include "content/common/child_process_messages.h" |
| 52 #include "content/common/mojo/channel_init.h" |
52 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
53 #include "ipc/ipc_logging.h" | 54 #include "ipc/ipc_logging.h" |
54 #include "ipc/ipc_switches.h" | 55 #include "ipc/ipc_switches.h" |
55 #include "ipc/ipc_sync_channel.h" | 56 #include "ipc/ipc_sync_channel.h" |
56 #include "ipc/ipc_sync_message_filter.h" | 57 #include "ipc/ipc_sync_message_filter.h" |
57 #include "ipc/mojo/ipc_channel_mojo.h" | 58 #include "ipc/mojo/ipc_channel_mojo.h" |
| 59 #include "ipc/mojo/scoped_ipc_support.h" |
58 | 60 |
59 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
60 #include "content/common/handle_enumerator_win.h" | 62 #include "content/common/handle_enumerator_win.h" |
61 #endif | 63 #endif |
62 | 64 |
63 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 65 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
64 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 66 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
65 #endif | 67 #endif |
66 | 68 |
67 using tracked_objects::ThreadData; | 69 using tracked_objects::ThreadData; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 198 } |
197 | 199 |
198 #endif | 200 #endif |
199 | 201 |
200 } // namespace | 202 } // namespace |
201 | 203 |
202 ChildThread* ChildThread::Get() { | 204 ChildThread* ChildThread::Get() { |
203 return ChildThreadImpl::current(); | 205 return ChildThreadImpl::current(); |
204 } | 206 } |
205 | 207 |
| 208 // Mojo client channel delegate to be used in single process mode. |
| 209 class ChildThreadImpl::SingleProcessChannelDelegate |
| 210 : public IPC::ChannelMojo::Delegate { |
| 211 public: |
| 212 explicit SingleProcessChannelDelegate() : weak_factory_(this) {} |
| 213 |
| 214 ~SingleProcessChannelDelegate() override {} |
| 215 |
| 216 base::WeakPtr<IPC::ChannelMojo::Delegate> ToWeakPtr() override { |
| 217 return weak_factory_.GetWeakPtr(); |
| 218 } |
| 219 |
| 220 scoped_refptr<base::TaskRunner> GetIOTaskRunner() override { |
| 221 return ChannelInit::GetSingleProcessIOTaskRunner(); |
| 222 } |
| 223 |
| 224 void OnChannelCreated(base::WeakPtr<IPC::ChannelMojo> channel) override {} |
| 225 |
| 226 void DeleteSoon() { |
| 227 ChannelInit::GetSingleProcessIOTaskRunner()->PostTask( |
| 228 FROM_HERE, |
| 229 base::Bind(&base::DeletePointer<SingleProcessChannelDelegate>, |
| 230 base::Unretained(this))); |
| 231 } |
| 232 |
| 233 private: |
| 234 base::WeakPtrFactory<IPC::ChannelMojo::Delegate> weak_factory_; |
| 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(SingleProcessChannelDelegate); |
| 237 }; |
| 238 |
| 239 void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()( |
| 240 SingleProcessChannelDelegate* delegate) const { |
| 241 delegate->DeleteSoon(); |
| 242 } |
| 243 |
206 ChildThreadImpl::Options::Options() | 244 ChildThreadImpl::Options::Options() |
207 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 245 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
208 switches::kProcessChannelID)), | 246 switches::kProcessChannelID)), |
209 use_mojo_channel(false), | 247 use_mojo_channel(false), |
210 in_browser_process(false) { | 248 in_browser_process(false) { |
211 } | 249 } |
212 | 250 |
213 ChildThreadImpl::Options::Options(bool mojo) | 251 ChildThreadImpl::Options::Options(bool mojo) |
214 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 252 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
215 switches::kProcessChannelID)), | 253 switches::kProcessChannelID)), |
(...skipping 27 matching lines...) Expand all Loading... |
243 : router_(this), | 281 : router_(this), |
244 in_browser_process_(options.in_browser_process), | 282 in_browser_process_(options.in_browser_process), |
245 channel_connected_factory_(this) { | 283 channel_connected_factory_(this) { |
246 Init(options); | 284 Init(options); |
247 } | 285 } |
248 | 286 |
249 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 287 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
250 bool create_pipe_now = true; | 288 bool create_pipe_now = true; |
251 if (use_mojo_channel) { | 289 if (use_mojo_channel) { |
252 VLOG(1) << "Mojo is enabled on child"; | 290 VLOG(1) << "Mojo is enabled on child"; |
253 channel_->Init(IPC::ChannelMojo::CreateClientFactory(channel_name_), | 291 scoped_refptr<base::TaskRunner> io_task_runner = |
254 create_pipe_now); | 292 ChannelInit::GetSingleProcessIOTaskRunner(); |
| 293 if (io_task_runner) { |
| 294 single_process_channel_delegate_.reset(new SingleProcessChannelDelegate); |
| 295 } else { |
| 296 io_task_runner = ChildProcess::current()->io_message_loop_proxy(); |
| 297 } |
| 298 DCHECK(io_task_runner); |
| 299 ipc_support_.reset(new IPC::ScopedIPCSupport(io_task_runner)); |
| 300 channel_->Init( |
| 301 IPC::ChannelMojo::CreateClientFactory( |
| 302 single_process_channel_delegate_.get(), |
| 303 channel_name_), |
| 304 create_pipe_now); |
255 return; | 305 return; |
256 } | 306 } |
257 | 307 |
258 VLOG(1) << "Mojo is disabled on child"; | 308 VLOG(1) << "Mojo is disabled on child"; |
259 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 309 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
260 } | 310 } |
261 | 311 |
262 void ChildThreadImpl::Init(const Options& options) { | 312 void ChildThreadImpl::Init(const Options& options) { |
263 channel_name_ = options.channel_name; | 313 channel_name_ = options.channel_name; |
264 | 314 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // doesn't cause such issues. TODO(gab): Remove this once the experiment is | 713 // doesn't cause such issues. TODO(gab): Remove this once the experiment is |
664 // over (http://crbug.com/458594). | 714 // over (http://crbug.com/458594). |
665 base::FieldTrial* trial = | 715 base::FieldTrial* trial = |
666 base::FieldTrialList::Find("BackgroundRendererProcesses"); | 716 base::FieldTrialList::Find("BackgroundRendererProcesses"); |
667 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") | 717 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") |
668 base::Process::Current().SetProcessBackgrounded(background); | 718 base::Process::Current().SetProcessBackgrounded(background); |
669 #endif // OS_WIN | 719 #endif // OS_WIN |
670 } | 720 } |
671 | 721 |
672 } // namespace content | 722 } // namespace content |
OLD | NEW |