Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/media/router/route_message.h" | 5 #include "chrome/browser/media/router/route_message.h" |
| 6 | 6 |
| 7 #include "base/json/string_escape.h" | |
| 8 | |
| 7 namespace media_router { | 9 namespace media_router { |
| 8 | 10 |
| 9 RouteMessage::RouteMessage() = default; | 11 RouteMessage::RouteMessage() = default; |
| 10 RouteMessage::RouteMessage(const RouteMessage& other) = default; | 12 RouteMessage::RouteMessage(const RouteMessage& other) = default; |
| 11 RouteMessage::~RouteMessage() = default; | 13 RouteMessage::~RouteMessage() = default; |
| 12 | 14 |
| 15 std::string RouteMessage::ToHumanReadableString() const { | |
| 16 if (!text && !binary) | |
| 17 return "null"; | |
| 18 if ((type == TEXT && !text) || (type == BINARY && !binary)) | |
| 19 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.
| |
| 20 std::string result; | |
| 21 if (text) { | |
| 22 result = "text="; | |
| 23 base::EscapeJSONString(*text, true, &result); | |
| 24 } else { | |
| 25 result = "binary="; | |
| 26 const base::StringPiece src(reinterpret_cast<const char*>(binary->data()), | |
| 27 binary->size()); | |
| 28 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
| |
| 29 } | |
| 30 return result; | |
| 31 } | |
| 32 | |
| 13 } // namespace media_router | 33 } // namespace media_router |
| OLD | NEW |