blob: 7187852ba26d86068e67a31e0666833daff6bf45 [file] [log] [blame]
[email protected]f0ecb552012-05-11 22:09:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e2614c62011-04-16 22:12:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/broker_dispatcher.h"
6
[email protected]2b657fd2011-04-18 16:00:477#include "base/sync_socket.h"
8#include "ppapi/c/pp_errors.h"
[email protected]e2614c62011-04-16 22:12:459#include "ppapi/proxy/ppapi_messages.h"
[email protected]5a77eca2011-11-23 23:46:4610#include "ppapi/shared_impl/platform_file.h"
[email protected]e2614c62011-04-16 22:12:4511
[email protected]4d2efd22011-08-18 21:58:0212namespace ppapi {
[email protected]e2614c62011-04-16 22:12:4513namespace proxy {
14
[email protected]f0ecb552012-05-11 22:09:1115BrokerDispatcher::BrokerDispatcher(PP_ConnectInstance_Func connect_instance)
16 : connect_instance_(connect_instance) {
[email protected]e2614c62011-04-16 22:12:4517}
18
19BrokerDispatcher::~BrokerDispatcher() {
20}
21
22bool BrokerDispatcher::InitBrokerWithChannel(
23 ProxyChannel::Delegate* delegate,
[email protected]108fd342013-01-04 20:46:5424 base::ProcessId peer_pid,
[email protected]e2614c62011-04-16 22:12:4525 const IPC::ChannelHandle& channel_handle,
26 bool is_client) {
[email protected]f7b7eb7c2014-02-27 23:54:1527 return ProxyChannel::InitWithChannel(delegate, peer_pid, channel_handle,
28 is_client);
[email protected]e2614c62011-04-16 22:12:4529}
30
31bool BrokerDispatcher::OnMessageReceived(const IPC::Message& msg) {
32 // Control messages.
33 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
34 bool handled = true;
[email protected]e2614c62011-04-16 22:12:4535 IPC_BEGIN_MESSAGE_MAP(BrokerDispatcher, msg)
[email protected]2b657fd2011-04-18 16:00:4736 IPC_MESSAGE_HANDLER(PpapiMsg_ConnectToPlugin, OnMsgConnectToPlugin)
[email protected]e2614c62011-04-16 22:12:4537 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP()
[email protected]e2614c62011-04-16 22:12:4539 return handled;
40 }
41 return false;
42}
43
[email protected]2b657fd2011-04-18 16:00:4744// Transfers ownership of the handle to the broker module.
45void BrokerDispatcher::OnMsgConnectToPlugin(
46 PP_Instance instance,
[email protected]6990e5d2011-09-30 18:10:5747 IPC::PlatformFileForTransit handle,
48 int32_t* result) {
[email protected]2b657fd2011-04-18 16:00:4749 if (handle == IPC::InvalidPlatformFileForTransit()) {
[email protected]6990e5d2011-09-30 18:10:5750 *result = PP_ERROR_FAILED;
[email protected]2b657fd2011-04-18 16:00:4751 } else {
52 base::SyncSocket::Handle socket_handle =
53 IPC::PlatformFileForTransitToPlatformFile(handle);
54
55 if (connect_instance_) {
[email protected]5a77eca2011-11-23 23:46:4656 *result = connect_instance_(instance,
57 ppapi::PlatformFileToInt(socket_handle));
[email protected]2b657fd2011-04-18 16:00:4758 } else {
[email protected]6990e5d2011-09-30 18:10:5759 *result = PP_ERROR_FAILED;
[email protected]2b657fd2011-04-18 16:00:4760 // Close the handle since there is no other owner.
61 // The easiest way to clean it up is to just put it in an object
62 // and then close them. This failure case is not performance critical.
63 base::SyncSocket temp_socket(socket_handle);
64 }
65 }
[email protected]2b657fd2011-04-18 16:00:4766}
67
[email protected]f0ecb552012-05-11 22:09:1168BrokerHostDispatcher::BrokerHostDispatcher()
69 : BrokerDispatcher(NULL) {
[email protected]2b657fd2011-04-18 16:00:4770}
71
[email protected]4b417e52011-04-18 22:51:0872void BrokerHostDispatcher::OnChannelError() {
[email protected]1977348dd2011-10-26 22:27:4173 DVLOG(1) << "BrokerHostDispatcher::OnChannelError()";
[email protected]4b417e52011-04-18 22:51:0874 BrokerDispatcher::OnChannelError(); // Stop using the channel.
75
76 // Tell the host about the crash so it can clean up and display notification.
77 // TODO(ddorwin): Add BrokerCrashed() to PPB_Proxy_Private and call it.
78 // ppb_proxy_->BrokerCrashed(pp_module());
79}
80
81BrokerSideDispatcher::BrokerSideDispatcher(
[email protected]4b417e52011-04-18 22:51:0882 PP_ConnectInstance_Func connect_instance)
[email protected]f0ecb552012-05-11 22:09:1183 : BrokerDispatcher(connect_instance) {
[email protected]4b417e52011-04-18 22:51:0884}
85
86void BrokerSideDispatcher::OnChannelError() {
[email protected]1977348dd2011-10-26 22:27:4187 DVLOG(1) << "BrokerSideDispatcher::OnChannelError()";
[email protected]4b417e52011-04-18 22:51:0888 BrokerDispatcher::OnChannelError();
89
90 // The renderer has crashed or exited. This channel and all instances
91 // associated with it are no longer valid.
92 // TODO(ddorwin): This causes the broker process to exit, which may not be
93 // desirable in some use cases.
94 delete this;
95}
96
97
[email protected]e2614c62011-04-16 22:12:4598} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0299} // namespace ppapi