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 { | 21 namespace { |
22 void DefaultHandleWriter(IPC::Message* m, const SerializedHandle& handle) { | 22 void DefaultHandleWriter(base::Pickle* m, const SerializedHandle& handle) { |
23 IPC::ParamTraits<SerializedHandle>::Write(m, handle); | 23 IPC::ParamTraits<SerializedHandle>::Write(m, handle); |
24 } | 24 } |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 // SerializedVar::Inner -------------------------------------------------------- | 27 // SerializedVar::Inner -------------------------------------------------------- |
28 | 28 |
29 SerializedVar::Inner::Inner() | 29 SerializedVar::Inner::Inner() |
30 : serialization_rules_(NULL), | 30 : serialization_rules_(NULL), |
31 var_(PP_MakeUndefined()), | 31 var_(PP_MakeUndefined()), |
32 instance_(0), | 32 instance_(0), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void SerializedVar::Inner::SetInstance(PP_Instance instance) { | 89 void SerializedVar::Inner::SetInstance(PP_Instance instance) { |
90 instance_ = instance; | 90 instance_ = instance; |
91 } | 91 } |
92 | 92 |
93 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { | 93 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { |
94 var_ = value; | 94 var_ = value; |
95 raw_var_data_.reset(NULL); | 95 raw_var_data_.reset(NULL); |
96 } | 96 } |
97 | 97 |
98 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const { | 98 void SerializedVar::Inner::WriteToMessage(base::Pickle* m) const { |
99 // When writing to the IPC messages, a serialization rules handler should | 99 // When writing to the IPC messages, a serialization rules handler should |
100 // always have been set. | 100 // always have been set. |
101 // | 101 // |
102 // When sending a message, it should be difficult to trigger this if you're | 102 // When sending a message, it should be difficult to trigger this if you're |
103 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. | 103 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. |
104 // Make sure you're using the proper "Send" helper class. | 104 // Make sure you're using the proper "Send" helper class. |
105 // | 105 // |
106 // It should be more common to see this when handling an incoming message | 106 // It should be more common to see this when handling an incoming message |
107 // 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 |
108 // output parameter, or possibly you used the wrong helper class | 108 // output parameter, or possibly you used the wrong helper class |
109 // (normally SerializedVarReturnValue). | 109 // (normally SerializedVarReturnValue). |
110 DCHECK(serialization_rules_.get()); | 110 DCHECK(serialization_rules_.get()); |
111 | 111 |
112 #ifndef NDEBUG | 112 #ifndef NDEBUG |
113 // We should only be serializing something once. | 113 // We should only be serializing something once. |
114 DCHECK(!has_been_serialized_); | 114 DCHECK(!has_been_serialized_); |
115 has_been_serialized_ = true; | 115 has_been_serialized_ = true; |
116 #endif | 116 #endif |
117 scoped_ptr<RawVarDataGraph> data = RawVarDataGraph::Create(var_, instance_); | 117 scoped_ptr<RawVarDataGraph> data = RawVarDataGraph::Create(var_, instance_); |
118 if (data) { | 118 if (data) { |
119 m->WriteBool(true); // Success. | 119 m->WriteBool(true); // Success. |
120 data->Write(m, base::Bind(&DefaultHandleWriter)); | 120 data->Write(m, base::Bind(&DefaultHandleWriter)); |
121 } else { | 121 } else { |
122 m->WriteBool(false); // Failure. | 122 m->WriteBool(false); // Failure. |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 void SerializedVar::Inner::WriteDataToMessage( | 126 void SerializedVar::Inner::WriteDataToMessage( |
127 IPC::Message* m, | 127 base::Pickle* m, |
128 const HandleWriter& handle_writer) const { | 128 const HandleWriter& handle_writer) const { |
129 if (raw_var_data_) { | 129 if (raw_var_data_) { |
130 m->WriteBool(true); // Success. | 130 m->WriteBool(true); // Success. |
131 raw_var_data_->Write(m, handle_writer); | 131 raw_var_data_->Write(m, handle_writer); |
132 } else { | 132 } else { |
133 m->WriteBool(false); // Failure. | 133 m->WriteBool(false); // Failure. |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, | 137 bool SerializedVar::Inner::ReadFromMessage(const base::Pickle* m, |
138 base::PickleIterator* iter) { | 138 base::PickleIterator* iter) { |
139 #ifndef NDEBUG | 139 #ifndef NDEBUG |
140 // 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 |
141 // references. | 141 // references. |
142 // | 142 // |
143 // One place this has happened in the past is using | 143 // One place this has happened in the past is using |
144 // std::vector<SerializedVar>.resize(). If you're doing this manually instead | 144 // std::vector<SerializedVar>.resize(). If you're doing this manually instead |
145 // 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 |
146 // sure you use the same pattern as the SerializedVarVector classes. | 146 // sure you use the same pattern as the SerializedVarVector classes. |
147 DCHECK(!has_been_deserialized_); | 147 DCHECK(!has_been_deserialized_); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const std::string& str) { | 458 const std::string& str) { |
459 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); | 459 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); |
460 } | 460 } |
461 | 461 |
462 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) | 462 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) |
463 : SerializedVar(var) { | 463 : SerializedVar(var) { |
464 } | 464 } |
465 | 465 |
466 } // namespace proxy | 466 } // namespace proxy |
467 } // namespace ppapi | 467 } // namespace ppapi |
OLD | NEW |