Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: content/child/mojo/mojo_application.cc

Issue 1877743002: Use token-based initialisation for the utility process MojoApplication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/child/mojo/mojo_application.h" 5 #include "content/child/mojo/mojo_application.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/child/child_process.h" 10 #include "content/child/child_process.h"
11 #include "content/common/application_setup.mojom.h" 11 #include "content/common/application_setup.mojom.h"
12 #include "content/common/mojo/channel_init.h" 12 #include "content/common/mojo/channel_init.h"
13 #include "content/common/mojo/mojo_messages.h" 13 #include "content/common/mojo/mojo_messages.h"
14 #include "ipc/ipc_message.h" 14 #include "ipc/ipc_message.h"
15 #include "mojo/edk/embedder/embedder.h"
15 #include "mojo/public/cpp/bindings/interface_ptr.h" 16 #include "mojo/public/cpp/bindings/interface_ptr.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 MojoApplication::MojoApplication( 20 MojoApplication::MojoApplication(
20 scoped_refptr<base::SequencedTaskRunner> io_task_runner) 21 scoped_refptr<base::SequencedTaskRunner> io_task_runner)
21 : io_task_runner_(io_task_runner) { 22 : io_task_runner_(io_task_runner) {
22 DCHECK(io_task_runner_); 23 DCHECK(io_task_runner_);
23 } 24 }
24 25
25 MojoApplication::~MojoApplication() { 26 MojoApplication::~MojoApplication() {
26 } 27 }
27 28
28 bool MojoApplication::OnMessageReceived(const IPC::Message& msg) { 29 bool MojoApplication::OnMessageReceived(const IPC::Message& msg) {
29 bool handled = true; 30 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg) 31 IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg)
31 IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate) 32 IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate)
32 IPC_MESSAGE_UNHANDLED(handled = false) 33 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP() 34 IPC_END_MESSAGE_MAP()
34 return handled; 35 return handled;
35 } 36 }
36 37
38 void MojoApplication::InitWithToken(std::string token) {
39 mojo::ScopedMessagePipeHandle handle =
40 mojo::edk::CreateChildMessagePipe(token);
41 InitWithPipe(std::move(handle));
42 }
43
44 void MojoApplication::InitWithPipe(mojo::ScopedMessagePipeHandle handle) {
45 DCHECK(handle.is_valid());
46
47 mojom::ApplicationSetupPtr application_setup;
48 application_setup.Bind(
49 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(handle), 0u));
50
51 mojo::shell::mojom::InterfaceProviderPtr services;
52 mojo::shell::mojom::InterfaceProviderPtr exposed_services;
53 service_registry_.Bind(GetProxy(&exposed_services));
54 application_setup->ExchangeInterfaceProviders(GetProxy(&services),
55 std::move(exposed_services));
56 service_registry_.BindRemoteServiceProvider(std::move(services));
57 }
58
37 void MojoApplication::OnActivate( 59 void MojoApplication::OnActivate(
38 const IPC::PlatformFileForTransit& file) { 60 const IPC::PlatformFileForTransit& file) {
39 #if defined(OS_POSIX) 61 #if defined(OS_POSIX)
40 base::PlatformFile handle = file.fd; 62 base::PlatformFile handle = file.fd;
41 #elif defined(OS_WIN) 63 #elif defined(OS_WIN)
42 base::PlatformFile handle = file.GetHandle(); 64 base::PlatformFile handle = file.GetHandle();
43 #endif 65 #endif
44 66
45 mojo::ScopedMessagePipeHandle pipe = 67 mojo::ScopedMessagePipeHandle pipe =
46 channel_init_.Init(handle, io_task_runner_); 68 channel_init_.Init(handle, io_task_runner_);
47 DCHECK(pipe.is_valid()); 69 DCHECK(pipe.is_valid());
48 70
49 mojom::ApplicationSetupPtr application_setup; 71 mojom::ApplicationSetupPtr application_setup;
50 application_setup.Bind( 72 application_setup.Bind(
51 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(pipe), 0u)); 73 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(pipe), 0u));
52 74
53 mojo::shell::mojom::InterfaceProviderPtr services; 75 mojo::shell::mojom::InterfaceProviderPtr services;
54 mojo::shell::mojom::InterfaceProviderPtr exposed_services; 76 mojo::shell::mojom::InterfaceProviderPtr exposed_services;
55 service_registry_.Bind(GetProxy(&exposed_services)); 77 service_registry_.Bind(GetProxy(&exposed_services));
56 application_setup->ExchangeInterfaceProviders(GetProxy(&services), 78 application_setup->ExchangeInterfaceProviders(GetProxy(&services),
57 std::move(exposed_services)); 79 std::move(exposed_services));
58 service_registry_.BindRemoteServiceProvider(std::move(services)); 80 service_registry_.BindRemoteServiceProvider(std::move(services));
59 } 81 }
60 82
61 } // namespace content 83 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698