| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 value.SetDouble("preference", candidate.preference()); | 52 value.SetDouble("preference", candidate.preference()); |
| 53 value.SetInteger("generation", candidate.generation()); | 53 value.SetInteger("generation", candidate.generation()); |
| 54 | 54 |
| 55 std::string result; | 55 std::string result; |
| 56 base::JSONWriter::Write(&value, &result); | 56 base::JSONWriter::Write(&value, &result); |
| 57 return result; | 57 return result; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool DeserializeP2PCandidate(const std::string& candidate_str, | 60 bool DeserializeP2PCandidate(const std::string& candidate_str, |
| 61 cricket::Candidate* candidate) { | 61 cricket::Candidate* candidate) { |
| 62 scoped_ptr<Value> value(base::JSONReader::Read(candidate_str, true)); | 62 scoped_ptr<Value> value( |
| 63 base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS)); |
| 63 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { | 64 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { |
| 64 return false; | 65 return false; |
| 65 } | 66 } |
| 66 | 67 |
| 67 DictionaryValue* dic_value = static_cast<DictionaryValue*>(value.get()); | 68 DictionaryValue* dic_value = static_cast<DictionaryValue*>(value.get()); |
| 68 | 69 |
| 69 std::string name; | 70 std::string name; |
| 70 std::string ip; | 71 std::string ip; |
| 71 int port; | 72 int port; |
| 72 std::string type; | 73 std::string type; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 94 candidate->set_protocol(protocol); | 95 candidate->set_protocol(protocol); |
| 95 candidate->set_username(username); | 96 candidate->set_username(username); |
| 96 candidate->set_password(password); | 97 candidate->set_password(password); |
| 97 candidate->set_preference(static_cast<float>(preference)); | 98 candidate->set_preference(static_cast<float>(preference)); |
| 98 candidate->set_generation(generation); | 99 candidate->set_generation(generation); |
| 99 | 100 |
| 100 return true; | 101 return true; |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace jingle_glue | 104 } // namespace jingle_glue |
| OLD | NEW |