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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 VarSerializationRules* serialization_rules() { | 93 VarSerializationRules* serialization_rules() { |
94 return serialization_rules_; | 94 return serialization_rules_; |
95 } | 95 } |
96 void set_serialization_rules(VarSerializationRules* serialization_rules) { | 96 void set_serialization_rules(VarSerializationRules* serialization_rules) { |
97 serialization_rules_ = serialization_rules; | 97 serialization_rules_ = serialization_rules; |
98 } | 98 } |
99 | 99 |
100 // See outer class's declarations above. | 100 // See outer class's declarations above. |
101 PP_Var GetVar() const; | 101 PP_Var GetVar() const; |
102 PP_Var GetIncompleteVar() const; | |
103 void SetVar(PP_Var var); | 102 void SetVar(PP_Var var); |
104 void SetString(scoped_ptr<std::string> str); | |
105 // Return a new string with the contents of the string referenced by Inner. | |
106 // The string referenced by the Inner will be empty after this. | |
107 scoped_ptr<std::string> GetStringDestructive(); | |
108 // Return a pointer to our internal string pointer. This is so that the | |
109 // caller will be able to make this Inner point to a string that's owned | |
110 // elsewhere (i.e., in the tracker). | |
111 const std::string** GetStringPtrPtr(); | |
112 | 103 |
113 // For the SerializedVarTestConstructor, this writes the Var value as if | 104 // For the SerializedVarTestConstructor, this writes the Var value as if |
114 // it was just received off the wire, without any serialization rules. | 105 // it was just received off the wire, without any serialization rules. |
115 void ForceSetVarValueForTest(PP_Var value); | 106 void ForceSetVarValueForTest(PP_Var value); |
116 void ForceSetStringValueForTest(const std::string& str); | |
117 | 107 |
118 void WriteToMessage(IPC::Message* m) const; | 108 void WriteToMessage(IPC::Message* m) const; |
119 bool ReadFromMessage(const IPC::Message* m, void** iter); | 109 bool ReadFromMessage(const IPC::Message* m, void** iter); |
120 | 110 |
121 // Sets the cleanup mode. See the CleanupMode enum below. These functions | 111 // Sets the cleanup mode. See the CleanupMode enum below. These functions |
122 // are not just a simple setter in order to require that the appropriate | 112 // are not just a simple setter in order to require that the appropriate |
123 // data is set along with the corresponding mode. | 113 // data is set along with the corresponding mode. |
124 void SetCleanupModeToEndSendPassRef(Dispatcher* dispatcher); | 114 void SetCleanupModeToEndSendPassRef(Dispatcher* dispatcher); |
125 void SetCleanupModeToEndReceiveCallerOwned(); | 115 void SetCleanupModeToEndReceiveCallerOwned(); |
126 | 116 |
(...skipping 18 matching lines...) Expand all Loading... |
145 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the | 135 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the |
146 // string_from_ipc_ holds the string. This means that the caller hasn't | 136 // string_from_ipc_ holds the string. This means that the caller hasn't |
147 // called Deserialize with a valid Dispatcher yet, which is how we can | 137 // called Deserialize with a valid Dispatcher yet, which is how we can |
148 // convert the serialized string value to a PP_Var string ID. | 138 // convert the serialized string value to a PP_Var string ID. |
149 // | 139 // |
150 // This var may not be complete until the serialization rules are set when | 140 // This var may not be complete until the serialization rules are set when |
151 // reading from IPC since we'll need that to convert the string_value to | 141 // reading from IPC since we'll need that to convert the string_value to |
152 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. | 142 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. |
153 PP_Var var_; | 143 PP_Var var_; |
154 | 144 |
155 // If valid, this is a pointer to a string owned by the VarTracker. When our | |
156 // outer SerializedVar gets serialized, it will write the string directly | |
157 // from the tracker so we do not need to make any unnecessary copies. This | |
158 // should only be valid on the sender side. | |
159 const std::string* tracker_string_ptr_; | |
160 | |
161 // If valid, this is a string received from IPC which needs to be inserted | |
162 // in to the var tracker. When we provide it to the tracker, we pass | |
163 // ownership so that there are no unnecessary copies. This should only ever | |
164 // be valid on the receiver side. | |
165 scoped_ptr<std::string> string_from_ipc_; | |
166 | |
167 CleanupMode cleanup_mode_; | 145 CleanupMode cleanup_mode_; |
168 | 146 |
169 // The dispatcher saved for the call to EndSendPassRef for the cleanup. | 147 // The dispatcher saved for the call to EndSendPassRef for the cleanup. |
170 // This is only valid when cleanup_mode == END_SEND_PASS_REF. | 148 // This is only valid when cleanup_mode == END_SEND_PASS_REF. |
171 Dispatcher* dispatcher_for_end_send_pass_ref_; | 149 Dispatcher* dispatcher_for_end_send_pass_ref_; |
172 | 150 |
173 #ifndef NDEBUG | 151 #ifndef NDEBUG |
174 // When being sent or received over IPC, we should only be serialized or | 152 // When being sent or received over IPC, we should only be serialized or |
175 // deserialized once. These flags help us assert this is true. | 153 // deserialized once. These flags help us assert this is true. |
176 mutable bool has_been_serialized_; | 154 mutable bool has_been_serialized_; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 }; | 435 }; |
458 | 436 |
459 // For tests that want to read what's in a SerializedVar. | 437 // For tests that want to read what's in a SerializedVar. |
460 class PPAPI_PROXY_EXPORT SerializedVarTestReader : public SerializedVar { | 438 class PPAPI_PROXY_EXPORT SerializedVarTestReader : public SerializedVar { |
461 public: | 439 public: |
462 explicit SerializedVarTestReader(const SerializedVar& var); | 440 explicit SerializedVarTestReader(const SerializedVar& var); |
463 | 441 |
464 // The "incomplete" var is the one sent over the wire. Strings and object | 442 // The "incomplete" var is the one sent over the wire. Strings and object |
465 // IDs have not yet been converted, so this is the thing that tests will | 443 // IDs have not yet been converted, so this is the thing that tests will |
466 // actually want to check. | 444 // actually want to check. |
467 PP_Var GetIncompleteVar() const { return inner_->GetIncompleteVar(); } | 445 PP_Var GetVar() const { return inner_->GetVar(); } |
468 | |
469 const std::string* GetTrackerStringPtr() const { | |
470 return *inner_->GetStringPtrPtr(); | |
471 } | |
472 }; | 446 }; |
473 | 447 |
474 } // namespace proxy | 448 } // namespace proxy |
475 } // namespace ppapi | 449 } // namespace ppapi |
476 | 450 |
477 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ | 451 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ |
478 | 452 |
OLD | NEW |