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

Side by Side Diff: content/browser/mojo/mojo_application_host.cc

Issue 1676913002: [mojo] Delete third_party/mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 10 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/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 "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" 13 #include "mojo/edk/embedder/platform_channel_pair.h"
14 14
15 namespace content { 15 namespace content {
16 namespace { 16 namespace {
17 17
18 base::PlatformFile PlatformFileFromScopedPlatformHandle(
19 mojo::embedder::ScopedPlatformHandle handle) {
20 #if defined(OS_POSIX)
21 return handle.release().fd;
22 #elif defined(OS_WIN)
23 return handle.release().handle;
24 #endif
25 }
26
27 class ApplicationSetupImpl : public ApplicationSetup { 18 class ApplicationSetupImpl : public ApplicationSetup {
28 public: 19 public:
29 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, 20 ApplicationSetupImpl(ServiceRegistryImpl* service_registry,
30 mojo::InterfaceRequest<ApplicationSetup> request) 21 mojo::InterfaceRequest<ApplicationSetup> request)
31 : binding_(this, std::move(request)), 22 : binding_(this, std::move(request)),
32 service_registry_(service_registry) {} 23 service_registry_(service_registry) {}
33 24
34 ~ApplicationSetupImpl() override { 25 ~ApplicationSetupImpl() override {
35 } 26 }
36 27
(...skipping 19 matching lines...) Expand all
56 new ServiceRegistryAndroid(&service_registry_)); 47 new ServiceRegistryAndroid(&service_registry_));
57 #endif 48 #endif
58 } 49 }
59 50
60 MojoApplicationHost::~MojoApplicationHost() { 51 MojoApplicationHost::~MojoApplicationHost() {
61 } 52 }
62 53
63 bool MojoApplicationHost::Init() { 54 bool MojoApplicationHost::Init() {
64 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; 55 DCHECK(!client_handle_.is_valid()) << "Already initialized!";
65 56
66 mojo::embedder::PlatformChannelPair channel_pair; 57 mojo::edk::PlatformChannelPair channel_pair;
67 58
68 scoped_refptr<base::TaskRunner> io_task_runner; 59 scoped_refptr<base::TaskRunner> io_task_runner;
69 if (io_task_runner_override_) { 60 if (io_task_runner_override_) {
70 io_task_runner = io_task_runner_override_; 61 io_task_runner = io_task_runner_override_;
71 } else { 62 } else {
72 io_task_runner = 63 io_task_runner =
73 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 64 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
74 ->task_runner(); 65 ->task_runner();
75 } 66 }
76 67
77 // Forward this to the client once we know its process handle. 68 // Forward this to the client once we know its process handle.
78 client_handle_ = channel_pair.PassClientHandle(); 69 client_handle_ = channel_pair.PassClientHandle();
79 70
80 channel_init_.Init( 71 channel_init_.Init(channel_pair.PassServerHandle().release().handle,
81 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), 72 io_task_runner,
82 io_task_runner, 73 base::Bind(&MojoApplicationHost::OnMessagePipeCreated,
83 base::Bind(&MojoApplicationHost::OnMessagePipeCreated, 74 weak_factory_.GetWeakPtr()));
84 weak_factory_.GetWeakPtr()));
85 75
86 return true; 76 return true;
87 } 77 }
88 78
89 void MojoApplicationHost::Activate(IPC::Sender* sender, 79 void MojoApplicationHost::Activate(IPC::Sender* sender,
90 base::ProcessHandle process_handle) { 80 base::ProcessHandle process_handle) {
91 DCHECK(!did_activate_); 81 DCHECK(!did_activate_);
92 DCHECK(client_handle_.is_valid()); 82 DCHECK(client_handle_.is_valid());
93 83
94 base::PlatformFile client_file = 84 base::PlatformFile client_file = client_handle_.release().handle;
95 PlatformFileFromScopedPlatformHandle(std::move(client_handle_));
96 did_activate_ = sender->Send(new MojoMsg_Activate( 85 did_activate_ = sender->Send(new MojoMsg_Activate(
97 IPC::GetFileHandleForProcess(client_file, process_handle, true))); 86 IPC::GetFileHandleForProcess(client_file, process_handle, true)));
98 } 87 }
99 88
100 void MojoApplicationHost::WillDestroySoon() {
101 channel_init_.WillDestroySoon();
102 }
103
104 void MojoApplicationHost::OverrideIOTaskRunnerForTest( 89 void MojoApplicationHost::OverrideIOTaskRunnerForTest(
105 scoped_refptr<base::TaskRunner> io_task_runner) { 90 scoped_refptr<base::TaskRunner> io_task_runner) {
106 io_task_runner_override_ = io_task_runner; 91 io_task_runner_override_ = io_task_runner;
107 } 92 }
108 93
109 void MojoApplicationHost::OnMessagePipeCreated( 94 void MojoApplicationHost::OnMessagePipeCreated(
110 mojo::ScopedMessagePipeHandle pipe) { 95 mojo::ScopedMessagePipeHandle pipe) {
111 DCHECK(pipe.is_valid()); 96 DCHECK(pipe.is_valid());
112 application_setup_.reset(new ApplicationSetupImpl( 97 application_setup_.reset(new ApplicationSetupImpl(
113 &service_registry_, 98 &service_registry_,
114 mojo::MakeRequest<ApplicationSetup>(std::move(pipe)))); 99 mojo::MakeRequest<ApplicationSetup>(std::move(pipe))));
115 } 100 }
116 101
117 } // namespace content 102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698