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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.h

Issue 9227008: WebSocket Pepper API: SRPC proxy implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase because two ppapi_proxy related CLs are landed Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_ 5 #ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_
6 #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_ 6 #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <map> 9 #include <map>
10 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" 10 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
11 #include "ppapi/c/pp_completion_callback.h" 11 #include "ppapi/c/pp_completion_callback.h"
12 #include "ppapi/c/pp_var.h"
12 13
13 namespace ppapi_proxy { 14 namespace ppapi_proxy {
14 15
15 // Skips callback invocation and returns |result| if callback function is NULL 16 // Skips callback invocation and returns |result| if callback function is NULL
16 // or PP_COMPLETIONCALLBACK_FLAG_OPTIONAL is set. Otherwise, schedules the 17 // or PP_COMPLETIONCALLBACK_FLAG_OPTIONAL is set. Otherwise, schedules the
17 // callback with |result| as an argument and returns PP_OK_COMPLETIONPENDING. 18 // callback with |result| as an argument and returns PP_OK_COMPLETIONPENDING.
18 int32_t MayForceCallback(PP_CompletionCallback callback, int32_t result); 19 int32_t MayForceCallback(PP_CompletionCallback callback, int32_t result);
19 20
20 // Maintains a table of PP_CompletionCallback objects and their respective 21 // Maintains a table of PP_CompletionCallback objects and their respective
21 // identifiers that can be used to retrieve the objects. 22 // identifiers that can be used to retrieve the objects.
22 class CompletionCallbackTable { 23 class CompletionCallbackTable {
23 public: 24 public:
24 // Return a singleton instance. 25 // Return a singleton instance.
25 static CompletionCallbackTable* Get() { 26 static CompletionCallbackTable* Get() {
26 static CompletionCallbackTable table; 27 static CompletionCallbackTable table;
27 return &table; 28 return &table;
28 } 29 }
29 30
30 // Adds the given |callback| and optionally the associated |read_buffer|, 31 // Adds the given |callback| and optionally the associated |read_buffer|,
31 // generating and returning an identifier for it. 32 // generating and returning an identifier for it.
32 // If |callback| is NULL, then returns 0. 33 // If |callback| is NULL, then returns 0.
33 int32_t AddCallback(const PP_CompletionCallback& callback); 34 int32_t AddCallback(const PP_CompletionCallback& callback);
34 int32_t AddCallback(const PP_CompletionCallback& callback, void* read_buffer); 35 int32_t AddCallback(const PP_CompletionCallback& callback, void* read_buffer);
36 int32_t AddCallback(const PP_CompletionCallback& callback, PP_Var* read_var);
35 // Removes and returns the callback and optionally the associated 37 // Removes and returns the callback and optionally the associated
36 // |read_buffer| corresponding to the given |callback_id|. 38 // |read_buffer| corresponding to the given |callback_id|.
37 // If no callback is found, returns a NULL callback. 39 // If no callback is found, returns a NULL callback.
38 PP_CompletionCallback RemoveCallback(int32_t callback_id, void** read_buffer); 40 PP_CompletionCallback RemoveCallback(
41 int32_t callback_id, void** read_buffer, PP_Var** read_var);
39 42
40 private: 43 private:
41 // Currently implemented as singleton, so use a private constructor. 44 // Currently implemented as singleton, so use a private constructor.
42 CompletionCallbackTable() : next_id_(1) { } 45 CompletionCallbackTable() : next_id_(1) { }
43 ~CompletionCallbackTable() { } 46 ~CompletionCallbackTable() { }
44 47
48 int32_t AddCallback(const PP_CompletionCallback& callback,
49 void* read_buffer,
50 PP_Var* read_var);
51
45 struct CallbackInfo { 52 struct CallbackInfo {
46 PP_CompletionCallback callback; 53 PP_CompletionCallback callback;
47 void* read_buffer; // To be used with callbacks invoked on byte reads. 54 void* read_buffer; // To be used with callbacks invoked on byte reads.
55 PP_Var* read_var; // To be used with callbacks invoked on PP_Var reads.
48 }; 56 };
49 57
50 typedef std::map<int32_t, CallbackInfo> CallbackTable; 58 typedef std::map<int32_t, CallbackInfo> CallbackTable;
51 CallbackTable table_; 59 CallbackTable table_;
52 int32_t next_id_; 60 int32_t next_id_;
53 61
54 // Single static mutex used as critical section for all callback tables. 62 // Single static mutex used as critical section for all callback tables.
55 static pthread_mutex_t mutex_; 63 static pthread_mutex_t mutex_;
56 class CallbackTableCriticalSection { 64 class CallbackTableCriticalSection {
57 public: 65 public:
58 CallbackTableCriticalSection() { pthread_mutex_lock(&mutex_); } 66 CallbackTableCriticalSection() { pthread_mutex_lock(&mutex_); }
59 ~CallbackTableCriticalSection() { pthread_mutex_unlock(&mutex_); } 67 ~CallbackTableCriticalSection() { pthread_mutex_unlock(&mutex_); }
60 }; 68 };
61 }; 69 };
62 70
63 } // namespace ppapi_proxy 71 } // namespace ppapi_proxy
64 72
65 #endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_ 73 #endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_CALLBACK_H_
OLDNEW
« no previous file with comments | « ppapi/native_client/src/shared/ppapi_proxy/nacl.scons ('k') | ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698