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

Side by Side Diff: ppapi/proxy/resource_message_params.h

Issue 10560030: Add resource message call and reply infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
(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 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
6 #define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
7
8 #include "ipc/ipc_message_utils.h"
9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/proxy/ppapi_proxy_export.h"
11
12 namespace ppapi {
13 namespace proxy {
14
15 // Common parameters for call and reply params.
bbudge 2012/06/18 17:23:47 // Common parameters for resource call and reply m
16 class PPAPI_PROXY_EXPORT ResourceMessageParams {
17 public:
18 virtual ~ResourceMessageParams();
19
20 PP_Resource pp_resource() const { return pp_resource_; }
21 int32_t sequence() const { return sequence_; }
22
23 protected:
24 ResourceMessageParams();
25 ResourceMessageParams(PP_Resource resource, int32_t sequence);
26
27 virtual void Serialize(IPC::Message* msg) const;
28 virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter);
29
30 private:
31 PP_Resource pp_resource_;
32
33 // Identifier for this message. Sequence numbers are quasi-unique within a
34 // resource, but will overlap between different resource objects.
35 //
36 // If you send a lot of messages, the ID may wrap around. This is OK. All IDs
37 // are valid and 0 and -1 aren't special, so those cases won't confuse us.
38 // In practice, if you send more than 4 billion messages for a resource, the
39 // old ones will be long gone and there will be no collisions.
40 //
41 // If there is a malicious plugin (or exceptionally bad luck) that causes a
42 // wraparound and collision the worst that will happen is that we can get
43 // confused between different callbacks. But since these can only cause
44 // confusion within the plugin and within callbacks on the same resoruce,
bbudge 2012/06/18 17:23:47 sp. resource
45 // there shouldn't be a security problem.
46 int32_t sequence_;
47 };
48
49 // Parameters common to all ResourceMessage "Call" requests.
50 class PPAPI_PROXY_EXPORT ResourceMessageCallParams
51 : public ResourceMessageParams {
52 public:
53 ResourceMessageCallParams();
54 ResourceMessageCallParams(PP_Resource resource, int32_t sequence);
55 virtual ~ResourceMessageCallParams();
56
57 void set_has_callback() { flags_ |= kFlagHasCallback; }
58 bool has_callback() const { return flags_ & kFlagHasCallback; }
59
60 virtual void Serialize(IPC::Message* msg) const OVERRIDE;
61 virtual bool Deserialize(const IPC::Message* msg,
62 PickleIterator* iter) OVERRIDE;
63
64 private:
65 uint32 flags_;
66
67 // Values used in the |flags| bitfield of ResourceRequest message.
68 static const unsigned kFlagHasCallback = 1 << 0;
bbudge 2012/06/18 17:23:47 I'm wondering why this isn't just a bool. Will the
69 };
70
71 // Parameters common to all ResourceMessage "Reply" requests.
72 class PPAPI_PROXY_EXPORT ResourceMessageReplyParams
73 : public ResourceMessageParams {
74 public:
75 ResourceMessageReplyParams();
76 ResourceMessageReplyParams(PP_Resource resource, int32_t sequence);
77 virtual ~ResourceMessageReplyParams();
78
79 void set_result(int32_t r) { result_ = r; }
80 int32_t result() const { return result_; }
81
82 virtual void Serialize(IPC::Message* msg) const OVERRIDE;
83 virtual bool Deserialize(const IPC::Message* msg,
84 PickleIterator* iter) OVERRIDE;
85
86 private:
87 // Pepper "result code" for the callback.
88 int32_t result_;
89 };
90
91 } // namespace proxy
92 } // namespace ppapi
93
94 namespace IPC {
95
bbudge 2012/06/18 17:23:47 Is it typical for components that use IPC to put t
brettw 2012/06/18 17:33:53 This is a template specialization so it has to be
96 template <> struct PPAPI_PROXY_EXPORT
97 ParamTraits<ppapi::proxy::ResourceMessageCallParams> {
98 typedef ppapi::proxy::ResourceMessageCallParams param_type;
99 static void Write(Message* m, const param_type& p) {
100 p.Serialize(m);
101 }
102 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
103 return r->Deserialize(m, iter);
104 }
105 static void Log(const param_type& p, std::string* l) {
106 }
107 };
108
109 template <> struct PPAPI_PROXY_EXPORT
110 ParamTraits<ppapi::proxy::ResourceMessageReplyParams> {
111 typedef ppapi::proxy::ResourceMessageReplyParams param_type;
112 static void Write(Message* m, const param_type& p) {
113 p.Serialize(m);
114 }
115 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
116 return r->Deserialize(m, iter);
117 }
118 static void Log(const param_type& p, std::string* l) {
119 }
120 };
121
122 } // namespace IPC
123
124 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698