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 #include "content/browser/mojo/mojo_application_host.h" | 5 #include "content/browser/mojo/mojo_application_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "content/common/mojo/mojo_messages.h" | 10 #include "content/common/mojo/mojo_messages.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "ipc/ipc_sender.h" | 12 #include "ipc/ipc_sender.h" |
| 13 #include "mojo/edk/embedder/embedder.h" |
13 #include "mojo/edk/embedder/platform_channel_pair.h" | 14 #include "mojo/edk/embedder/platform_channel_pair.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 namespace { | 17 namespace { |
17 | 18 |
18 class ApplicationSetupImpl : public mojom::ApplicationSetup { | 19 class ApplicationSetupImpl : public mojom::ApplicationSetup { |
19 public: | 20 public: |
20 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, | 21 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, |
21 mojo::InterfaceRequest<mojom::ApplicationSetup> request) | 22 mojo::InterfaceRequest<mojom::ApplicationSetup> request) |
22 : binding_(this, std::move(request)), | 23 : binding_(this, std::move(request)), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 void MojoApplicationHost::Activate(IPC::Sender* sender, | 78 void MojoApplicationHost::Activate(IPC::Sender* sender, |
78 base::ProcessHandle process_handle) { | 79 base::ProcessHandle process_handle) { |
79 DCHECK(!did_activate_); | 80 DCHECK(!did_activate_); |
80 DCHECK(client_handle_.is_valid()); | 81 DCHECK(client_handle_.is_valid()); |
81 | 82 |
82 base::PlatformFile client_file = client_handle_.release().handle; | 83 base::PlatformFile client_file = client_handle_.release().handle; |
83 did_activate_ = sender->Send(new MojoMsg_Activate( | 84 did_activate_ = sender->Send(new MojoMsg_Activate( |
84 IPC::GetPlatformFileForTransit(client_file, true))); | 85 IPC::GetPlatformFileForTransit(client_file, true))); |
85 } | 86 } |
86 | 87 |
| 88 std::string MojoApplicationHost::InitWithToken() { |
| 89 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; |
| 90 DCHECK(!did_activate_); |
| 91 |
| 92 std::string token = mojo::edk::GenerateRandomToken(); |
| 93 mojo::ScopedMessagePipeHandle pipe = |
| 94 mojo::edk::CreateParentMessagePipe(token); |
| 95 DCHECK(pipe.is_valid()); |
| 96 application_setup_.reset(new ApplicationSetupImpl( |
| 97 &service_registry_, |
| 98 mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe)))); |
| 99 |
| 100 did_activate_ = true; |
| 101 return token; |
| 102 } |
| 103 |
| 104 mojo::ScopedMessagePipeHandle MojoApplicationHost::InitWithPipe() { |
| 105 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; |
| 106 DCHECK(!did_activate_); |
| 107 |
| 108 mojo::MessagePipe handles; |
| 109 DCHECK(handles.handle0.is_valid()); |
| 110 DCHECK(handles.handle1.is_valid()); |
| 111 application_setup_.reset(new ApplicationSetupImpl( |
| 112 &service_registry_, |
| 113 mojo::MakeRequest<mojom::ApplicationSetup>(std::move(handles.handle0)))); |
| 114 |
| 115 did_activate_ = true; |
| 116 return std::move(handles.handle1); |
| 117 } |
| 118 |
87 void MojoApplicationHost::OverrideIOTaskRunnerForTest( | 119 void MojoApplicationHost::OverrideIOTaskRunnerForTest( |
88 scoped_refptr<base::TaskRunner> io_task_runner) { | 120 scoped_refptr<base::TaskRunner> io_task_runner) { |
89 io_task_runner_override_ = io_task_runner; | 121 io_task_runner_override_ = io_task_runner; |
90 } | 122 } |
91 | 123 |
92 | 124 |
93 } // namespace content | 125 } // namespace content |
OLD | NEW |