Chromium Code Reviews| Index: content/public/common/presentation_connection_message.cc |
| diff --git a/content/public/common/presentation_connection_message.cc b/content/public/common/presentation_connection_message.cc |
| index 1e960c18e827e8ddedf1d31f501dda49e9d3c120..70c0a4508279888af318e029a8dcc31c05bd649d 100644 |
| --- a/content/public/common/presentation_connection_message.cc |
| +++ b/content/public/common/presentation_connection_message.cc |
| @@ -4,16 +4,58 @@ |
| #include "content/public/common/presentation_connection_message.h" |
| +#include <utility> |
| + |
| namespace content { |
| +// TODO(crbug.com/524128): This restriction comes from Cast. Raise this limit |
| +// for non-Cast presentations. |
| +const size_t kMaxPresentationConnectionMessageSize = 64 * 1024; // 64 KB. |
| + |
| +PresentationConnectionMessage::PresentationConnectionMessage() = default; |
| + |
| +PresentationConnectionMessage::PresentationConnectionMessage( |
| + const std::string& message) |
| + : message(std::move(message)) {} |
|
imcheng
2017/02/25 01:08:40
I believe this is still making a copy of the input
mark a. foltz
2017/02/27 23:25:15
Done.
|
| + |
| +PresentationConnectionMessage::PresentationConnectionMessage( |
| + const std::vector<uint8_t>& data) |
| + : data(std::move(data)) {} |
| + |
| PresentationConnectionMessage::PresentationConnectionMessage( |
| - PresentationMessageType type) |
| - : type(type) {} |
| + PresentationConnectionMessage&& other) { |
| + if (other.is_binary()) { |
| + data = std::move(other.data); |
|
dcheng
2017/02/25 07:17:27
It's legal to just write:
data = std::move(other.
mark a. foltz
2017/02/27 23:25:14
Done.
|
| + } else { |
| + message = std::move(other.message); |
| + } |
| +} |
| PresentationConnectionMessage::~PresentationConnectionMessage() {} |
| +bool PresentationConnectionMessage::operator==( |
| + const PresentationConnectionMessage& other) const { |
| + if (this->is_binary()) { |
| + return other.is_binary() && this->data == other.data; |
| + } else { |
| + return !this->is_binary() && this->message == other.message; |
|
dcheng
2017/02/25 07:17:27
Or just write return this->data == other.data && t
mark a. foltz
2017/02/27 23:25:15
Done.
|
| + } |
| +} |
| + |
| +PresentationConnectionMessage& PresentationConnectionMessage::operator=( |
| + PresentationConnectionMessage&& other) { |
| + if (other.is_binary()) { |
| + this->message.reset(); |
| + this->data = std::move(other.data); |
|
dcheng
2017/02/25 07:17:27
Ditto to the move ctor comments: it's legal to jus
mark a. foltz
2017/02/27 23:25:15
Done.
|
| + } else { |
| + this->data.reset(); |
| + this->message = std::move(other.message); |
| + } |
| + return *this; |
| +} |
| + |
| bool PresentationConnectionMessage::is_binary() const { |
| - return data != nullptr; |
| + return data.has_value(); |
| } |
| } // namespace content |