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

Side by Side Diff: components/arc/arc_session.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
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_session.h" 5 #include "components/arc/arc_session.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <grp.h> 8 #include <grp.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 15 matching lines...) Expand all
26 #include "chromeos/dbus/dbus_method_call_status.h" 26 #include "chromeos/dbus/dbus_method_call_status.h"
27 #include "chromeos/dbus/dbus_thread_manager.h" 27 #include "chromeos/dbus/dbus_thread_manager.h"
28 #include "chromeos/dbus/session_manager_client.h" 28 #include "chromeos/dbus/session_manager_client.h"
29 #include "components/arc/arc_bridge_host_impl.h" 29 #include "components/arc/arc_bridge_host_impl.h"
30 #include "components/arc/arc_features.h" 30 #include "components/arc/arc_features.h"
31 #include "components/arc/arc_session_observer.h" 31 #include "components/arc/arc_session_observer.h"
32 #include "components/user_manager/user_manager.h" 32 #include "components/user_manager/user_manager.h"
33 #include "mojo/edk/embedder/embedder.h" 33 #include "mojo/edk/embedder/embedder.h"
34 #include "mojo/edk/embedder/named_platform_handle.h" 34 #include "mojo/edk/embedder/named_platform_handle.h"
35 #include "mojo/edk/embedder/named_platform_handle_utils.h" 35 #include "mojo/edk/embedder/named_platform_handle_utils.h"
36 #include "mojo/edk/embedder/pending_process_connection.h"
36 #include "mojo/edk/embedder/platform_channel_pair.h" 37 #include "mojo/edk/embedder/platform_channel_pair.h"
37 #include "mojo/edk/embedder/platform_channel_utils_posix.h" 38 #include "mojo/edk/embedder/platform_channel_utils_posix.h"
38 #include "mojo/edk/embedder/platform_handle_vector.h" 39 #include "mojo/edk/embedder/platform_handle_vector.h"
39 #include "mojo/edk/embedder/scoped_platform_handle.h" 40 #include "mojo/edk/embedder/scoped_platform_handle.h"
40 #include "mojo/public/cpp/bindings/binding.h" 41 #include "mojo/public/cpp/bindings/binding.h"
41 42
42 namespace arc { 43 namespace arc {
43 44
44 namespace { 45 namespace {
45 46
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 mojo::edk::ScopedPlatformHandle scoped_fd; 435 mojo::edk::ScopedPlatformHandle scoped_fd;
435 if (!mojo::edk::ServerAcceptConnection(socket_fd.get(), &scoped_fd, 436 if (!mojo::edk::ServerAcceptConnection(socket_fd.get(), &scoped_fd,
436 /* check_peer_user = */ false) || 437 /* check_peer_user = */ false) ||
437 !scoped_fd.is_valid()) { 438 !scoped_fd.is_valid()) {
438 return mojo::ScopedMessagePipeHandle(); 439 return mojo::ScopedMessagePipeHandle();
439 } 440 }
440 441
441 // Hardcode pid 0 since it is unused in mojo. 442 // Hardcode pid 0 since it is unused in mojo.
442 const base::ProcessHandle kUnusedChildProcessHandle = 0; 443 const base::ProcessHandle kUnusedChildProcessHandle = 0;
443 mojo::edk::PlatformChannelPair channel_pair; 444 mojo::edk::PlatformChannelPair channel_pair;
444 std::string child_token = mojo::edk::GenerateRandomToken(); 445 mojo::edk::PendingProcessConnection process;
445 mojo::edk::ChildProcessLaunched(kUnusedChildProcessHandle, 446 process.Connect(kUnusedChildProcessHandle, channel_pair.PassServerHandle());
446 channel_pair.PassServerHandle(), child_token);
447 447
448 mojo::edk::ScopedPlatformHandleVectorPtr handles( 448 mojo::edk::ScopedPlatformHandleVectorPtr handles(
449 new mojo::edk::PlatformHandleVector{ 449 new mojo::edk::PlatformHandleVector{
450 channel_pair.PassClientHandle().release()}); 450 channel_pair.PassClientHandle().release()});
451 451
452 std::string token = mojo::edk::GenerateRandomToken(); 452 std::string token;
453 mojo::ScopedMessagePipeHandle pipe = process.CreateMessagePipe(&token);
454
453 // We need to send the length of the message as a single byte, so make sure it 455 // We need to send the length of the message as a single byte, so make sure it
454 // fits. 456 // fits.
455 DCHECK_LT(token.size(), 256u); 457 DCHECK_LT(token.size(), 256u);
456 uint8_t message_length = static_cast<uint8_t>(token.size()); 458 uint8_t message_length = static_cast<uint8_t>(token.size());
457 struct iovec iov[] = {{&message_length, sizeof(message_length)}, 459 struct iovec iov[] = {{&message_length, sizeof(message_length)},
458 {const_cast<char*>(token.c_str()), token.size()}}; 460 {const_cast<char*>(token.c_str()), token.size()}};
459 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles( 461 ssize_t result = mojo::edk::PlatformChannelSendmsgWithHandles(
460 scoped_fd.get(), iov, sizeof(iov) / sizeof(iov[0]), handles->data(), 462 scoped_fd.get(), iov, sizeof(iov) / sizeof(iov[0]), handles->data(),
461 handles->size()); 463 handles->size());
462 if (result == -1) { 464 if (result == -1) {
463 PLOG(ERROR) << "sendmsg"; 465 PLOG(ERROR) << "sendmsg";
464 return mojo::ScopedMessagePipeHandle(); 466 return mojo::ScopedMessagePipeHandle();
465 } 467 }
466 468
467 return mojo::edk::CreateParentMessagePipe(token, child_token); 469 return pipe;
468 } 470 }
469 471
470 void ArcSessionImpl::OnMojoConnected( 472 void ArcSessionImpl::OnMojoConnected(
471 mojo::ScopedMessagePipeHandle server_pipe) { 473 mojo::ScopedMessagePipeHandle server_pipe) {
472 DCHECK(thread_checker_.CalledOnValidThread()); 474 DCHECK(thread_checker_.CalledOnValidThread());
473 475
474 if (state_ == State::STOPPED) { 476 if (state_ == State::STOPPED) {
475 // This is the case that error is notified via DBus before the 477 // This is the case that error is notified via DBus before the
476 // OnMojoConnected() callback is invoked. The stopping procedure has 478 // OnMojoConnected() callback is invoked. The stopping procedure has
477 // been run, so do nothing. 479 // been run, so do nothing.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 644
643 // static 645 // static
644 std::unique_ptr<ArcSession> ArcSession::Create( 646 std::unique_ptr<ArcSession> ArcSession::Create(
645 ArcBridgeService* arc_bridge_service, 647 ArcBridgeService* arc_bridge_service,
646 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { 648 const scoped_refptr<base::TaskRunner>& blocking_task_runner) {
647 return base::MakeUnique<ArcSessionImpl>(arc_bridge_service, 649 return base::MakeUnique<ArcSessionImpl>(arc_bridge_service,
648 blocking_task_runner); 650 blocking_task_runner);
649 } 651 }
650 652
651 } // namespace arc 653 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/utility/importer/firefox_importer_unittest_utils_mac.cc ('k') | components/nacl/broker/nacl_broker_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698