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 #ifndef CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 5 #ifndef CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
6 #define CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 6 #define CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/public/common/mojo_shell_connection.h" | 12 #include "content/public/common/mojo_shell_connection.h" |
13 #include "mojo/application/public/cpp/application_delegate.h" | 13 #include "mojo/application/public/cpp/application_delegate.h" |
| 14 #include "mojo/public/cpp/system/message_pipe.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace runner { | 17 namespace runner { |
17 class RunnerConnection; | 18 class RunnerConnection; |
18 } | 19 } |
19 } | 20 } |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 // Returns true if the Chrome browser process was launched from the external | 24 // Returns true for processes launched from an external mojo shell. |
24 // Mojo shell. | |
25 bool IsRunningInMojoShell(); | 25 bool IsRunningInMojoShell(); |
26 | 26 |
27 class MojoShellConnectionImpl : public MojoShellConnection, | 27 class MojoShellConnectionImpl : public MojoShellConnection, |
28 public mojo::ApplicationDelegate { | 28 public mojo::ApplicationDelegate { |
29 public: | 29 public: |
30 // Creates an instance of this class and stuffs it in TLS on the calling | 30 // Creates an instance of this class and stuffs it in TLS on the calling |
31 // thread. Retrieve it using MojoShellConnection::Get(). Blocks the calling | 31 // thread. Retrieve it using MojoShellConnection::Get(). Blocks the calling |
32 // thread until calling GetApplication() will return an Initialized() | 32 // thread until calling GetApplication() will return an Initialized() |
33 // application with a bound ShellPtr. | 33 // application with a bound ShellPtr. |
34 static void Create(); | 34 static void Create(); |
| 35 // Same as Create(), but receives a handle instead of looking for one on the |
| 36 // command line. |
| 37 static void CreateWithMessagePipe(mojo::ScopedMessagePipeHandle handle); |
35 | 38 |
36 private: | 39 private: |
37 MojoShellConnectionImpl(); | 40 MojoShellConnectionImpl(); |
38 ~MojoShellConnectionImpl() override; | 41 ~MojoShellConnectionImpl() override; |
39 | 42 |
40 // mojo::ApplicationDelegate: | 43 // mojo::ApplicationDelegate: |
41 void Initialize(mojo::ApplicationImpl* application) override; | 44 void Initialize(mojo::ApplicationImpl* application) override; |
42 bool ConfigureIncomingConnection( | 45 bool ConfigureIncomingConnection( |
43 mojo::ApplicationConnection* connection) override; | 46 mojo::ApplicationConnection* connection) override; |
44 | 47 |
45 // MojoShellConnection: | 48 // MojoShellConnection: |
46 mojo::ApplicationImpl* GetApplication() override; | 49 mojo::ApplicationImpl* GetApplication() override; |
47 void AddListener(Listener* listener) override; | 50 void AddListener(Listener* listener) override; |
48 void RemoveListener(Listener* listener) override; | 51 void RemoveListener(Listener* listener) override; |
49 | 52 |
50 // Blocks the calling thread until a connection to the spawning shell is | 53 // Blocks the calling thread until a connection to the spawning shell is |
51 // established, an Application request from it is bound, and the Initialize() | 54 // established, an Application request from it is bound, and the Initialize() |
52 // method on that application is called. | 55 // method on that application is called. |
53 void WaitForShell(); | 56 void WaitForShell(mojo::ScopedMessagePipeHandle handle); |
54 | 57 |
55 bool initialized_; | 58 bool initialized_; |
56 scoped_ptr<mojo::runner::RunnerConnection> runner_connection_; | 59 scoped_ptr<mojo::runner::RunnerConnection> runner_connection_; |
57 scoped_ptr<mojo::ApplicationImpl> application_impl_; | 60 scoped_ptr<mojo::ApplicationImpl> application_impl_; |
58 std::vector<Listener*> listeners_; | 61 std::vector<Listener*> listeners_; |
59 | 62 |
60 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); | 63 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); |
61 }; | 64 }; |
62 | 65 |
63 } // namespace content | 66 } // namespace content |
64 | 67 |
65 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 68 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
OLD | NEW |