| 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/public/cpp/system/message_pipe.h" | 13 #include "mojo/public/cpp/system/message_pipe.h" |
| 14 #include "mojo/shell/public/cpp/application_delegate.h" | 14 #include "mojo/shell/public/cpp/application_impl.h" |
| 15 #include "mojo/shell/public/cpp/shell_client.h" |
| 15 | 16 |
| 16 namespace mojo { | 17 namespace mojo { |
| 17 namespace shell { | 18 namespace shell { |
| 18 class RunnerConnection; | 19 class RunnerConnection; |
| 19 } | 20 } |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 // Returns true for processes launched from an external mojo shell. | 25 // Returns true for processes launched from an external mojo shell. |
| 25 bool IsRunningInMojoShell(); | 26 bool IsRunningInMojoShell(); |
| 26 | 27 |
| 27 class MojoShellConnectionImpl : public MojoShellConnection, | 28 class MojoShellConnectionImpl : public MojoShellConnection, |
| 28 public mojo::ApplicationDelegate { | 29 public mojo::ShellClient { |
| 29 public: | 30 public: |
| 30 // Creates an instance of this class and stuffs it in TLS on the calling | 31 // Creates an instance of this class and stuffs it in TLS on the calling |
| 31 // thread. Retrieve it using MojoShellConnection::Get(). | 32 // thread. Retrieve it using MojoShellConnection::Get(). |
| 32 static void Create(); | 33 static void Create(); |
| 33 | 34 |
| 34 // Will return null if no connection has been established (either because it | 35 // Will return null if no connection has been established (either because it |
| 35 // hasn't happened yet or the application was not spawned from the external | 36 // hasn't happened yet or the application was not spawned from the external |
| 36 // Mojo shell). | 37 // Mojo shell). |
| 37 static MojoShellConnectionImpl* Get(); | 38 static MojoShellConnectionImpl* Get(); |
| 38 | 39 |
| 39 // Blocks the calling thread until calling GetApplication() will return an | 40 // Blocks the calling thread until calling GetApplication() will return an |
| 40 // Initialized() application with a bound ShellPtr. This call is a no-op | 41 // Initialized() application with a bound ShellPtr. This call is a no-op |
| 41 // if the connection has already been initialized. | 42 // if the connection has already been initialized. |
| 42 void BindToCommandLinePlatformChannel(); | 43 void BindToCommandLinePlatformChannel(); |
| 43 | 44 |
| 44 // Same as BindToCommandLinePlatformChannel(), but receives a |handle| instead | 45 // Same as BindToCommandLinePlatformChannel(), but receives a |handle| instead |
| 45 // of looking for one on the command line. | 46 // of looking for one on the command line. |
| 46 void BindToMessagePipe(mojo::ScopedMessagePipeHandle handle); | 47 void BindToMessagePipe(mojo::ScopedMessagePipeHandle handle); |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 MojoShellConnectionImpl(); | 50 MojoShellConnectionImpl(); |
| 50 ~MojoShellConnectionImpl() override; | 51 ~MojoShellConnectionImpl() override; |
| 51 | 52 |
| 52 // mojo::ApplicationDelegate: | 53 // mojo::ShellClient: |
| 53 void Initialize(mojo::Shell* shell, const std::string& url, | 54 void Initialize(mojo::Shell* shell, const std::string& url, |
| 54 uint32_t id) override; | 55 uint32_t id) override; |
| 55 bool AcceptConnection( | 56 bool AcceptConnection(mojo::Connection* connection) override; |
| 56 mojo::ApplicationConnection* connection) override; | |
| 57 | 57 |
| 58 // MojoShellConnection: | 58 // MojoShellConnection: |
| 59 mojo::Shell* GetShell() override; | 59 mojo::Shell* GetShell() override; |
| 60 void AddListener(Listener* listener) override; | 60 void AddListener(Listener* listener) override; |
| 61 void RemoveListener(Listener* listener) override; | 61 void RemoveListener(Listener* listener) override; |
| 62 | 62 |
| 63 // Blocks the calling thread until a connection to the spawning shell is | 63 // Blocks the calling thread until a connection to the spawning shell is |
| 64 // established, an Application request from it is bound, and the Initialize() | 64 // established, an Application request from it is bound, and the Initialize() |
| 65 // method on that application is called. | 65 // method on that application is called. |
| 66 void WaitForShell(mojo::ScopedMessagePipeHandle handle); | 66 void WaitForShell(mojo::ScopedMessagePipeHandle handle); |
| 67 | 67 |
| 68 bool initialized_; | 68 bool initialized_; |
| 69 scoped_ptr<mojo::shell::RunnerConnection> runner_connection_; | 69 scoped_ptr<mojo::shell::RunnerConnection> runner_connection_; |
| 70 scoped_ptr<mojo::ApplicationImpl> application_impl_; | 70 scoped_ptr<mojo::ApplicationImpl> application_impl_; |
| 71 std::vector<Listener*> listeners_; | 71 std::vector<Listener*> listeners_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); | 73 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace content | 76 } // namespace content |
| 77 | 77 |
| 78 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 78 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
| OLD | NEW |