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 #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. | 24 |
| 26 struct CONTENT_EXPORT PresentationConnectionMessage { | 25 struct CONTENT_EXPORT PresentationConnectionMessage { |
| 27 public: | 26 public: |
| 28 explicit PresentationConnectionMessage(PresentationMessageType type); | 27 // Constructs a new, untyped message (for Mojo). These messages are not valid |
| 28 // and exactly one of |message| or |data| must be set. | |
| 29 PresentationConnectionMessage(); | |
| 30 // PCM is a move-only type. | |
| 31 PresentationConnectionMessage(PresentationConnectionMessage&& other); | |
| 32 // Constructs a text message from |message|. | |
| 33 explicit PresentationConnectionMessage(std::string message); | |
| 34 // Constructs a binary message from |data|. | |
| 35 explicit PresentationConnectionMessage(std::vector<uint8_t> data); | |
| 29 ~PresentationConnectionMessage(); | 36 ~PresentationConnectionMessage(); |
| 30 | 37 |
| 31 bool is_binary() const; | 38 bool is_binary() const; |
| 32 const PresentationMessageType type; | 39 |
| 33 std::string message; | 40 bool operator==(const PresentationConnectionMessage& other) const; |
| 34 std::unique_ptr<std::vector<uint8_t>> data; | 41 PresentationConnectionMessage& operator=( |
| 42 PresentationConnectionMessage&& other); | |
| 43 | |
| 44 base::Optional<std::string> message; | |
| 45 base::Optional<std::vector<uint8_t>> data; | |
| 35 }; | 46 }; |
|
dcheng
2017/02/28 06:45:27
Nit: DISALLOW_COPY_AND_ASSIGN, since it seems like
mark a. foltz
2017/02/28 18:35:21
The compiler automatically deletes the default cop
dcheng
2017/03/01 00:55:49
I think I would still prefer to be explicit about
mark a. foltz
2017/03/03 21:03:21
The compiler actually won't allow use of DISALLOW_
dcheng
2017/03/06 22:14:55
This shouldn't block the commit but:
$ cat test.c
| |
| 36 | 47 |
| 37 } // namespace content | 48 } // namespace content |
| 38 | 49 |
| 39 #endif // CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ | 50 #endif // CONTENT_PUBLIC_COMMON_PRESENTATION_CONNECTION_MESSAGE_H_ |
| OLD | NEW |