Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: extensions/browser/api/cast_channel/cast_message_util.cc

Issue 555283002: Create new class "CastTransport", which encapsulates the message read and write event loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests to CL Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ValidateCastMessage(const CastMessage& message_proto) {
mark a. foltz 2014/09/11 06:47:45 I think there are also restrictions on namespace (
Kevin M 2014/09/11 18:07:58 Yes. Done.
66 return (message_proto.payload_type() == CastMessage_PayloadType_STRING &&
67 message_proto.has_payload_utf8()) ||
68 (message_proto.payload_type() == CastMessage_PayloadType_BINARY &&
69 message_proto.has_payload_binary());
70 }
71
65 bool CastMessageToMessageInfo(const CastMessage& message_proto, 72 bool CastMessageToMessageInfo(const CastMessage& message_proto,
66 MessageInfo* message) { 73 MessageInfo* message) {
67 DCHECK(message); 74 DCHECK(message);
68 message->source_id = message_proto.source_id(); 75 message->source_id = message_proto.source_id();
69 message->destination_id = message_proto.destination_id(); 76 message->destination_id = message_proto.destination_id();
70 message->namespace_ = message_proto.namespace_(); 77 message->namespace_ = message_proto.namespace_();
71 // Determine the type of the payload and fill base::Value appropriately. 78 // Determine the type of the payload and fill base::Value appropriately.
72 scoped_ptr<base::Value> value; 79 scoped_ptr<base::Value> value;
73 switch (message_proto.payload_type()) { 80 switch (message_proto.payload_type()) {
74 case CastMessage_PayloadType_STRING: 81 case CastMessage_PayloadType_STRING:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 message_proto->set_payload_binary(auth_message_string); 148 message_proto->set_payload_binary(auth_message_string);
142 } 149 }
143 150
144 bool IsAuthMessage(const CastMessage& message) { 151 bool IsAuthMessage(const CastMessage& message) {
145 return message.namespace_() == kAuthNamespace; 152 return message.namespace_() == kAuthNamespace;
146 } 153 }
147 154
148 } // namespace cast_channel 155 } // namespace cast_channel
149 } // namespace core_api 156 } // namespace core_api
150 } // namespace extensions 157 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698