blob: 2e60abfd331043dfe0ee0df22a3e1d79d5a8c4d9 [file] [log] [blame]
[email protected]f20cc692012-11-28 19:21:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// 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/talk_resource.h"
6
[email protected]1f532162013-07-15 22:49:567#include "base/bind.h"
[email protected]f20cc692012-11-28 19:21:208#include "ppapi/proxy/ppapi_messages.h"
9
10namespace ppapi {
11namespace proxy {
12
13TalkResource::TalkResource(Connection connection, PP_Instance instance)
[email protected]ce97d7452013-06-07 19:02:0914 : PluginResource(connection, instance),
15 event_callback_(NULL),
16 event_callback_user_data_(NULL) {
17 SendCreate(BROWSER, PpapiHostMsg_Talk_Create());
[email protected]f20cc692012-11-28 19:21:2018}
19
20TalkResource::~TalkResource() {
21}
22
23thunk::PPB_Talk_Private_API* TalkResource::AsPPB_Talk_Private_API() {
24 return this;
25}
26
[email protected]ce97d7452013-06-07 19:02:0927int32_t TalkResource::RequestPermission(
28 PP_TalkPermission permission,
29 scoped_refptr<TrackedCallback> callback) {
30 if (TrackedCallback::IsPending(permission_callback_))
[email protected]f20cc692012-11-28 19:21:2031 return PP_ERROR_INPROGRESS;
[email protected]f20cc692012-11-28 19:21:2032
[email protected]ce97d7452013-06-07 19:02:0933 permission_callback_ = callback;
[email protected]f20cc692012-11-28 19:21:2034
[email protected]ce97d7452013-06-07 19:02:0935 Call<PpapiPluginMsg_Talk_RequestPermissionReply>(
[email protected]f20cc692012-11-28 19:21:2036 BROWSER,
[email protected]ce97d7452013-06-07 19:02:0937 PpapiHostMsg_Talk_RequestPermission(permission),
38 base::Bind(&TalkResource::OnRequestPermissionReply,
39 base::Unretained(this)));
[email protected]f20cc692012-11-28 19:21:2040 return PP_OK_COMPLETIONPENDING;
41}
42
[email protected]ce97d7452013-06-07 19:02:0943int32_t TalkResource::StartRemoting(PP_TalkEventCallback event_callback,
44 void* user_data,
45 scoped_refptr<TrackedCallback> callback) {
46 if (TrackedCallback::IsPending(start_callback_) ||
47 event_callback_ != NULL)
48 return PP_ERROR_INPROGRESS;
49
50 start_callback_ = callback;
51 event_callback_ = event_callback;
52 event_callback_user_data_ = user_data;
53
54 Call<PpapiPluginMsg_Talk_StartRemotingReply>(
55 BROWSER,
56 PpapiHostMsg_Talk_StartRemoting(),
57 base::Bind(&TalkResource::OnStartRemotingReply,
58 base::Unretained(this)));
59 return PP_OK_COMPLETIONPENDING;
60}
61
62int32_t TalkResource::StopRemoting(scoped_refptr<TrackedCallback> callback) {
63 if (TrackedCallback::IsPending(stop_callback_))
64 return PP_ERROR_INPROGRESS;
65
66 if (event_callback_ == NULL)
67 return PP_ERROR_FAILED;
68
69 stop_callback_ = callback;
70
71 Call<PpapiPluginMsg_Talk_StopRemotingReply>(
72 BROWSER,
73 PpapiHostMsg_Talk_StopRemoting(),
74 base::Bind(&TalkResource::OnStopRemotingReply,
75 base::Unretained(this)));
76 return PP_OK_COMPLETIONPENDING;
77}
78
79void TalkResource::OnReplyReceived(const ResourceMessageReplyParams& params,
80 const IPC::Message& msg) {
81 IPC_BEGIN_MESSAGE_MAP(TalkResource, msg)
82 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
83 PpapiPluginMsg_Talk_NotifyEvent,
84 OnNotifyEvent)
85 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
86 PluginResource::OnReplyReceived(params, msg))
87 IPC_END_MESSAGE_MAP()
88}
89
90void TalkResource::OnNotifyEvent(const ResourceMessageReplyParams& params,
91 PP_TalkEvent event) {
92 if (event_callback_ != NULL)
93 event_callback_(event_callback_user_data_, event);
94}
95
96void TalkResource::OnRequestPermissionReply(
[email protected]f20cc692012-11-28 19:21:2097 const ResourceMessageReplyParams& params) {
[email protected]ce97d7452013-06-07 19:02:0998 permission_callback_->Run(params.result());
99}
100
101void TalkResource::OnStartRemotingReply(
102 const ResourceMessageReplyParams& params) {
103 start_callback_->Run(params.result());
104}
105
106void TalkResource::OnStopRemotingReply(
107 const ResourceMessageReplyParams& params) {
108 event_callback_ = NULL;
109 event_callback_user_data_ = NULL;
110 stop_callback_->Run(params.result());
[email protected]f20cc692012-11-28 19:21:20111}
112
113} // namespace proxy
114} // namespace ppapi