Chromium Code Reviews| Index: chrome/browser/media/router/route_message.cc |
| diff --git a/chrome/browser/media/router/route_message.cc b/chrome/browser/media/router/route_message.cc |
| index 41bc9d0d1c53d26f51ff148908a112160a367e3d..fc83664be93c9d0a023a2948f18807ef18b19a82 100644 |
| --- a/chrome/browser/media/router/route_message.cc |
| +++ b/chrome/browser/media/router/route_message.cc |
| @@ -4,10 +4,30 @@ |
| #include "chrome/browser/media/router/route_message.h" |
| +#include "base/json/string_escape.h" |
| + |
| namespace media_router { |
| RouteMessage::RouteMessage() = default; |
| RouteMessage::RouteMessage(const RouteMessage& other) = default; |
| RouteMessage::~RouteMessage() = default; |
| +std::string RouteMessage::ToHumanReadableString() const { |
| + if (!text && !binary) |
| + return "null"; |
| + if ((type == TEXT && !text) || (type == BINARY && !binary)) |
| + return "illegal value"; |
|
dcheng
2016/09/20 08:20:13
We might even just DCHECK in this case... we shoul
miu
2016/09/21 03:15:50
Done.
|
| + std::string result; |
| + if (text) { |
| + result = "text="; |
| + base::EscapeJSONString(*text, true, &result); |
| + } else { |
| + result = "binary="; |
| + const base::StringPiece src(reinterpret_cast<const char*>(binary->data()), |
| + binary->size()); |
| + base::EscapeJSONString(src, true, &result); |
|
dcheng
2016/09/20 08:20:13
This assumes UTF8 input and will happily mangle th
miu
2016/09/21 03:15:50
Ah! Good catch. Base64 encoding is probably more-a
|
| + } |
| + return result; |
| +} |
| + |
| } // namespace media_router |