Cleanup: Move json.h into rtc namespace.

This should fix the TODO in that header.

BUG=None
TEST=ninja -C out/Debug still compiles everything.
R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/47919004

Patch from Thiago Farina <tfarina@chromium.org>.

Cr-Commit-Position: refs/heads/master@{#8921}
This commit is contained in:
Thiago Farina 2015-04-02 09:59:15 +00:00 committed by Tommi
parent 0dd58026a8
commit cb76b89572
4 changed files with 23 additions and 9 deletions

View File

@ -283,7 +283,7 @@ void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
std::string type; std::string type;
std::string json_object; std::string json_object;
GetStringFromJsonObject(jmessage, kSessionDescriptionTypeName, &type); rtc::GetStringFromJsonObject(jmessage, kSessionDescriptionTypeName, &type);
if (!type.empty()) { if (!type.empty()) {
if (type == "offer-loopback") { if (type == "offer-loopback") {
// This is a loopback call. // This is a loopback call.
@ -297,7 +297,8 @@ void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
} }
std::string sdp; std::string sdp;
if (!GetStringFromJsonObject(jmessage, kSessionDescriptionSdpName, &sdp)) { if (!rtc::GetStringFromJsonObject(jmessage, kSessionDescriptionSdpName,
&sdp)) {
LOG(WARNING) << "Can't parse received session description message."; LOG(WARNING) << "Can't parse received session description message.";
return; return;
} }
@ -319,10 +320,11 @@ void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
std::string sdp_mid; std::string sdp_mid;
int sdp_mlineindex = 0; int sdp_mlineindex = 0;
std::string sdp; std::string sdp;
if (!GetStringFromJsonObject(jmessage, kCandidateSdpMidName, &sdp_mid) || if (!rtc::GetStringFromJsonObject(jmessage, kCandidateSdpMidName,
!GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName, &sdp_mid) ||
&sdp_mlineindex) || !rtc::GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName,
!GetStringFromJsonObject(jmessage, kCandidateSdpName, &sdp)) { &sdp_mlineindex) ||
!rtc::GetStringFromJsonObject(jmessage, kCandidateSdpName, &sdp)) {
LOG(WARNING) << "Can't parse received message."; LOG(WARNING) << "Can't parse received message.";
return; return;
} }

View File

@ -16,6 +16,8 @@
#include <sstream> #include <sstream>
namespace rtc {
bool GetStringFromJson(const Json::Value& in, std::string* out) { bool GetStringFromJson(const Json::Value& in, std::string* out) {
if (!in.isString()) { if (!in.isString()) {
std::ostringstream s; std::ostringstream s;
@ -294,3 +296,5 @@ std::string JsonValueToString(const Json::Value& json) {
std::string value = w.write(json); std::string value = w.write(json);
return value.substr(0, value.size() - 1); // trim trailing newline return value.substr(0, value.size() - 1); // trim trailing newline
} }
} // namespace rtc

View File

@ -20,7 +20,7 @@
#include "third_party/jsoncpp/json.h" #include "third_party/jsoncpp/json.h"
#endif #endif
// TODO: Move to rtc namespace namespace rtc {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// JSON Helpers // JSON Helpers
@ -86,4 +86,6 @@ bool GetDoubleFromJsonObject(const Json::Value& in, const std::string& k,
// Writes out a Json value as a string. // Writes out a Json value as a string.
std::string JsonValueToString(const Json::Value& json); std::string JsonValueToString(const Json::Value& json);
} // namespace rtc
#endif // WEBRTC_BASE_JSON_H_ #endif // WEBRTC_BASE_JSON_H_

View File

@ -8,10 +8,14 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <vector>
#include "webrtc/base/gunit.h"
#include "webrtc/base/json.h" #include "webrtc/base/json.h"
#include <vector>
#include "webrtc/base/gunit.h"
namespace rtc {
static Json::Value in_s("foo"); static Json::Value in_s("foo");
static Json::Value in_sn("99"); static Json::Value in_sn("99");
static Json::Value in_si("-99"); static Json::Value in_si("-99");
@ -275,3 +279,5 @@ TEST(JsonTest, DoubleVectorToFromArray) {
EXPECT_EQ(in[i], outj[i]); EXPECT_EQ(in[i], outj[i]);
} }
} }
} // namespace rtc