OLD | NEW |
1 // Copyright (c) 2012 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 PPAPI_PROXY_SERIALIZED_VAR_H_ | 5 #ifndef PPAPI_PROXY_SERIALIZED_VAR_H_ |
6 #define PPAPI_PROXY_SERIALIZED_VAR_H_ | 6 #define PPAPI_PROXY_SERIALIZED_VAR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // behavior and will enforce that you don't do stupid things. | 73 // behavior and will enforce that you don't do stupid things. |
74 class PPAPI_PROXY_EXPORT SerializedVar { | 74 class PPAPI_PROXY_EXPORT SerializedVar { |
75 public: | 75 public: |
76 SerializedVar(); | 76 SerializedVar(); |
77 ~SerializedVar(); | 77 ~SerializedVar(); |
78 | 78 |
79 // Backend implementation for IPC::ParamTraits<SerializedVar>. | 79 // Backend implementation for IPC::ParamTraits<SerializedVar>. |
80 void WriteToMessage(IPC::Message* m) const { | 80 void WriteToMessage(IPC::Message* m) const { |
81 inner_->WriteToMessage(m); | 81 inner_->WriteToMessage(m); |
82 } | 82 } |
| 83 // If ReadFromMessage has been called, WriteDataToMessage will write the var |
| 84 // that has been read from ReadFromMessage back to a message. This is used |
| 85 // when converting handles for use in NaCl. |
| 86 void WriteDataToMessage(IPC::Message* m, |
| 87 const HandleWriter& handle_writer) const { |
| 88 inner_->WriteDataToMessage(m, handle_writer); |
| 89 } |
83 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter) { | 90 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter) { |
84 return inner_->ReadFromMessage(m, iter); | 91 return inner_->ReadFromMessage(m, iter); |
85 } | 92 } |
86 | 93 |
87 RawVarDataGraph* raw_var_data() const { | 94 bool is_valid_var() const { |
88 return inner_->raw_var_data(); | 95 return inner_->is_valid_var(); |
| 96 } |
| 97 |
| 98 // Returns the shared memory handles associated with this SerializedVar. |
| 99 std::vector<SerializedHandle*> GetHandles() const { |
| 100 return inner_->GetHandles(); |
89 } | 101 } |
90 | 102 |
91 protected: | 103 protected: |
92 friend class SerializedVarReceiveInput; | 104 friend class SerializedVarReceiveInput; |
93 friend class SerializedVarReturnValue; | 105 friend class SerializedVarReturnValue; |
94 friend class SerializedVarOutParam; | 106 friend class SerializedVarOutParam; |
95 friend class SerializedVarSendInput; | 107 friend class SerializedVarSendInput; |
96 friend class SerializedVarSendInputShmem; | 108 friend class SerializedVarSendInputShmem; |
97 friend class SerializedVarTestConstructor; | 109 friend class SerializedVarTestConstructor; |
98 friend class SerializedVarVectorReceiveInput; | 110 friend class SerializedVarVectorReceiveInput; |
99 | 111 |
100 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> { | 112 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> { |
101 public: | 113 public: |
102 Inner(); | 114 Inner(); |
103 Inner(VarSerializationRules* serialization_rules); | 115 Inner(VarSerializationRules* serialization_rules); |
104 ~Inner(); | 116 ~Inner(); |
105 | 117 |
106 VarSerializationRules* serialization_rules() { | 118 VarSerializationRules* serialization_rules() { |
107 return serialization_rules_.get(); | 119 return serialization_rules_.get(); |
108 } | 120 } |
109 void set_serialization_rules(VarSerializationRules* serialization_rules) { | 121 void set_serialization_rules(VarSerializationRules* serialization_rules) { |
110 serialization_rules_ = serialization_rules; | 122 serialization_rules_ = serialization_rules; |
111 } | 123 } |
112 | 124 |
113 RawVarDataGraph* raw_var_data() { | 125 bool is_valid_var() const { |
114 return raw_var_data_.get(); | 126 return is_valid_var_; |
| 127 } |
| 128 |
| 129 std::vector<SerializedHandle*> GetHandles() { |
| 130 return (raw_var_data_ ? raw_var_data_->GetHandles() : |
| 131 std::vector<SerializedHandle*>()); |
115 } | 132 } |
116 | 133 |
117 // See outer class's declarations above. | 134 // See outer class's declarations above. |
118 PP_Var GetVar(); | 135 PP_Var GetVar(); |
119 void SetVar(PP_Var var); | 136 void SetVar(PP_Var var); |
120 void SetInstance(PP_Instance instance); | 137 void SetInstance(PP_Instance instance); |
121 | 138 |
122 // For the SerializedVarTestConstructor, this writes the Var value as if | 139 // For the SerializedVarTestConstructor, this writes the Var value as if |
123 // it was just received off the wire, without any serialization rules. | 140 // it was just received off the wire, without any serialization rules. |
124 void ForceSetVarValueForTest(PP_Var value); | 141 void ForceSetVarValueForTest(PP_Var value); |
125 | 142 |
126 void WriteToMessage(IPC::Message* m) const; | 143 void WriteToMessage(IPC::Message* m) const; |
| 144 void WriteDataToMessage(IPC::Message* m, |
| 145 const HandleWriter& handle_writer) const; |
127 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter); | 146 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter); |
128 | 147 |
129 // Sets the cleanup mode. See the CleanupMode enum below. | 148 // Sets the cleanup mode. See the CleanupMode enum below. |
130 void SetCleanupModeToEndSendPassRef(); | 149 void SetCleanupModeToEndSendPassRef(); |
131 void SetCleanupModeToEndReceiveCallerOwned(); | 150 void SetCleanupModeToEndReceiveCallerOwned(); |
132 | 151 |
133 private: | 152 private: |
134 enum CleanupMode { | 153 enum CleanupMode { |
135 // The serialized var won't do anything special in the destructor | 154 // The serialized var won't do anything special in the destructor |
136 // (default). | 155 // (default). |
(...skipping 18 matching lines...) Expand all Loading... |
155 // | 174 // |
156 // This var may not be complete until the serialization rules are set when | 175 // This var may not be complete until the serialization rules are set when |
157 // reading from IPC since we'll need that to convert the string_value to | 176 // reading from IPC since we'll need that to convert the string_value to |
158 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. | 177 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. |
159 PP_Var var_; | 178 PP_Var var_; |
160 | 179 |
161 PP_Instance instance_; | 180 PP_Instance instance_; |
162 | 181 |
163 CleanupMode cleanup_mode_; | 182 CleanupMode cleanup_mode_; |
164 | 183 |
| 184 // If the var is not properly serialized, this will be false. |
| 185 bool is_valid_var_; |
| 186 |
165 #ifndef NDEBUG | 187 #ifndef NDEBUG |
166 // When being sent or received over IPC, we should only be serialized or | 188 // When being sent or received over IPC, we should only be serialized or |
167 // deserialized once. These flags help us assert this is true. | 189 // deserialized once. These flags help us assert this is true. |
168 mutable bool has_been_serialized_; | 190 mutable bool has_been_serialized_; |
169 mutable bool has_been_deserialized_; | 191 mutable bool has_been_deserialized_; |
170 #endif | 192 #endif |
171 | 193 |
172 // ReadFromMessage() may be called on the I/O thread, e.g., when reading the | 194 // ReadFromMessage() may be called on the I/O thread, e.g., when reading the |
173 // reply to a sync message. We cannot use the var tracker on the I/O thread, | 195 // reply to a sync message. We cannot use the var tracker on the I/O thread, |
174 // which means we cannot create some types of PP_Var | 196 // which means we cannot create some types of PP_Var |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 class PPAPI_PROXY_EXPORT SerializedVarReceiveInput { | 357 class PPAPI_PROXY_EXPORT SerializedVarReceiveInput { |
336 public: | 358 public: |
337 // We rely on the implicit constructor here since the IPC layer will call | 359 // We rely on the implicit constructor here since the IPC layer will call |
338 // us with a SerializedVar. Pass this object by value, the copy constructor | 360 // us with a SerializedVar. Pass this object by value, the copy constructor |
339 // will pass along the pointer (as cheap as passing a pointer arg). | 361 // will pass along the pointer (as cheap as passing a pointer arg). |
340 SerializedVarReceiveInput(const SerializedVar& serialized); | 362 SerializedVarReceiveInput(const SerializedVar& serialized); |
341 ~SerializedVarReceiveInput(); | 363 ~SerializedVarReceiveInput(); |
342 | 364 |
343 PP_Var Get(Dispatcher* dispatcher); | 365 PP_Var Get(Dispatcher* dispatcher); |
344 PP_Var GetForInstance(Dispatcher* dispatcher, PP_Instance instance); | 366 PP_Var GetForInstance(Dispatcher* dispatcher, PP_Instance instance); |
| 367 bool is_valid_var() { return serialized_.is_valid_var(); } |
345 | 368 |
346 private: | 369 private: |
347 const SerializedVar& serialized_; | 370 const SerializedVar& serialized_; |
348 }; | 371 }; |
349 | 372 |
350 // For receiving an input vector of vars from the remote side. | 373 // For receiving an input vector of vars from the remote side. |
351 // | 374 // |
352 // Example: | 375 // Example: |
353 // OnMsgMyFunction(SerializedVarVectorReceiveInput vector) { | 376 // OnMsgMyFunction(SerializedVarVectorReceiveInput vector) { |
354 // uint32_t size; | 377 // uint32_t size; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 public: | 493 public: |
471 explicit SerializedVarTestReader(const SerializedVar& var); | 494 explicit SerializedVarTestReader(const SerializedVar& var); |
472 | 495 |
473 PP_Var GetVar() const { return inner_->GetVar(); } | 496 PP_Var GetVar() const { return inner_->GetVar(); } |
474 }; | 497 }; |
475 | 498 |
476 } // namespace proxy | 499 } // namespace proxy |
477 } // namespace ppapi | 500 } // namespace ppapi |
478 | 501 |
479 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ | 502 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ |
OLD | NEW |