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

Side by Side Diff: components/arc/arc_bridge_bootstrap.cc

Issue 1641353003: GpuArcVideoService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arc-4-owen-ArcGpuVideoDecodeAccelerator
Patch Set: address lhchavez and dcheng's comments 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 | « components/arc/arc_bridge_bootstrap.h ('k') | components/arc/common/video.mojom » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/arc/arc_bridge_bootstrap.h" 5 #include "components/arc/arc_bridge_bootstrap.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <grp.h> 8 #include <grp.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "ipc/unix_domain_socket_util.h" 25 #include "ipc/unix_domain_socket_util.h"
26 #include "mojo/edk/embedder/embedder.h" 26 #include "mojo/edk/embedder/embedder.h"
27 #include "mojo/edk/embedder/platform_channel_pair.h" 27 #include "mojo/edk/embedder/platform_channel_pair.h"
28 #include "mojo/edk/embedder/platform_channel_utils_posix.h" 28 #include "mojo/edk/embedder/platform_channel_utils_posix.h"
29 #include "mojo/edk/embedder/platform_handle_vector.h" 29 #include "mojo/edk/embedder/platform_handle_vector.h"
30 #include "mojo/edk/embedder/scoped_platform_handle.h" 30 #include "mojo/edk/embedder/scoped_platform_handle.h"
31 #include "mojo/public/cpp/bindings/binding.h" 31 #include "mojo/public/cpp/bindings/binding.h"
32 32
33 namespace arc { 33 namespace arc {
34 34
35 // This assumes all video accelerator clients are from the same namespace and
36 // the max pid of the said namespace is kPidMask.
37 base::ProcessHandle RemapChildPid(uint32_t pid) {
Luis Héctor Chávez 2016/03/28 16:01:27 nit: s/uint32_t/base::ProcessHandle/ in all this.
kcwu 2016/03/28 18:16:49 Done.
38 uint32_t kPidBase = 0x3DE0EA7C; // arbitrarily chosen.
39 uint32_t kPidMask = 0x7fff; // the default, 32k.
40 return kPidBase + (pid & kPidMask);
41 }
42
35 namespace { 43 namespace {
36 44
37 // We do not know the PID of ARC, since Chrome does not create it directly.
38 // Since Mojo in POSIX does not use the child PID except as an unique
39 // identifier for the routing table, rather than doing a lot of plumbing in the
40 // whole system to get the correct PID, just use an arbitrary number that will
41 // never be used by a legitimate process. Chrome OS assigns unassigned PIDs
42 // sequentially until it reaches a certain maximum value (Chrome OS uses the
43 // default value of 32k), at which point it loops around to zero. An arbitrary
44 // number larger than the maximum should be safe.
45 const pid_t kArcPid = 0x3DE0EA7C;
46
47 const base::FilePath::CharType kArcBridgeSocketPath[] = 45 const base::FilePath::CharType kArcBridgeSocketPath[] =
48 FILE_PATH_LITERAL("/var/run/chrome/arc_bridge.sock"); 46 FILE_PATH_LITERAL("/var/run/chrome/arc_bridge.sock");
49 47
50 const char kArcBridgeSocketGroup[] = "arc-bridge"; 48 const char kArcBridgeSocketGroup[] = "arc-bridge";
51 49
52 class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap { 50 class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap {
53 public: 51 public:
54 // The possible states of the bootstrap connection. In the normal flow, 52 // The possible states of the bootstrap connection. In the normal flow,
55 // the state changes in the following sequence: 53 // the state changes in the following sequence:
56 // 54 //
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 251
254 // static 252 // static
255 base::ScopedFD ArcBridgeBootstrapImpl::AcceptInstanceConnection( 253 base::ScopedFD ArcBridgeBootstrapImpl::AcceptInstanceConnection(
256 base::ScopedFD socket_fd) { 254 base::ScopedFD socket_fd) {
257 int raw_fd = -1; 255 int raw_fd = -1;
258 if (!IPC::ServerAcceptConnection(socket_fd.get(), &raw_fd)) { 256 if (!IPC::ServerAcceptConnection(socket_fd.get(), &raw_fd)) {
259 return base::ScopedFD(); 257 return base::ScopedFD();
260 } 258 }
261 base::ScopedFD scoped_fd(raw_fd); 259 base::ScopedFD scoped_fd(raw_fd);
262 260
261 // We do not know the PID of ARC, since Chrome does not create it directly
262 // and it may in the difference namespace. Here we assume the pid is zero
263 // (should not happen in its namespace) and RemapChildPid to safe range (not
264 // conflict in our namespace).
265 const pid_t kArcPid = RemapChildPid(0);
Luis Héctor Chávez 2016/03/28 16:01:27 nit: const base::ProcessHandle
kcwu 2016/03/28 18:16:49 Done.
263 mojo::edk::ScopedPlatformHandle child_handle = 266 mojo::edk::ScopedPlatformHandle child_handle =
264 mojo::edk::ChildProcessLaunched(kArcPid); 267 mojo::edk::ChildProcessLaunched(kArcPid);
265 268
266 mojo::edk::ScopedPlatformHandleVectorPtr handles( 269 mojo::edk::ScopedPlatformHandleVectorPtr handles(
267 new mojo::edk::PlatformHandleVector{child_handle.release()}); 270 new mojo::edk::PlatformHandleVector{child_handle.release()});
268 271
269 struct iovec iov = {const_cast<char*>(""), 1}; 272 struct iovec iov = {const_cast<char*>(""), 1};
270 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles( 273 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles(
271 mojo::edk::PlatformHandle(scoped_fd.get()), &iov, 1, handles->data(), 274 mojo::edk::PlatformHandle(scoped_fd.get()), &iov, 1, handles->data(),
272 handles->size()); 275 handles->size());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 345
343 ArcBridgeBootstrap::ArcBridgeBootstrap() {} 346 ArcBridgeBootstrap::ArcBridgeBootstrap() {}
344 ArcBridgeBootstrap::~ArcBridgeBootstrap() {} 347 ArcBridgeBootstrap::~ArcBridgeBootstrap() {}
345 348
346 // static 349 // static
347 scoped_ptr<ArcBridgeBootstrap> ArcBridgeBootstrap::Create() { 350 scoped_ptr<ArcBridgeBootstrap> ArcBridgeBootstrap::Create() {
348 return make_scoped_ptr(new ArcBridgeBootstrapImpl()); 351 return make_scoped_ptr(new ArcBridgeBootstrapImpl());
349 } 352 }
350 353
351 } // namespace arc 354 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_bootstrap.h ('k') | components/arc/common/video.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698