| 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 #ifndef CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ | 6 #define CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> // For size_t |
| 8 #include <stdint.h> | 9 #include <stdint.h> |
| 9 | 10 |
| 10 #include <memory> | |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/optional.h" |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 enum PresentationMessageType { | 19 // The maximum number of bytes allowed in a presentation connection message. |
| 19 TEXT, | 20 CONTENT_EXPORT extern const size_t kMaxPresentationConnectionMessageSize; |
| 20 BINARY, | |
| 21 }; | |
| 22 | 21 |
| 23 // Represents a presentation connection message. | 22 // Represents a presentation connection message. If this is a text message, |
| 24 // If this is a text message, |data| is null; otherwise, |message| is null. | 23 // |data| is null; otherwise, |message| is null. Empty messages are allowed. |
| 25 // Empty messages are allowed. | |
| 26 struct CONTENT_EXPORT PresentationConnectionMessage { | 24 struct CONTENT_EXPORT PresentationConnectionMessage { |
| 27 public: | 25 public: |
| 28 explicit PresentationConnectionMessage(PresentationMessageType type); | 26 // Constructs a new, untyped message (for Mojo). These messages are not valid |
| 27 // and exactly one of |message| or |data| must be set. |
| 28 PresentationConnectionMessage(); |
| 29 // PCM is a move-only type. |
| 30 PresentationConnectionMessage(PresentationConnectionMessage&& other); |
| 31 // Constructs a text message from |message|. |
| 32 explicit PresentationConnectionMessage(std::string message); |
| 33 // Constructs a binary message from |data|. |
| 34 explicit PresentationConnectionMessage(std::vector<uint8_t> data); |
| 29 ~PresentationConnectionMessage(); | 35 ~PresentationConnectionMessage(); |
| 30 | 36 |
| 31 bool is_binary() const; | 37 bool is_binary() const; |
| 32 const PresentationMessageType type; | 38 |
| 33 std::string message; | 39 bool operator==(const PresentationConnectionMessage& other) const; |
| 34 std::unique_ptr<std::vector<uint8_t>> data; | 40 PresentationConnectionMessage& operator=( |
| 41 PresentationConnectionMessage&& other); |
| 42 |
| 43 base::Optional<std::string> message; |
| 44 base::Optional<std::vector<uint8_t>> data; |
| 35 }; | 45 }; |
| 36 | 46 |
| 37 } // namespace content | 47 } // namespace content |
| 38 | 48 |
| 39 #endif // CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ | 49 #endif // CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ |
| OLD | NEW |