Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / mojo / mojo_application_host.h
blobfffb59e05c63395ee3e666f4eb4faa249cf7d49c
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"
17 #endif
19 namespace IPC {
20 class Sender;
23 namespace content {
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 {
31 public:
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.
38 bool Init();
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();
52 #endif
54 void OverrideIOTaskRunnerForTest(
55 scoped_refptr<base::TaskRunner> io_task_runner);
57 private:
58 ChannelInit channel_init_;
59 mojo::embedder::ScopedPlatformHandle client_handle_;
61 bool did_activate_;
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_;
70 #endif
72 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost);
75 } // namespace content
77 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_