Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/public/common/presentation_connection_message.h" | 5 #include "content/public/common/presentation_connection_message.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | |
| 10 #include "base/json/string_escape.h" | |
| 11 | |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 11 // TODO(crbug.com/524128): This restriction comes from Cast. Raise this limit | 14 // TODO(crbug.com/524128): This restriction comes from Cast. Raise this limit |
| 12 // for non-Cast presentations. | 15 // for non-Cast presentations. |
| 13 const size_t kMaxPresentationConnectionMessageSize = 64 * 1024; // 64 KB. | 16 const size_t kMaxPresentationConnectionMessageSize = 64 * 1024; // 64 KB. |
| 14 | 17 |
| 15 PresentationConnectionMessage::PresentationConnectionMessage() = default; | 18 PresentationConnectionMessage::PresentationConnectionMessage() = default; |
| 16 | 19 |
| 17 PresentationConnectionMessage::PresentationConnectionMessage( | 20 PresentationConnectionMessage::PresentationConnectionMessage( |
| 18 std::string message) | 21 std::string message) |
| 19 : message(std::move(message)) {} | 22 : message(std::move(message)) {} |
| 20 | 23 |
| 21 PresentationConnectionMessage::PresentationConnectionMessage( | 24 PresentationConnectionMessage::PresentationConnectionMessage( |
| 22 std::vector<uint8_t> data) | 25 std::vector<uint8_t> data) |
| 23 : data(std::move(data)) {} | 26 : data(std::move(data)) {} |
| 24 | 27 |
| 25 PresentationConnectionMessage::PresentationConnectionMessage( | 28 PresentationConnectionMessage::PresentationConnectionMessage( |
| 26 PresentationConnectionMessage&& other) = default; | 29 const PresentationConnectionMessage& other) = default; |
| 30 | |
| 31 // Note: "move constructor noexcept = default" currently does not compile on | |
| 32 // Windows and Android (crbug.com/706963). | |
| 33 PresentationConnectionMessage::PresentationConnectionMessage( | |
| 34 PresentationConnectionMessage&& other) noexcept | |
| 35 : message(std::move(other.message)), data(std::move(other.data)) {} | |
| 27 | 36 |
| 28 PresentationConnectionMessage::~PresentationConnectionMessage() {} | 37 PresentationConnectionMessage::~PresentationConnectionMessage() {} |
| 29 | 38 |
| 30 bool PresentationConnectionMessage::operator==( | 39 bool PresentationConnectionMessage::operator==( |
| 31 const PresentationConnectionMessage& other) const { | 40 const PresentationConnectionMessage& other) const { |
| 32 return this->data == other.data && this->message == other.message; | 41 return this->data == other.data && this->message == other.message; |
| 33 } | 42 } |
| 34 | 43 |
| 35 PresentationConnectionMessage& PresentationConnectionMessage::operator=( | 44 PresentationConnectionMessage& PresentationConnectionMessage::operator=( |
|
mark a. foltz
2017/06/28 07:29:55
Can you add a note explaining why this isn't move-
imcheng
2017/06/29 08:21:09
added comment in header file.
| |
| 45 const PresentationConnectionMessage& other) = default; | |
| 46 | |
| 47 PresentationConnectionMessage& PresentationConnectionMessage::operator=( | |
| 36 PresentationConnectionMessage&& other) = default; | 48 PresentationConnectionMessage&& other) = default; |
| 37 | 49 |
| 38 bool PresentationConnectionMessage::is_binary() const { | 50 bool PresentationConnectionMessage::is_binary() const { |
| 39 return data.has_value(); | 51 return data.has_value(); |
| 40 } | 52 } |
| 41 | 53 |
| 54 std::string PresentationConnectionMessage::ToHumanReadableString() const { | |
|
mark a. foltz
2017/06/28 07:29:56
This only seems to be called from logging in unitt
imcheng
2017/06/29 08:21:09
Added #ifndef NDEBUG.
imcheng
2017/06/29 17:58:23
It turns out we build unit tests on release builds
| |
| 55 if (!message && !data) | |
| 56 return "null"; | |
| 57 std::string result; | |
| 58 if (message) { | |
| 59 result = "text="; | |
| 60 base::EscapeJSONString(*message, true, &result); | |
| 61 } else { | |
| 62 const base::StringPiece src(reinterpret_cast<const char*>(data->data()), | |
| 63 data->size()); | |
| 64 base::Base64Encode(src, &result); | |
| 65 result = "binary=" + result; | |
| 66 } | |
| 67 return result; | |
| 68 } | |
| 69 | |
| 42 } // namespace content | 70 } // namespace content |
| OLD | NEW |