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.
5 #ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_
6 #define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/process/process_handle.h"
10 #include "content/common/application_setup.mojom.h"
11 #include "content/common/mojo/channel_init.h"
12 #include "content/common/mojo/service_registry_impl.h"
13 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
15 #if defined(OS_ANDROID)
16 #include "content/browser/mojo/service_registry_android.h"
25 // MojoApplicationHost represents the code needed on the browser side to setup
26 // a child process as a Mojo application via Chrome IPC. The child process
27 // should use MojoApplication to handle messages generated by an instance of
28 // MojoApplicationHost. MojoApplicationHost makes the ServiceRegistry interface
29 // available so that child-provided services can be invoked.
30 class CONTENT_EXPORT MojoApplicationHost
{
32 MojoApplicationHost();
33 ~MojoApplicationHost();
35 // Two-phase initialization:
36 // 1- Init makes service_registry() available synchronously.
37 // 2- Activate establishes the actual connection to the peer process.
39 void Activate(IPC::Sender
* sender
, base::ProcessHandle process_handle
);
41 void WillDestroySoon();
43 // Shuts down the Mojo channel. Must be called from the IO thread.
44 void ShutdownOnIOThread();
46 ServiceRegistry
* service_registry() { return &service_registry_
; }
48 #if defined(OS_ANDROID)
49 ServiceRegistryAndroid
* service_registry_android() {
50 return service_registry_android_
.get();
54 void OverrideIOTaskRunnerForTest(
55 scoped_refptr
<base::TaskRunner
> io_task_runner
);
58 ChannelInit channel_init_
;
59 mojo::embedder::ScopedPlatformHandle client_handle_
;
63 scoped_ptr
<ApplicationSetup
> application_setup_
;
64 ServiceRegistryImpl service_registry_
;
66 scoped_refptr
<base::TaskRunner
> io_task_runner_override_
;
68 #if defined(OS_ANDROID)
69 scoped_ptr
<ServiceRegistryAndroid
> service_registry_android_
;
72 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost
);
75 } // namespace content
77 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_