| 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 "jingle/glue/utils.h" | 5 #include "jingle/glue/utils.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 value.SetString("ip", candidate.address().ipaddr().ToString()); | 39 value.SetString("ip", candidate.address().ipaddr().ToString()); |
| 40 value.SetInteger("port", candidate.address().port()); | 40 value.SetInteger("port", candidate.address().port()); |
| 41 value.SetString("type", candidate.type()); | 41 value.SetString("type", candidate.type()); |
| 42 value.SetString("protocol", candidate.protocol()); | 42 value.SetString("protocol", candidate.protocol()); |
| 43 value.SetString("username", candidate.username()); | 43 value.SetString("username", candidate.username()); |
| 44 value.SetString("password", candidate.password()); | 44 value.SetString("password", candidate.password()); |
| 45 value.SetDouble("preference", candidate.preference()); | 45 value.SetDouble("preference", candidate.preference()); |
| 46 value.SetInteger("generation", candidate.generation()); | 46 value.SetInteger("generation", candidate.generation()); |
| 47 | 47 |
| 48 std::string result; | 48 std::string result; |
| 49 base::JSONWriter::Write(&value, &result); | 49 base::JSONWriter::Write(value, &result); |
| 50 return result; | 50 return result; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool DeserializeP2PCandidate(const std::string& candidate_str, | 53 bool DeserializeP2PCandidate(const std::string& candidate_str, |
| 54 cricket::Candidate* candidate) { | 54 cricket::Candidate* candidate) { |
| 55 scoped_ptr<base::Value> value( | 55 scoped_ptr<base::Value> value( |
| 56 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); | 56 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); |
| 57 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { | 57 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 candidate->set_protocol(protocol); | 86 candidate->set_protocol(protocol); |
| 87 candidate->set_username(username); | 87 candidate->set_username(username); |
| 88 candidate->set_password(password); | 88 candidate->set_password(password); |
| 89 candidate->set_preference(static_cast<float>(preference)); | 89 candidate->set_preference(static_cast<float>(preference)); |
| 90 candidate->set_generation(generation); | 90 candidate->set_generation(generation); |
| 91 | 91 |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace jingle_glue | 95 } // namespace jingle_glue |
| OLD | NEW |