1 // 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.
5 #include "ppapi/proxy/talk_resource.h"
8 #include "ppapi/proxy/ppapi_messages.h"
13 TalkResource::TalkResource(Connection connection
, PP_Instance instance
)
14 : PluginResource(connection
, instance
),
15 event_callback_(NULL
),
16 event_callback_user_data_(NULL
) {
17 SendCreate(BROWSER
, PpapiHostMsg_Talk_Create());
20 TalkResource::~TalkResource() {
23 thunk::PPB_Talk_Private_API
* TalkResource::AsPPB_Talk_Private_API() {
27 int32_t TalkResource::RequestPermission(
28 PP_TalkPermission permission
,
29 scoped_refptr
<TrackedCallback
> callback
) {
30 if (TrackedCallback::IsPending(permission_callback_
))
31 return PP_ERROR_INPROGRESS
;
33 permission_callback_
= callback
;
35 Call
<PpapiPluginMsg_Talk_RequestPermissionReply
>(
37 PpapiHostMsg_Talk_RequestPermission(permission
),
38 base::Bind(&TalkResource::OnRequestPermissionReply
,
39 base::Unretained(this)));
40 return PP_OK_COMPLETIONPENDING
;
43 int32_t TalkResource::StartRemoting(PP_TalkEventCallback event_callback
,
45 scoped_refptr
<TrackedCallback
> callback
) {
46 if (TrackedCallback::IsPending(start_callback_
) ||
47 event_callback_
!= NULL
)
48 return PP_ERROR_INPROGRESS
;
50 start_callback_
= callback
;
51 event_callback_
= event_callback
;
52 event_callback_user_data_
= user_data
;
54 Call
<PpapiPluginMsg_Talk_StartRemotingReply
>(
56 PpapiHostMsg_Talk_StartRemoting(),
57 base::Bind(&TalkResource::OnStartRemotingReply
,
58 base::Unretained(this)));
59 return PP_OK_COMPLETIONPENDING
;
62 int32_t TalkResource::StopRemoting(scoped_refptr
<TrackedCallback
> callback
) {
63 if (TrackedCallback::IsPending(stop_callback_
))
64 return PP_ERROR_INPROGRESS
;
66 if (event_callback_
== NULL
)
67 return PP_ERROR_FAILED
;
69 stop_callback_
= callback
;
71 Call
<PpapiPluginMsg_Talk_StopRemotingReply
>(
73 PpapiHostMsg_Talk_StopRemoting(),
74 base::Bind(&TalkResource::OnStopRemotingReply
,
75 base::Unretained(this)));
76 return PP_OK_COMPLETIONPENDING
;
79 void TalkResource::OnReplyReceived(const ResourceMessageReplyParams
& params
,
80 const IPC::Message
& msg
) {
81 PPAPI_BEGIN_MESSAGE_MAP(TalkResource
, msg
)
82 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
83 PpapiPluginMsg_Talk_NotifyEvent
,
85 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
86 PluginResource::OnReplyReceived(params
, msg
))
87 PPAPI_END_MESSAGE_MAP()
90 void TalkResource::OnNotifyEvent(const ResourceMessageReplyParams
& params
,
92 if (event_callback_
!= NULL
)
93 event_callback_(event_callback_user_data_
, event
);
96 void TalkResource::OnRequestPermissionReply(
97 const ResourceMessageReplyParams
& params
) {
98 permission_callback_
->Run(params
.result());
101 void TalkResource::OnStartRemotingReply(
102 const ResourceMessageReplyParams
& params
) {
103 start_callback_
->Run(params
.result());
106 void TalkResource::OnStopRemotingReply(
107 const ResourceMessageReplyParams
& params
) {
108 event_callback_
= NULL
;
109 event_callback_user_data_
= NULL
;
110 stop_callback_
->Run(params
.result());