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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter) { | 83 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter) { |
84 return inner_->ReadFromMessage(m, iter); | 84 return inner_->ReadFromMessage(m, iter); |
85 } | 85 } |
86 | 86 |
| 87 bool is_valid_var() const { |
| 88 return inner_->is_valid_var(); |
| 89 } |
| 90 |
87 RawVarDataGraph* raw_var_data() const { | 91 RawVarDataGraph* raw_var_data() const { |
88 return inner_->raw_var_data(); | 92 return inner_->raw_var_data(); |
89 } | 93 } |
90 | 94 |
91 protected: | 95 protected: |
92 friend class SerializedVarReceiveInput; | 96 friend class SerializedVarReceiveInput; |
93 friend class SerializedVarReturnValue; | 97 friend class SerializedVarReturnValue; |
94 friend class SerializedVarOutParam; | 98 friend class SerializedVarOutParam; |
95 friend class SerializedVarSendInput; | 99 friend class SerializedVarSendInput; |
96 friend class SerializedVarSendInputShmem; | 100 friend class SerializedVarSendInputShmem; |
97 friend class SerializedVarTestConstructor; | 101 friend class SerializedVarTestConstructor; |
98 friend class SerializedVarVectorReceiveInput; | 102 friend class SerializedVarVectorReceiveInput; |
99 | 103 |
100 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> { | 104 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> { |
101 public: | 105 public: |
102 Inner(); | 106 Inner(); |
103 Inner(VarSerializationRules* serialization_rules); | 107 Inner(VarSerializationRules* serialization_rules); |
104 ~Inner(); | 108 ~Inner(); |
105 | 109 |
106 VarSerializationRules* serialization_rules() { | 110 VarSerializationRules* serialization_rules() { |
107 return serialization_rules_.get(); | 111 return serialization_rules_.get(); |
108 } | 112 } |
109 void set_serialization_rules(VarSerializationRules* serialization_rules) { | 113 void set_serialization_rules(VarSerializationRules* serialization_rules) { |
110 serialization_rules_ = serialization_rules; | 114 serialization_rules_ = serialization_rules; |
111 } | 115 } |
112 | 116 |
| 117 bool is_valid_var() const { |
| 118 return is_valid_var_; |
| 119 } |
| 120 |
113 RawVarDataGraph* raw_var_data() { | 121 RawVarDataGraph* raw_var_data() { |
114 return raw_var_data_.get(); | 122 return raw_var_data_.get(); |
115 } | 123 } |
116 | 124 |
117 // See outer class's declarations above. | 125 // See outer class's declarations above. |
118 PP_Var GetVar(); | 126 PP_Var GetVar(); |
119 void SetVar(PP_Var var); | 127 void SetVar(PP_Var var); |
120 void SetInstance(PP_Instance instance); | 128 void SetInstance(PP_Instance instance); |
121 | 129 |
122 // For the SerializedVarTestConstructor, this writes the Var value as if | 130 // For the SerializedVarTestConstructor, this writes the Var value as if |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // | 163 // |
156 // This var may not be complete until the serialization rules are set when | 164 // 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 | 165 // 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. | 166 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. |
159 PP_Var var_; | 167 PP_Var var_; |
160 | 168 |
161 PP_Instance instance_; | 169 PP_Instance instance_; |
162 | 170 |
163 CleanupMode cleanup_mode_; | 171 CleanupMode cleanup_mode_; |
164 | 172 |
| 173 // If the var is not properly serialized, this will be false. |
| 174 bool is_valid_var_; |
| 175 |
165 #ifndef NDEBUG | 176 #ifndef NDEBUG |
166 // When being sent or received over IPC, we should only be serialized or | 177 // When being sent or received over IPC, we should only be serialized or |
167 // deserialized once. These flags help us assert this is true. | 178 // deserialized once. These flags help us assert this is true. |
168 mutable bool has_been_serialized_; | 179 mutable bool has_been_serialized_; |
169 mutable bool has_been_deserialized_; | 180 mutable bool has_been_deserialized_; |
170 #endif | 181 #endif |
171 | 182 |
172 // ReadFromMessage() may be called on the I/O thread, e.g., when reading the | 183 // 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, | 184 // 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 | 185 // 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 { | 346 class PPAPI_PROXY_EXPORT SerializedVarReceiveInput { |
336 public: | 347 public: |
337 // We rely on the implicit constructor here since the IPC layer will call | 348 // 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 | 349 // 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). | 350 // will pass along the pointer (as cheap as passing a pointer arg). |
340 SerializedVarReceiveInput(const SerializedVar& serialized); | 351 SerializedVarReceiveInput(const SerializedVar& serialized); |
341 ~SerializedVarReceiveInput(); | 352 ~SerializedVarReceiveInput(); |
342 | 353 |
343 PP_Var Get(Dispatcher* dispatcher); | 354 PP_Var Get(Dispatcher* dispatcher); |
344 PP_Var GetForInstance(Dispatcher* dispatcher, PP_Instance instance); | 355 PP_Var GetForInstance(Dispatcher* dispatcher, PP_Instance instance); |
| 356 bool is_valid_var() { return serialized_.is_valid_var(); } |
345 | 357 |
346 private: | 358 private: |
347 const SerializedVar& serialized_; | 359 const SerializedVar& serialized_; |
348 }; | 360 }; |
349 | 361 |
350 // For receiving an input vector of vars from the remote side. | 362 // For receiving an input vector of vars from the remote side. |
351 // | 363 // |
352 // Example: | 364 // Example: |
353 // OnMsgMyFunction(SerializedVarVectorReceiveInput vector) { | 365 // OnMsgMyFunction(SerializedVarVectorReceiveInput vector) { |
354 // uint32_t size; | 366 // uint32_t size; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 public: | 482 public: |
471 explicit SerializedVarTestReader(const SerializedVar& var); | 483 explicit SerializedVarTestReader(const SerializedVar& var); |
472 | 484 |
473 PP_Var GetVar() const { return inner_->GetVar(); } | 485 PP_Var GetVar() const { return inner_->GetVar(); } |
474 }; | 486 }; |
475 | 487 |
476 } // namespace proxy | 488 } // namespace proxy |
477 } // namespace ppapi | 489 } // namespace ppapi |
478 | 490 |
479 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ | 491 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ |
OLD | NEW |