| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
| 6 #define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 6 #define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
| 7 | 7 |
| 8 #include "base/process/process_handle.h" | 8 #include "base/process/process_handle.h" |
| 9 #include "mojo/common/channel_init.h" | 9 #include "mojo/common/channel_init.h" |
| 10 #include "mojo/embedder/scoped_platform_handle.h" | 10 #include "mojo/embedder/scoped_platform_handle.h" |
| 11 #include "mojo/public/cpp/bindings/remote_ptr.h" | |
| 12 #include "mojo/public/interfaces/shell/shell.mojom.h" | 11 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 13 | 12 |
| 14 namespace IPC { | 13 namespace IPC { |
| 15 class Sender; | 14 class Sender; |
| 16 } | 15 } |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 | 18 |
| 20 // MojoApplicationHost represents the code needed on the browser side to setup | 19 // MojoApplicationHost represents the code needed on the browser side to setup |
| 21 // a child process as a Mojo application via Chrome IPC. The child process | 20 // a child process as a Mojo application via Chrome IPC. The child process |
| 22 // should use MojoApplication to handle messages generated by an instance of | 21 // should use MojoApplication to handle messages generated by an instance of |
| 23 // MojoApplicationHost. MojoApplicationHost makes the mojo::ShellClient | 22 // MojoApplicationHost. MojoApplicationHost makes the mojo::ShellClient |
| 24 // interface available so that child-provided services can be invoked. | 23 // interface available so that child-provided services can be invoked. |
| 25 class MojoApplicationHost { | 24 class MojoApplicationHost { |
| 26 public: | 25 public: |
| 27 MojoApplicationHost(); | 26 MojoApplicationHost(); |
| 28 ~MojoApplicationHost(); | 27 ~MojoApplicationHost(); |
| 29 | 28 |
| 30 // Two-phase initialization: | 29 // Two-phase initialization: |
| 31 // 1- Init makes the shell_client() available synchronously. | 30 // 1- Init makes the shell_client() available synchronously. |
| 32 // 2- Activate establishes the actual connection to the peer process. | 31 // 2- Activate establishes the actual connection to the peer process. |
| 33 bool Init(); | 32 bool Init(); |
| 34 bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle); | 33 bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle); |
| 35 | 34 |
| 36 bool did_activate() const { return did_activate_; } | 35 bool did_activate() const { return did_activate_; } |
| 37 | 36 |
| 38 mojo::ShellClient* shell_client() { return shell_client_.get(); } | 37 mojo::ShellClient* shell_client() { return shell_impl_->client(); } |
| 39 | 38 |
| 40 private: | 39 private: |
| 40 class ShellImpl : public mojo::Shell { |
| 41 public: |
| 42 ShellImpl() : client_(NULL) {} |
| 43 mojo::ShellClient* client() { return client_; } |
| 44 |
| 45 // mojo::Shell methods: |
| 46 virtual void SetClient(mojo::ShellClient* client) OVERRIDE; |
| 47 virtual void Connect(const mojo::String& url, |
| 48 mojo::ScopedMessagePipeHandle handle) OVERRIDE; |
| 49 private: |
| 50 mojo::ShellClient* client_; |
| 51 }; |
| 52 |
| 41 mojo::common::ChannelInit channel_init_; | 53 mojo::common::ChannelInit channel_init_; |
| 42 mojo::embedder::ScopedPlatformHandle client_handle_; | 54 mojo::embedder::ScopedPlatformHandle client_handle_; |
| 43 mojo::RemotePtr<mojo::ShellClient> shell_client_; | 55 |
| 56 // shell_impl_ is bound to the lifetime of shell_. |
| 57 mojo::ShellPtr shell_; |
| 58 ShellImpl* shell_impl_; |
| 59 |
| 44 bool did_activate_; | 60 bool did_activate_; |
| 45 | 61 |
| 46 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); | 62 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); |
| 47 }; | 63 }; |
| 48 | 64 |
| 49 } // namespace content | 65 } // namespace content |
| 50 | 66 |
| 51 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 67 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
| OLD | NEW |