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

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

Issue 9786001: Avoid accessing VarTracker from multiple threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.cc ('k') | ppapi/proxy/serialized_var.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ~Inner(); 94 ~Inner();
95 95
96 VarSerializationRules* serialization_rules() { 96 VarSerializationRules* serialization_rules() {
97 return serialization_rules_; 97 return serialization_rules_;
98 } 98 }
99 void set_serialization_rules(VarSerializationRules* serialization_rules) { 99 void set_serialization_rules(VarSerializationRules* serialization_rules) {
100 serialization_rules_ = serialization_rules; 100 serialization_rules_ = serialization_rules;
101 } 101 }
102 102
103 // See outer class's declarations above. 103 // See outer class's declarations above.
104 PP_Var GetVar() const; 104 PP_Var GetVar();
105 void SetVar(PP_Var var); 105 void SetVar(PP_Var var);
106 106
107 // For the SerializedVarTestConstructor, this writes the Var value as if 107 // For the SerializedVarTestConstructor, this writes the Var value as if
108 // it was just received off the wire, without any serialization rules. 108 // it was just received off the wire, without any serialization rules.
109 void ForceSetVarValueForTest(PP_Var value); 109 void ForceSetVarValueForTest(PP_Var value);
110 110
111 void WriteToMessage(IPC::Message* m) const; 111 void WriteToMessage(IPC::Message* m) const;
112 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter); 112 bool ReadFromMessage(const IPC::Message* m, PickleIterator* iter);
113 113
114 // Sets the cleanup mode. See the CleanupMode enum below. 114 // Sets the cleanup mode. See the CleanupMode enum below.
115 void SetCleanupModeToEndSendPassRef(); 115 void SetCleanupModeToEndSendPassRef();
116 void SetCleanupModeToEndReceiveCallerOwned(); 116 void SetCleanupModeToEndReceiveCallerOwned();
117 117
118 private: 118 private:
119 enum CleanupMode { 119 enum CleanupMode {
120 // The serialized var won't do anything special in the destructor 120 // The serialized var won't do anything special in the destructor
121 // (default). 121 // (default).
122 CLEANUP_NONE, 122 CLEANUP_NONE,
123 123
124 // The serialized var will call EndSendPassRef in the destructor. 124 // The serialized var will call EndSendPassRef in the destructor.
125 END_SEND_PASS_REF, 125 END_SEND_PASS_REF,
126 126
127 // The serialized var will call EndReceiveCallerOwned in the destructor. 127 // The serialized var will call EndReceiveCallerOwned in the destructor.
128 END_RECEIVE_CALLER_OWNED 128 END_RECEIVE_CALLER_OWNED
129 }; 129 };
130 130
131 // ReadFromMessage() may be called on the I/O thread, e.g., when reading the
132 // reply to a sync message. We cannot use the var tracker on the I/O thread,
133 // which means we cannot create PP_Var for PP_VARTYPE_STRING and
134 // PP_VARTYPE_ARRAY_BUFFER in ReadFromMessage(). So we save the raw var data
135 // and create PP_Var later when GetVar() is called, which should happen on
136 // the main thread.
137 struct RawVarData {
138 PP_VarType type;
139 std::string data;
140 };
141
142 // Converts |raw_var_data_| to |var_|. It is a no-op if |raw_var_data_| is
143 // NULL.
144 void ConvertRawVarData();
145
131 // Rules for serializing and deserializing vars for this process type. 146 // Rules for serializing and deserializing vars for this process type.
132 // This may be NULL, but must be set before trying to serialize to IPC when 147 // This may be NULL, but must be set before trying to serialize to IPC when
133 // sending, or before converting back to a PP_Var when receiving. 148 // sending, or before converting back to a PP_Var when receiving.
134 scoped_refptr<VarSerializationRules> serialization_rules_; 149 scoped_refptr<VarSerializationRules> serialization_rules_;
135 150
136 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the 151 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the
137 // string_from_ipc_ holds the string. This means that the caller hasn't 152 // string_from_ipc_ holds the string. This means that the caller hasn't
138 // called Deserialize with a valid Dispatcher yet, which is how we can 153 // called Deserialize with a valid Dispatcher yet, which is how we can
139 // convert the serialized string value to a PP_Var string ID. 154 // convert the serialized string value to a PP_Var string ID.
140 // 155 //
141 // This var may not be complete until the serialization rules are set when 156 // This var may not be complete until the serialization rules are set when
142 // reading from IPC since we'll need that to convert the string_value to 157 // reading from IPC since we'll need that to convert the string_value to
143 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. 158 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING.
144 PP_Var var_; 159 PP_Var var_;
145 160
146 CleanupMode cleanup_mode_; 161 CleanupMode cleanup_mode_;
147 162
148 #ifndef NDEBUG 163 #ifndef NDEBUG
149 // When being sent or received over IPC, we should only be serialized or 164 // When being sent or received over IPC, we should only be serialized or
150 // deserialized once. These flags help us assert this is true. 165 // deserialized once. These flags help us assert this is true.
151 mutable bool has_been_serialized_; 166 mutable bool has_been_serialized_;
152 mutable bool has_been_deserialized_; 167 mutable bool has_been_deserialized_;
153 #endif 168 #endif
154 169
170 // It will be non-NULL if there is PP_VARTYPE_STRING or
171 // PP_VARTYPE_ARRAY_BUFFER data from ReadFromMessage() that hasn't been
172 // converted to PP_Var.
173 scoped_ptr<RawVarData> raw_var_data_;
174
155 DISALLOW_COPY_AND_ASSIGN(Inner); 175 DISALLOW_COPY_AND_ASSIGN(Inner);
156 }; 176 };
157 177
158 SerializedVar(VarSerializationRules* serialization_rules); 178 SerializedVar(VarSerializationRules* serialization_rules);
159 179
160 mutable scoped_refptr<Inner> inner_; 180 mutable scoped_refptr<Inner> inner_;
161 }; 181 };
162 182
163 // Helpers for message sending side -------------------------------------------- 183 // Helpers for message sending side --------------------------------------------
164 184
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // The "incomplete" var is the one sent over the wire. Strings and object 455 // The "incomplete" var is the one sent over the wire. Strings and object
436 // IDs have not yet been converted, so this is the thing that tests will 456 // IDs have not yet been converted, so this is the thing that tests will
437 // actually want to check. 457 // actually want to check.
438 PP_Var GetVar() const { return inner_->GetVar(); } 458 PP_Var GetVar() const { return inner_->GetVar(); }
439 }; 459 };
440 460
441 } // namespace proxy 461 } // namespace proxy
442 } // namespace ppapi 462 } // namespace ppapi
443 463
444 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ 464 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.cc ('k') | ppapi/proxy/serialized_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698