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 3// found in the LICENSE file. 4 5#ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ 6#define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ 7 8#include "base/process/process_handle.h" 9#include "mojo/embedder/channel_init.h" 10#include "mojo/embedder/scoped_platform_handle.h" 11#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 12 13namespace IPC { 14class Sender; 15} 16 17namespace content { 18 19// MojoApplicationHost represents the code needed on the browser side to setup 20// a child process as a Mojo application via Chrome IPC. The child process 21// should use MojoApplication to handle messages generated by an instance of 22// MojoApplicationHost. MojoApplicationHost makes the mojo::ShellClient 23// interface available so that child-provided services can be invoked. 24class MojoApplicationHost { 25 public: 26 MojoApplicationHost(); 27 virtual ~MojoApplicationHost(); 28 29 // Two-phase initialization: 30 // 1- Init makes the shell_client() available synchronously. 31 // 2- Activate establishes the actual connection to the peer process. 32 bool Init(); 33 bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle); 34 35 bool did_activate() const { return did_activate_; } 36 37 mojo::ServiceProvider* service_provider() { 38 DCHECK(child_service_provider_.get()); 39 return child_service_provider_->client(); 40 } 41 42 private: 43 class ServiceProviderImpl 44 : public mojo::InterfaceImpl<mojo::ServiceProvider> { 45 public: 46 virtual void OnConnectionError() OVERRIDE { 47 // TODO(darin): How should we handle this error? 48 } 49 50 // mojo::ServiceProvider methods: 51 virtual void ConnectToService( 52 const mojo::String& service_url, 53 const mojo::String& service_name, 54 mojo::ScopedMessagePipeHandle handle, 55 const mojo::String& requestor_url) OVERRIDE; 56 }; 57 58 mojo::embedder::ChannelInit channel_init_; 59 mojo::embedder::ScopedPlatformHandle client_handle_; 60 61 scoped_ptr<ServiceProviderImpl> child_service_provider_; 62 63 bool did_activate_; 64 65 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); 66}; 67 68} // namespace content 69 70#endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ 71