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

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

Issue 1901513003: Re-land: "Use a token to initialise ChannelMojo and MojoApplication everywhere." (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
« no previous file with comments | « content/child/mojo/mojo_application.h ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/logging.h"
10 #include "content/child/child_process.h"
11 #include "content/common/application_setup.mojom.h" 10 #include "content/common/application_setup.mojom.h"
12 #include "content/common/mojo/channel_init.h"
13 #include "content/common/mojo/mojo_messages.h"
14 #include "ipc/ipc_message.h"
15 #include "mojo/edk/embedder/embedder.h" 11 #include "mojo/edk/embedder/embedder.h"
16 #include "mojo/public/cpp/bindings/interface_ptr.h"
17 12
18 namespace content { 13 namespace content {
19 14
20 MojoApplication::MojoApplication( 15 MojoApplication::MojoApplication() {
21 scoped_refptr<base::SequencedTaskRunner> io_task_runner)
22 : io_task_runner_(io_task_runner) {
23 DCHECK(io_task_runner_);
24 } 16 }
25 17
26 MojoApplication::~MojoApplication() { 18 MojoApplication::~MojoApplication() {
27 } 19 }
28 20
29 bool MojoApplication::OnMessageReceived(const IPC::Message& msg) { 21 void MojoApplication::InitWithToken(const std::string& token) {
30 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg)
32 IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate)
33 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP()
35 return handled;
36 }
37
38 void MojoApplication::InitWithToken(std::string token) {
39 mojo::ScopedMessagePipeHandle handle = 22 mojo::ScopedMessagePipeHandle handle =
40 mojo::edk::CreateChildMessagePipe(token); 23 mojo::edk::CreateChildMessagePipe(token);
41 DCHECK(handle.is_valid()); 24 DCHECK(handle.is_valid());
42 25
43 mojom::ApplicationSetupPtr application_setup; 26 mojom::ApplicationSetupPtr application_setup;
44 application_setup.Bind( 27 application_setup.Bind(
45 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(handle), 0u)); 28 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(handle), 0u));
46 29
47 shell::mojom::InterfaceProviderPtr services; 30 shell::mojom::InterfaceProviderPtr services;
48 shell::mojom::InterfaceProviderPtr exposed_services; 31 shell::mojom::InterfaceProviderPtr exposed_services;
49 service_registry_.Bind(GetProxy(&exposed_services)); 32 service_registry_.Bind(GetProxy(&exposed_services));
50 application_setup->ExchangeInterfaceProviders(GetProxy(&services), 33 application_setup->ExchangeInterfaceProviders(GetProxy(&services),
51 std::move(exposed_services)); 34 std::move(exposed_services));
52 service_registry_.BindRemoteServiceProvider(std::move(services)); 35 service_registry_.BindRemoteServiceProvider(std::move(services));
53 } 36 }
54 37
55 void MojoApplication::OnActivate(
56 const IPC::PlatformFileForTransit& file) {
57 #if defined(OS_POSIX)
58 base::PlatformFile handle = file.fd;
59 #elif defined(OS_WIN)
60 base::PlatformFile handle = file.GetHandle();
61 #endif
62
63 mojo::ScopedMessagePipeHandle pipe =
64 channel_init_.Init(handle, io_task_runner_);
65 DCHECK(pipe.is_valid());
66
67 mojom::ApplicationSetupPtr application_setup;
68 application_setup.Bind(
69 mojo::InterfacePtrInfo<mojom::ApplicationSetup>(std::move(pipe), 0u));
70
71 shell::mojom::InterfaceProviderPtr services;
72 shell::mojom::InterfaceProviderPtr exposed_services;
73 service_registry_.Bind(GetProxy(&exposed_services));
74 application_setup->ExchangeInterfaceProviders(GetProxy(&services),
75 std::move(exposed_services));
76 service_registry_.BindRemoteServiceProvider(std::move(services));
77 }
78
79 } // namespace content 38 } // namespace content
OLDNEW
« no previous file with comments | « content/child/mojo/mojo_application.h ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698