OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_message_util.h" | 5 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 break; | 56 break; |
57 default: | 57 default: |
58 // Unknown value type. message_proto will remain uninitialized because | 58 // Unknown value type. message_proto will remain uninitialized because |
59 // payload_type is unset. | 59 // payload_type is unset. |
60 break; | 60 break; |
61 } | 61 } |
62 return message_proto->IsInitialized(); | 62 return message_proto->IsInitialized(); |
63 } | 63 } |
64 | 64 |
| 65 bool IsCastMessageValid(const CastMessage& message_proto) { |
| 66 if (message_proto.namespace_().empty() || message_proto.source_id().empty() || |
| 67 message_proto.destination_id().empty()) { |
| 68 return false; |
| 69 } |
| 70 return (message_proto.payload_type() == CastMessage_PayloadType_STRING && |
| 71 message_proto.has_payload_utf8()) || |
| 72 (message_proto.payload_type() == CastMessage_PayloadType_BINARY && |
| 73 message_proto.has_payload_binary()); |
| 74 } |
| 75 |
65 bool CastMessageToMessageInfo(const CastMessage& message_proto, | 76 bool CastMessageToMessageInfo(const CastMessage& message_proto, |
66 MessageInfo* message) { | 77 MessageInfo* message) { |
67 DCHECK(message); | 78 DCHECK(message); |
68 message->source_id = message_proto.source_id(); | 79 message->source_id = message_proto.source_id(); |
69 message->destination_id = message_proto.destination_id(); | 80 message->destination_id = message_proto.destination_id(); |
70 message->namespace_ = message_proto.namespace_(); | 81 message->namespace_ = message_proto.namespace_(); |
71 // Determine the type of the payload and fill base::Value appropriately. | 82 // Determine the type of the payload and fill base::Value appropriately. |
72 scoped_ptr<base::Value> value; | 83 scoped_ptr<base::Value> value; |
73 switch (message_proto.payload_type()) { | 84 switch (message_proto.payload_type()) { |
74 case CastMessage_PayloadType_STRING: | 85 case CastMessage_PayloadType_STRING: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 message_proto->set_payload_binary(auth_message_string); | 152 message_proto->set_payload_binary(auth_message_string); |
142 } | 153 } |
143 | 154 |
144 bool IsAuthMessage(const CastMessage& message) { | 155 bool IsAuthMessage(const CastMessage& message) { |
145 return message.namespace_() == kAuthNamespace; | 156 return message.namespace_() == kAuthNamespace; |
146 } | 157 } |
147 | 158 |
148 } // namespace cast_channel | 159 } // namespace cast_channel |
149 } // namespace core_api | 160 } // namespace core_api |
150 } // namespace extensions | 161 } // namespace extensions |
OLD | NEW |