| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 break; | 49 break; |
| 50 case END_RECEIVE_CALLER_OWNED: | 50 case END_RECEIVE_CALLER_OWNED: |
| 51 serialization_rules_->EndReceiveCallerOwned(var_); | 51 serialization_rules_->EndReceiveCallerOwned(var_); |
| 52 break; | 52 break; |
| 53 default: | 53 default: |
| 54 break; | 54 break; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 PP_Var SerializedVar::Inner::GetVar() { | 58 PP_Var SerializedVar::Inner::GetVar() { |
| 59 DCHECK(serialization_rules_); | 59 DCHECK(serialization_rules_.get()); |
| 60 | 60 |
| 61 #if defined(NACL_WIN64) | 61 #if defined(NACL_WIN64) |
| 62 NOTREACHED(); | 62 NOTREACHED(); |
| 63 return PP_MakeUndefined(); | 63 return PP_MakeUndefined(); |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 if (raw_var_data_.get()) { | 66 if (raw_var_data_.get()) { |
| 67 var_ = raw_var_data_->CreatePPVar(instance_); | 67 var_ = raw_var_data_->CreatePPVar(instance_); |
| 68 raw_var_data_.reset(NULL); | 68 raw_var_data_.reset(NULL); |
| 69 } | 69 } |
| 70 | 70 |
| 71 return var_; | 71 return var_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void SerializedVar::Inner::SetVar(PP_Var var) { | 74 void SerializedVar::Inner::SetVar(PP_Var var) { |
| 75 // Sanity check, when updating the var we should have received a | 75 // Sanity check, when updating the var we should have received a |
| 76 // serialization rules pointer already. | 76 // serialization rules pointer already. |
| 77 DCHECK(serialization_rules_); | 77 DCHECK(serialization_rules_.get()); |
| 78 var_ = var; | 78 var_ = var; |
| 79 raw_var_data_.reset(NULL); | 79 raw_var_data_.reset(NULL); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SerializedVar::Inner::SetInstance(PP_Instance instance) { | 82 void SerializedVar::Inner::SetInstance(PP_Instance instance) { |
| 83 instance_ = instance; | 83 instance_ = instance; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { | 86 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { |
| 87 var_ = value; | 87 var_ = value; |
| 88 raw_var_data_.reset(NULL); | 88 raw_var_data_.reset(NULL); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const { | 91 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const { |
| 92 // When writing to the IPC messages, a serialization rules handler should | 92 // When writing to the IPC messages, a serialization rules handler should |
| 93 // always have been set. | 93 // always have been set. |
| 94 // | 94 // |
| 95 // When sending a message, it should be difficult to trigger this if you're | 95 // When sending a message, it should be difficult to trigger this if you're |
| 96 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. | 96 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. |
| 97 // Make sure you're using the proper "Send" helper class. | 97 // Make sure you're using the proper "Send" helper class. |
| 98 // | 98 // |
| 99 // It should be more common to see this when handling an incoming message | 99 // It should be more common to see this when handling an incoming message |
| 100 // that returns a var. This means the message handler didn't write to the | 100 // 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 | 101 // output parameter, or possibly you used the wrong helper class |
| 102 // (normally SerializedVarReturnValue). | 102 // (normally SerializedVarReturnValue). |
| 103 DCHECK(serialization_rules_); | 103 DCHECK(serialization_rules_.get()); |
| 104 | 104 |
| 105 #ifndef NDEBUG | 105 #ifndef NDEBUG |
| 106 // We should only be serializing something once. | 106 // We should only be serializing something once. |
| 107 DCHECK(!has_been_serialized_); | 107 DCHECK(!has_been_serialized_); |
| 108 has_been_serialized_ = true; | 108 has_been_serialized_ = true; |
| 109 #endif | 109 #endif |
| 110 RawVarDataGraph::Create(var_, instance_)->Write(m); | 110 RawVarDataGraph::Create(var_, instance_)->Write(m); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, | 113 bool SerializedVar::Inner::ReadFromMessage(const IPC::Message* m, |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 const std::string& str) { | 427 const std::string& str) { |
| 428 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); | 428 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str)); |
| 429 } | 429 } |
| 430 | 430 |
| 431 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) | 431 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) |
| 432 : SerializedVar(var) { | 432 : SerializedVar(var) { |
| 433 } | 433 } |
| 434 | 434 |
| 435 } // namespace proxy | 435 } // namespace proxy |
| 436 } // namespace ppapi | 436 } // namespace ppapi |
| OLD | NEW |