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

Side by Side Diff: ppapi/proxy/ppb_talk_private_proxy.cc

Issue 9666020: Add a private PPB_Talk_Private interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_talk_private_proxy.h ('k') | ppapi/proxy/resource_creation_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/proxy/ppb_talk_private_proxy.h"
6
7 #include "ipc/ipc_message_macros.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/plugin_globals.h"
11 #include "ppapi/proxy/plugin_proxy_delegate.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/shared_impl/resource.h"
14 #include "ppapi/shared_impl/tracked_callback.h"
15 #include "ppapi/thunk/enter.h"
16 #include "ppapi/thunk/ppb_talk_private_api.h"
17
18 namespace ppapi {
19 namespace proxy {
20
21 namespace {
22
23 class Talk : public Resource, public thunk::PPB_Talk_Private_API {
24 public:
25 Talk(PP_Instance instance) : Resource(OBJECT_IS_PROXY, instance) {
26 }
27
28 // Resource overrides.
29 thunk::PPB_Talk_Private_API* AsPPB_Talk_Private_API() { return this; }
30
31 // PPB_Talk_API implementation.
32 int32_t GetPermission(const PP_CompletionCallback& callback) {
33 if (TrackedCallback::IsPending(callback_))
34 return PP_ERROR_INPROGRESS;
35 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
36 pp_instance());
37 if (!dispatcher)
38 return PP_ERROR_FAILED;
39
40 callback_ = new TrackedCallback(this, callback);
41 dispatcher->Send(
42 new PpapiHostMsg_PPBTalk_GetPermission(
43 API_ID_PPB_TALK, pp_resource()));
44 return PP_OK_COMPLETIONPENDING;
45 }
46
47 void GotCompletion(int32_t result) {
48 TrackedCallback::ClearAndRun(&callback_, result);
49 }
50
51 private:
52 scoped_refptr<TrackedCallback> callback_;
53
54 DISALLOW_COPY_AND_ASSIGN(Talk);
55 };
56
57 PP_Resource Create(PP_Instance instance) {
58 return (new Talk(instance))->GetReference();
59 }
60
61 int32_t GetPermission(PP_Resource talk_resource,
62 PP_CompletionCallback callback) {
63 ppapi::EnterResource<PPB_Talk_API> enter(resource, callback, true);
64 if (enter.failed())
65 return enter.retval();
66 return enter.SetResult(enter.object()->GetPermission(callback));
67 }
68
69 const PPB_Talk_Private_1_0 talk_interface = {
70 &Create,
71 &GetPermission
72 };
73
74 } // namespace
75
76 PPB_Talk_Private_Proxy::PPB_Talk_Private_Proxy(Dispatcher* dispatcher)
77 : InterfaceProxy(dispatcher) {
78 }
79
80 // static
81 const PPB_Talk_Private_1_0* PPB_Talk_Private_Proxy::GetInterface() const {
82 return talk_interface;
83 }
84
85 bool PPB_Talk_Private_Proxy::OnMessageReceived(const IPC::Message& msg) {
86 bool handled = true;
87 IPC_BEGIN_MESSAGE_MAP(PPB_Talk_Private_Proxy, msg)
88 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTalk_GetPermission,
89 OnMsgGetPermission)
90 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTalk_GetPermissionACK,
91 OnMsgGetPermissionACK)
92 IPC_MESSAGE_UNHANDLED(handled = false);
93 IPC_END_MESSAGE_MAP();
94 return handled;
95 }
96
97 void PPB_Talk_Private_Proxy::OnMsgGetPermission(const HostResource& resource) {
98 // Add a completion callback factory and implement
99 EnterHostFromHostResourceForceCallback<thunk::PPB_Talk_Private_API> enter(
100 &factory_, // Need to add to this class
101 &OnGotPermission,
102 resource);
103 if (enter.succeeded())
104 // Copy another place that uses EnterHostFromHostResourceForceCallback
105 }
106
107 void PPB_Talk_Private_Proxy::OnMsgGetPermissionACK(const HostResource& resource,
108 int32_t result) {
109 thunk::EnterPluginFromHostResource<thunk::PPB_Talk_Private_API> enter(
110 resource, false);
111 if (enter.succeeded())
112 static_cast<Talk*>(enter.object())->GotCompletion(result);
113 }
114
115 OnGotPermission(int32_t result, const HostResource& resource) {
116 // Forward to the plugin process
117 Send(new ...ACK(result));
118 }
119 } // namespace proxy
120 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_talk_private_proxy.h ('k') | ppapi/proxy/resource_creation_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698