OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/mojo/mojo_shell_connection_impl.h" | 5 #include "content/common/mojo/mojo_shell_connection_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 #include "mojo/application/public/cpp/application_delegate.h" | 10 #include "mojo/application/public/cpp/application_delegate.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 bool IsRunningInMojoShell() { | 26 bool IsRunningInMojoShell() { |
27 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 27 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
28 "mojo-platform-channel-handle"); | 28 "mojo-platform-channel-handle"); |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 void MojoShellConnectionImpl::Create() { | 32 void MojoShellConnectionImpl::Create() { |
33 DCHECK(IsRunningInMojoShell()); | 33 DCHECK(IsRunningInMojoShell()); |
34 CreateWithMessagePipe(mojo::ScopedMessagePipeHandle()); | |
35 } | |
36 | |
37 // static | |
38 void MojoShellConnectionImpl::CreateWithMessagePipe( | |
39 mojo::ScopedMessagePipeHandle handle) { | |
40 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 34 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
41 MojoShellConnectionImpl* connection = new MojoShellConnectionImpl; | 35 MojoShellConnectionImpl* connection = new MojoShellConnectionImpl; |
42 lazy_tls_ptr.Pointer()->Set(connection); | 36 lazy_tls_ptr.Pointer()->Set(connection); |
43 connection->WaitForShell(handle.Pass()); | 37 connection->WaitForShell(); |
44 } | 38 } |
45 | 39 |
46 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {} | 40 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {} |
47 MojoShellConnectionImpl::~MojoShellConnectionImpl() {} | 41 MojoShellConnectionImpl::~MojoShellConnectionImpl() {} |
48 | 42 |
49 void MojoShellConnectionImpl::WaitForShell( | 43 void MojoShellConnectionImpl::WaitForShell() { |
50 mojo::ScopedMessagePipeHandle handle) { | |
51 mojo::InterfaceRequest<mojo::Application> application_request; | 44 mojo::InterfaceRequest<mojo::Application> application_request; |
52 runner_connection_.reset(mojo::runner::RunnerConnection::ConnectToRunner( | 45 runner_connection_.reset( |
53 &application_request, handle.Pass())); | 46 mojo::runner::RunnerConnection::ConnectToRunner(&application_request)); |
54 application_impl_.reset(new mojo::ApplicationImpl( | 47 application_impl_.reset(new mojo::ApplicationImpl( |
55 this, application_request.Pass())); | 48 this, application_request.Pass())); |
56 application_impl_->WaitForInitialize(); | 49 application_impl_->WaitForInitialize(); |
57 } | 50 } |
58 | 51 |
59 void MojoShellConnectionImpl::Initialize(mojo::ApplicationImpl* application) { | 52 void MojoShellConnectionImpl::Initialize(mojo::ApplicationImpl* application) { |
60 initialized_ = true; | 53 initialized_ = true; |
61 } | 54 } |
62 | 55 |
63 bool MojoShellConnectionImpl::ConfigureIncomingConnection( | 56 bool MojoShellConnectionImpl::ConfigureIncomingConnection( |
(...skipping 29 matching lines...) Expand all Loading... |
93 // static | 86 // static |
94 void MojoShellConnection::Destroy() { | 87 void MojoShellConnection::Destroy() { |
95 // This joins the shell controller thread. | 88 // This joins the shell controller thread. |
96 delete Get(); | 89 delete Get(); |
97 lazy_tls_ptr.Pointer()->Set(nullptr); | 90 lazy_tls_ptr.Pointer()->Set(nullptr); |
98 } | 91 } |
99 | 92 |
100 MojoShellConnection::~MojoShellConnection() {} | 93 MojoShellConnection::~MojoShellConnection() {} |
101 | 94 |
102 } // namespace content | 95 } // namespace content |
OLD | NEW |