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 |
11 #include "base/process/process_handle.h" | |
11 #include "base/allocator/allocator_extension.h" | 12 #include "base/allocator/allocator_extension.h" |
12 #include "base/base_switches.h" | 13 #include "base/base_switches.h" |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/debug/leak_annotations.h" | 16 #include "base/debug/leak_annotations.h" |
16 #include "base/debug/profiler.h" | 17 #include "base/debug/profiler.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/location.h" | 19 #include "base/location.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/message_loop/timer_slack.h" | 21 #include "base/message_loop/timer_slack.h" |
21 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
22 #include "base/process/process.h" | 23 #include "base/process/process.h" |
23 #include "base/process/process_handle.h" | 24 #include "base/process/process_handle.h" |
24 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
27 #include "base/synchronization/condition_variable.h" | 28 #include "base/synchronization/condition_variable.h" |
28 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
29 #include "base/thread_task_runner_handle.h" | 30 #include "base/thread_task_runner_handle.h" |
30 #include "base/threading/thread_local.h" | 31 #include "base/threading/thread_local.h" |
31 #include "base/tracked_objects.h" | 32 #include "base/tracked_objects.h" |
33 #include "components/mus/public/cpp/window.h" | |
34 #include "components/mus/public/cpp/window_observer.h" | |
35 #include "components/mus/public/cpp/window_surface.h" | |
36 #include "components/mus/public/cpp/window_tree_connection.h" | |
37 #include "components/mus/public/cpp/window_tree_delegate.h" | |
32 #include "components/tracing/child_trace_message_filter.h" | 38 #include "components/tracing/child_trace_message_filter.h" |
33 #include "content/child/child_discardable_shared_memory_manager.h" | 39 #include "content/child/child_discardable_shared_memory_manager.h" |
34 #include "content/child/child_gpu_memory_buffer_manager.h" | 40 #include "content/child/child_gpu_memory_buffer_manager.h" |
35 #include "content/child/child_histogram_message_filter.h" | 41 #include "content/child/child_histogram_message_filter.h" |
36 #include "content/child/child_process.h" | 42 #include "content/child/child_process.h" |
37 #include "content/child/child_resource_message_filter.h" | 43 #include "content/child/child_resource_message_filter.h" |
38 #include "content/child/child_shared_bitmap_manager.h" | 44 #include "content/child/child_shared_bitmap_manager.h" |
39 #include "content/child/fileapi/file_system_dispatcher.h" | 45 #include "content/child/fileapi/file_system_dispatcher.h" |
40 #include "content/child/fileapi/webfilesystem_impl.h" | 46 #include "content/child/fileapi/webfilesystem_impl.h" |
41 #include "content/child/geofencing/geofencing_message_filter.h" | 47 #include "content/child/geofencing/geofencing_message_filter.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
54 #include "content/common/in_process_child_thread_params.h" | 60 #include "content/common/in_process_child_thread_params.h" |
55 #include "content/common/mojo/mojo_messages.h" | 61 #include "content/common/mojo/mojo_messages.h" |
56 #include "content/public/common/content_switches.h" | 62 #include "content/public/common/content_switches.h" |
57 #include "ipc/attachment_broker.h" | 63 #include "ipc/attachment_broker.h" |
58 #include "ipc/attachment_broker_unprivileged.h" | 64 #include "ipc/attachment_broker_unprivileged.h" |
59 #include "ipc/ipc_logging.h" | 65 #include "ipc/ipc_logging.h" |
60 #include "ipc/ipc_switches.h" | 66 #include "ipc/ipc_switches.h" |
61 #include "ipc/ipc_sync_channel.h" | 67 #include "ipc/ipc_sync_channel.h" |
62 #include "ipc/ipc_sync_message_filter.h" | 68 #include "ipc/ipc_sync_message_filter.h" |
63 #include "ipc/mojo/ipc_channel_mojo.h" | 69 #include "ipc/mojo/ipc_channel_mojo.h" |
70 #include "mojo/application/public/cpp/application_impl.h" | |
71 #include "mojo/converters/geometry/geometry_type_converters.h" | |
72 #include "mojo/converters/surfaces/surfaces_utils.h" | |
64 | 73 |
65 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 74 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
66 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 75 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
67 #endif | 76 #endif |
68 | 77 |
69 #if defined(OS_MACOSX) | 78 #if defined(OS_MACOSX) |
70 #include "content/child/child_io_surface_manager_mac.h" | 79 #include "content/child/child_io_surface_manager_mac.h" |
71 #endif | 80 #endif |
72 | 81 |
73 #if defined(USE_OZONE) | 82 #if defined(USE_OZONE) |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 base::AutoLock lock(lock_); | 279 base::AutoLock lock(lock_); |
271 while (closure_.is_null()) | 280 while (closure_.is_null()) |
272 cond_var_.Wait(); | 281 cond_var_.Wait(); |
273 | 282 |
274 closure_.Run(); | 283 closure_.Run(); |
275 } | 284 } |
276 | 285 |
277 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; | 286 base::LazyInstance<QuitClosure> g_quit_closure = LAZY_INSTANCE_INITIALIZER; |
278 #endif | 287 #endif |
279 | 288 |
289 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate, | |
290 public mus::WindowObserver { | |
291 public: | |
292 WindowTreeDelegateImpl() {} | |
293 ~WindowTreeDelegateImpl() override {} | |
294 | |
295 private: | |
296 // WindowTreeDelegateImpl: | |
297 void OnEmbed(mus::Window* root) override { | |
298 root->AddObserver(this); | |
299 fprintf(stderr, ">>>%s root: %p\n", __PRETTY_FUNCTION__, root); | |
Fady Samuel
2015/11/24 04:42:38
Move this to RenderWidgetViewMus and revert the re
| |
300 surface_ = root->RequestSurface(mus::mojom::SURFACE_TYPE_DEFAULT); | |
301 surface_->BindToThread(); | |
302 | |
303 const gfx::Rect bounds(root->bounds()); | |
304 fprintf(stderr, ">>>%s bounds(%d, %d, %d, %d)\n", __PRETTY_FUNCTION__, | |
305 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | |
306 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | |
307 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); | |
308 | |
309 // TODO(rjkroege): Support device scale factor in PDF viewer | |
310 mus::mojom::CompositorFrameMetadataPtr meta = | |
311 mus::mojom::CompositorFrameMetadata::New(); | |
312 meta->device_scale_factor = 1.0f; | |
313 frame->metadata = meta.Pass(); | |
314 | |
315 frame->resources.resize(0u); | |
316 | |
317 pass->quads.resize(0u); | |
318 pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(bounds.size())); | |
319 | |
320 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); | |
321 quad->material = mus::mojom::MATERIAL_SOLID_COLOR; | |
322 quad->rect = mojo::Rect::From(bounds); | |
323 quad->opaque_rect = mojo::Rect::New(); | |
324 quad->visible_rect = mojo::Rect::From(bounds); | |
325 quad->needs_blending = false; | |
326 quad->shared_quad_state_index = 0u; | |
327 | |
328 mus::mojom::SolidColorQuadStatePtr color_state = | |
329 mus::mojom::SolidColorQuadState::New(); | |
330 color_state->color = mus::mojom::Color::New(); | |
331 color_state->color->rgba = 0xff00ff00; | |
332 color_state->force_anti_aliasing_off = false; | |
333 | |
334 quad->solid_color_quad_state = color_state.Pass(); | |
335 pass->quads.push_back(quad.Pass()); | |
336 frame->passes.push_back(pass.Pass()); | |
337 surface_->SubmitCompositorFrame(frame.Pass(), mojo::Closure()); | |
338 } | |
339 | |
340 void OnUnembed() override {} | |
341 | |
342 void OnWindowBoundsChanged(mus::Window* window, | |
343 const gfx::Rect& old_bounds, | |
344 const gfx::Rect& new_bounds) override { | |
345 // TODO(fsamuel): Update the size of the child content here. | |
346 } | |
347 | |
348 void OnConnectionLost(mus::WindowTreeConnection* connection) override { | |
349 delete this; | |
350 } | |
351 | |
352 scoped_ptr<mus::WindowSurface> surface_; | |
353 }; | |
354 | |
280 } // namespace | 355 } // namespace |
281 | 356 |
282 ChildThread* ChildThread::Get() { | 357 ChildThread* ChildThread::Get() { |
283 return ChildThreadImpl::current(); | 358 return ChildThreadImpl::current(); |
284 } | 359 } |
285 | 360 |
286 ChildThreadImpl::Options::Options() | 361 ChildThreadImpl::Options::Options() |
287 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 362 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
288 switches::kProcessChannelID)), | 363 switches::kProcessChannelID)), |
289 use_mojo_channel(false) { | 364 use_mojo_channel(false) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 | 635 |
561 void ChildThreadImpl::OnChannelConnected(int32 peer_pid) { | 636 void ChildThreadImpl::OnChannelConnected(int32 peer_pid) { |
562 channel_connected_factory_.InvalidateWeakPtrs(); | 637 channel_connected_factory_.InvalidateWeakPtrs(); |
563 } | 638 } |
564 | 639 |
565 void ChildThreadImpl::OnChannelError() { | 640 void ChildThreadImpl::OnChannelError() { |
566 set_on_channel_error_called(true); | 641 set_on_channel_error_called(true); |
567 base::MessageLoop::current()->QuitWhenIdle(); | 642 base::MessageLoop::current()->QuitWhenIdle(); |
568 } | 643 } |
569 | 644 |
645 bool ChildThreadImpl::ConfigureIncomingConnection( | |
646 mojo::ApplicationConnection* connection) { | |
647 // TODO(fsamuel): This doens't belong here. We should have this elsewhere. | |
648 fprintf(stderr, ">>>>>INCOMING CONNECTION %s!!!\n", | |
649 connection->GetRemoteApplicationURL().c_str()); | |
650 connection->AddService<mus::mojom::WindowTreeClient>(this); | |
651 return true; | |
652 } | |
653 | |
654 void ChildThreadImpl::Create( | |
655 mojo::ApplicationConnection* connection, | |
656 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { | |
657 fprintf(stderr, ">>>>>WINDOW TREE CLIENT!!!\n"); | |
658 mus::WindowTreeConnection::Create( | |
659 new WindowTreeDelegateImpl, request.Pass(), | |
660 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | |
661 } | |
662 | |
570 bool ChildThreadImpl::Send(IPC::Message* msg) { | 663 bool ChildThreadImpl::Send(IPC::Message* msg) { |
571 DCHECK(base::MessageLoop::current() == message_loop()); | 664 DCHECK(base::MessageLoop::current() == message_loop()); |
572 if (!channel_) { | 665 if (!channel_) { |
573 delete msg; | 666 delete msg; |
574 return false; | 667 return false; |
575 } | 668 } |
576 | 669 |
577 return channel_->Send(msg); | 670 return channel_->Send(msg); |
578 } | 671 } |
579 | 672 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 #if defined(MOJO_SHELL_CLIENT) | 813 #if defined(MOJO_SHELL_CLIENT) |
721 #if defined(OS_POSIX) | 814 #if defined(OS_POSIX) |
722 base::PlatformFile handle = file.fd; | 815 base::PlatformFile handle = file.fd; |
723 #elif defined(OS_WIN) | 816 #elif defined(OS_WIN) |
724 base::PlatformFile handle = file; | 817 base::PlatformFile handle = file; |
725 #endif | 818 #endif |
726 mojo::ScopedMessagePipeHandle message_pipe = | 819 mojo::ScopedMessagePipeHandle message_pipe = |
727 mojo_shell_channel_init_.Init(handle, GetIOTaskRunner()); | 820 mojo_shell_channel_init_.Init(handle, GetIOTaskRunner()); |
728 DCHECK(message_pipe.is_valid()); | 821 DCHECK(message_pipe.is_valid()); |
729 MojoShellConnectionImpl::CreateWithMessagePipe(message_pipe.Pass()); | 822 MojoShellConnectionImpl::CreateWithMessagePipe(message_pipe.Pass()); |
823 fprintf(stderr, "[%d] >>>%s url: %s\n", base::GetCurrentProcId(), | |
824 __PRETTY_FUNCTION__, | |
825 MojoShellConnection::Get()->GetApplication()->url().c_str()); | |
826 MojoShellConnection::Get()->AddListener(this); | |
730 #endif // defined(MOJO_SHELL_CLIENT) | 827 #endif // defined(MOJO_SHELL_CLIENT) |
828 Send(new MojoHostMsg_MojoReady()); | |
731 } | 829 } |
732 | 830 |
733 #if defined(USE_TCMALLOC) | 831 #if defined(USE_TCMALLOC) |
734 void ChildThreadImpl::OnGetTcmallocStats() { | 832 void ChildThreadImpl::OnGetTcmallocStats() { |
735 std::string result; | 833 std::string result; |
736 char buffer[1024 * 32]; | 834 char buffer[1024 * 32]; |
737 base::allocator::GetStats(buffer, sizeof(buffer)); | 835 base::allocator::GetStats(buffer, sizeof(buffer)); |
738 result.append(buffer); | 836 result.append(buffer); |
739 Send(new ChildProcessHostMsg_TcmallocStats(result)); | 837 Send(new ChildProcessHostMsg_TcmallocStats(result)); |
740 } | 838 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 void ChildThreadImpl::EnsureConnected() { | 870 void ChildThreadImpl::EnsureConnected() { |
773 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 871 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
774 base::Process::Current().Terminate(0, false); | 872 base::Process::Current().Terminate(0, false); |
775 } | 873 } |
776 | 874 |
777 bool ChildThreadImpl::IsInBrowserProcess() const { | 875 bool ChildThreadImpl::IsInBrowserProcess() const { |
778 return browser_process_io_runner_; | 876 return browser_process_io_runner_; |
779 } | 877 } |
780 | 878 |
781 } // namespace content | 879 } // namespace content |
OLD | NEW |