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

Side by Side Diff: chrome/browser/chromeos/arc/video/gpu_arc_video_service_host.cc

Issue 2680973006: Mojo EDK: Add safe process connection API (Closed)
Patch Set: . Created 3 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
« no previous file with comments | « no previous file | chrome/service/service_utility_process_host.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/chromeos/arc/video/gpu_arc_video_service_host.h" 5 #include "chrome/browser/chromeos/arc/video/gpu_arc_video_service_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/arc/arc_bridge_service.h" 15 #include "components/arc/arc_bridge_service.h"
16 #include "components/arc/common/video_accelerator.mojom.h" 16 #include "components/arc/common/video_accelerator.mojom.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/gpu_service_registry.h" 18 #include "content/public/browser/gpu_service_registry.h"
19 #include "mojo/edk/embedder/embedder.h" 19 #include "mojo/edk/embedder/embedder.h"
20 #include "mojo/edk/embedder/pending_process_connection.h"
20 #include "mojo/edk/embedder/platform_channel_pair.h" 21 #include "mojo/edk/embedder/platform_channel_pair.h"
21 #include "mojo/public/cpp/bindings/strong_binding.h" 22 #include "mojo/public/cpp/bindings/strong_binding.h"
22 #include "services/service_manager/public/cpp/interface_provider.h" 23 #include "services/service_manager/public/cpp/interface_provider.h"
23 24
24 namespace arc { 25 namespace arc {
25 26
26 namespace { 27 namespace {
27 28
28 void ConnectToVideoAcceleratorServiceOnIOThread( 29 void ConnectToVideoAcceleratorServiceOnIOThread(
29 mojom::VideoAcceleratorServiceRequest request) { 30 mojom::VideoAcceleratorServiceRequest request) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 video_instance->Init(binding_.CreateInterfacePtrAndBind()); 67 video_instance->Init(binding_.CreateInterfacePtrAndBind());
67 } 68 }
68 69
69 void GpuArcVideoServiceHost::OnBootstrapVideoAcceleratorFactory( 70 void GpuArcVideoServiceHost::OnBootstrapVideoAcceleratorFactory(
70 const OnBootstrapVideoAcceleratorFactoryCallback& callback) { 71 const OnBootstrapVideoAcceleratorFactoryCallback& callback) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 73
73 // Hardcode pid 0 since it is unused in mojo. 74 // Hardcode pid 0 since it is unused in mojo.
74 const base::ProcessHandle kUnusedChildProcessHandle = 75 const base::ProcessHandle kUnusedChildProcessHandle =
75 base::kNullProcessHandle; 76 base::kNullProcessHandle;
77 mojo::edk::PendingProcessConnection process;
76 mojo::edk::PlatformChannelPair channel_pair; 78 mojo::edk::PlatformChannelPair channel_pair;
77 std::string child_token = mojo::edk::GenerateRandomToken(); 79 process.Connect(kUnusedChildProcessHandle, channel_pair.PassServerHandle());
78 mojo::edk::ChildProcessLaunched(kUnusedChildProcessHandle,
79 channel_pair.PassServerHandle(), child_token);
80 80
81 MojoHandle wrapped_handle; 81 MojoHandle wrapped_handle;
82 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( 82 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper(
83 channel_pair.PassClientHandle(), &wrapped_handle); 83 channel_pair.PassClientHandle(), &wrapped_handle);
84 if (wrap_result != MOJO_RESULT_OK) { 84 if (wrap_result != MOJO_RESULT_OK) {
85 LOG(ERROR) << "Pipe failed to wrap handles. Closing: " << wrap_result; 85 LOG(ERROR) << "Pipe failed to wrap handles. Closing: " << wrap_result;
86 callback.Run(mojo::ScopedHandle(), std::string()); 86 callback.Run(mojo::ScopedHandle(), std::string());
87 return; 87 return;
88 } 88 }
89 mojo::ScopedHandle child_handle{mojo::Handle(wrapped_handle)}; 89 mojo::ScopedHandle child_handle{mojo::Handle(wrapped_handle)};
90 90
91 std::string token = mojo::edk::GenerateRandomToken(); 91 std::string token;
92 mojo::ScopedMessagePipeHandle server_pipe = 92 mojo::ScopedMessagePipeHandle server_pipe = process.CreateMessagePipe(&token);
93 mojo::edk::CreateParentMessagePipe(token, child_token);
94 if (!server_pipe.is_valid()) {
95 LOG(ERROR) << "Invalid pipe";
96 callback.Run(mojo::ScopedHandle(), std::string());
97 return;
98 }
99 callback.Run(std::move(child_handle), token); 93 callback.Run(std::move(child_handle), token);
100 94
101 mojo::MakeStrongBinding(base::MakeUnique<VideoAcceleratorFactoryService>(), 95 mojo::MakeStrongBinding(base::MakeUnique<VideoAcceleratorFactoryService>(),
102 mojo::MakeRequest<mojom::VideoAcceleratorFactory>( 96 mojo::MakeRequest<mojom::VideoAcceleratorFactory>(
103 std::move(server_pipe))); 97 std::move(server_pipe)));
104 } 98 }
105 99
106 } // namespace arc 100 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | chrome/service/service_utility_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698