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