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 #include "ppapi/proxy/serialized_var.h" | 5 #include "ppapi/proxy/serialized_var.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ipc/ipc_message_utils.h" | 8 #include "ipc/ipc_message_utils.h" |
9 #include "ppapi/c/pp_instance.h" | 9 #include "ppapi/c/pp_instance.h" |
10 #include "ppapi/proxy/dispatcher.h" | 10 #include "ppapi/proxy/dispatcher.h" |
11 #include "ppapi/proxy/interface_proxy.h" | 11 #include "ppapi/proxy/interface_proxy.h" |
12 #include "ppapi/proxy/ppapi_param_traits.h" | 12 #include "ppapi/proxy/ppapi_param_traits.h" |
13 #include "ppapi/proxy/ppb_buffer_proxy.h" | 13 #include "ppapi/proxy/ppb_buffer_proxy.h" |
14 #include "ppapi/shared_impl/ppapi_globals.h" | 14 #include "ppapi/shared_impl/ppapi_globals.h" |
15 #include "ppapi/shared_impl/var.h" | 15 #include "ppapi/shared_impl/var.h" |
16 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
17 | 17 |
18 namespace ppapi { | 18 namespace ppapi { |
19 namespace proxy { | 19 namespace proxy { |
20 | 20 |
| 21 namespace { |
| 22 void DefaultHandleWriter(IPC::Message* m, const SerializedHandle& handle) { |
| 23 IPC::ParamTraits<SerializedHandle>::Write(m, handle); |
| 24 } |
| 25 } // namespace |
| 26 |
21 // SerializedVar::Inner -------------------------------------------------------- | 27 // SerializedVar::Inner -------------------------------------------------------- |
22 | 28 |
23 SerializedVar::Inner::Inner() | 29 SerializedVar::Inner::Inner() |
24 : serialization_rules_(NULL), | 30 : serialization_rules_(NULL), |
25 var_(PP_MakeUndefined()), | 31 var_(PP_MakeUndefined()), |
26 instance_(0), | 32 instance_(0), |
27 cleanup_mode_(CLEANUP_NONE) { | 33 cleanup_mode_(CLEANUP_NONE), |
| 34 is_valid_var_(true) { |
28 #ifndef NDEBUG | 35 #ifndef NDEBUG |
29 has_been_serialized_ = false; | 36 has_been_serialized_ = false; |
30 has_been_deserialized_ = false; | 37 has_been_deserialized_ = false; |
31 #endif | 38 #endif |
32 } | 39 } |
33 | 40 |
34 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) | 41 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) |
35 : serialization_rules_(serialization_rules), | 42 : serialization_rules_(serialization_rules), |
36 var_(PP_MakeUndefined()), | 43 var_(PP_MakeUndefined()), |
37 instance_(0), | 44 instance_(0), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // that returns a var. This means the message handler didn't write to the | 107 // that returns a var. This means the message handler didn't write to the |
101 // output parameter, or possibly you used the wrong helper class | 108 // output parameter, or possibly you used the wrong helper class |
102 // (normally SerializedVarReturnValue). | 109 // (normally SerializedVarReturnValue). |
103 DCHECK(serialization_rules_.get()); | 110 DCHECK(serialization_rules_.get()); |
104 | 111 |
105 #ifndef NDEBUG | 112 #ifndef NDEBUG |
106 // We should only be serializing something once. | 113 // We should only be serializing something once. |
107 DCHECK(!has_been_serialized_); | 114 DCHECK(!has_been_serialized_); |
108 has_been_serialized_ = true; | 115 has_been_serialized_ = true; |
109 #endif | 116 #endif |
110 RawVarDataGraph::Create(var_, instance_)->Write(m); | 117 scoped_ptr<RawVarDataGraph> data = RawVarDataGraph::Create(var_, instance_); |
| 118 if (data) { |
| 119 m->WriteBool(true); // Success. |
| 120 data->Write(m, base::Bind(&DefaultHandleWriter)); |
| 121 } else { |
| 122 m->WriteBool(false); // Failure. |
| 123 } |
| 124 } |
| 125 |
| 126 void SerializedVar::Inner::WriteDataToMessage( |
| 127 IPC::Message* m, |
| 128 const HandleWriter& handle_writer) const { |
| 129 if (raw_var_data_) { |
| 130 m->WriteBool(true); // Success. |
| 131 raw_var_data_->Write(m, handle_writer); |
| 132 } else { |
| 133 m->WriteBool(false); // Failure. |
| 134 } |
111 } | 135 } |
112 | 136 |
113 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, | 137 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, |
114 PickleIterator* iter) { | 138 PickleIterator* iter) { |
115 #ifndef NDEBUG | 139 #ifndef NDEBUG |
116 // We should only deserialize something once or will end up with leaked | 140 // We should only deserialize something once or will end up with leaked |
117 // references. | 141 // references. |
118 // | 142 // |
119 // One place this has happened in the past is using | 143 // One place this has happened in the past is using |
120 // std::vector<SerializedVar>.resize(). If you're doing this manually instead | 144 // std::vector<SerializedVar>.resize(). If you're doing this manually instead |
121 // of using the helper classes for handling in/out vectors of vars, be | 145 // of using the helper classes for handling in/out vectors of vars, be |
122 // sure you use the same pattern as the SerializedVarVector classes. | 146 // sure you use the same pattern as the SerializedVarVector classes. |
123 DCHECK(!has_been_deserialized_); | 147 DCHECK(!has_been_deserialized_); |
124 has_been_deserialized_ = true; | 148 has_been_deserialized_ = true; |
125 #endif | 149 #endif |
126 // When reading, the dispatcher should be set when we get a Deserialize | 150 // When reading, the dispatcher should be set when we get a Deserialize |
127 // call (which will supply a dispatcher). | 151 // call (which will supply a dispatcher). |
128 raw_var_data_ = RawVarDataGraph::Read(m, iter); | 152 if (!m->ReadBool(iter, &is_valid_var_)) |
129 return raw_var_data_.get() != NULL; | 153 return false; |
| 154 if (is_valid_var_) { |
| 155 raw_var_data_ = RawVarDataGraph::Read(m, iter); |
| 156 if (!raw_var_data_) |
| 157 return false; |
| 158 } |
| 159 |
| 160 return true; |
130 } | 161 } |
131 | 162 |
132 void SerializedVar::Inner::SetCleanupModeToEndSendPassRef() { | 163 void SerializedVar::Inner::SetCleanupModeToEndSendPassRef() { |
133 cleanup_mode_ = END_SEND_PASS_REF; | 164 cleanup_mode_ = END_SEND_PASS_REF; |
134 } | 165 } |
135 | 166 |
136 void SerializedVar::Inner::SetCleanupModeToEndReceiveCallerOwned() { | 167 void SerializedVar::Inner::SetCleanupModeToEndReceiveCallerOwned() { |
137 cleanup_mode_ = END_RECEIVE_CALLER_OWNED; | 168 cleanup_mode_ = END_RECEIVE_CALLER_OWNED; |
138 } | 169 } |
139 | 170 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 const std::string& str) { | 458 const std::string& str) { |
428 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); | 459 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); |
429 } | 460 } |
430 | 461 |
431 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) | 462 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) |
432 : SerializedVar(var) { | 463 : SerializedVar(var) { |
433 } | 464 } |
434 | 465 |
435 } // namespace proxy | 466 } // namespace proxy |
436 } // namespace ppapi | 467 } // namespace ppapi |
OLD | NEW |