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

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

Issue 120323002: Revert 242158 "Refactor CastSocket code for the following:" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | trunk/src/chrome/browser/extensions/api/cast_channel/cast_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_message_util.h" 5 #include "chrome/browser/extensions/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"
11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" 11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h"
12 #include "chrome/common/extensions/api/cast_channel.h" 12 #include "chrome/common/extensions/api/cast_channel.h"
13 13
14 namespace { 14 namespace {
15 static const char kAuthNamespace[] = 15 static const char kAuthNamespace[] =
16 "urn:x-cast:com.google.cast.tp.deviceauth"; 16 "urn:x-cast:com.google.cast.tp.deviceauth";
17 // Sender and receiver IDs to use for platform messages. 17 // Sender and receiver IDs to use for platform messages.
18 static const char kPlatformSenderId[] = "sender-0"; 18 static const char kPlatformSenderId[] = "sender-0";
19 static const char kPlatformReceiverId[] = "receiver-0"; 19 static const char kPlatformReceiverId[] = "receiver-0";
20 } // namespace 20 } // namespace
21 21
22 namespace extensions { 22 namespace extensions {
23 namespace api { 23 namespace api {
24 namespace cast_channel { 24 namespace cast_channel {
25 25
26 bool MessageInfoToCastMessage(const MessageInfo& message, 26 bool MessageInfoToCastMessage(const MessageInfo& message,
27 CastMessage* message_proto) { 27 CastMessage* message_proto) {
28 DCHECK(message_proto); 28 DCHECK(message_proto);
29 if (!message.data)
30 return false;
31
32 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); 29 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0);
33 message_proto->set_source_id(message.source_id); 30 message_proto->set_source_id(message.source_id);
34 message_proto->set_destination_id(message.destination_id); 31 message_proto->set_destination_id(message.destination_id);
35 message_proto->set_namespace_(message.namespace_); 32 message_proto->set_namespace_(message.namespace_);
36 // Determine the type of the base::Value and set the message payload 33 // Determine the type of the base::Value and set the message payload
37 // appropriately. 34 // appropriately.
38 std::string data; 35 std::string data;
39 base::BinaryValue* real_value; 36 base::BinaryValue* real_value;
40 switch (message.data->GetType()) { 37 switch (message.data->GetType()) {
41 // JS string 38 // JS string
42 case base::Value::TYPE_STRING: 39 case base::Value::TYPE_STRING:
43 if (message.data->GetAsString(&data)) { 40 if (message.data->GetAsString(&data)) {
44 message_proto->set_payload_type(CastMessage_PayloadType_STRING); 41 message_proto->set_payload_type(CastMessage_PayloadType_STRING);
45 message_proto->set_payload_utf8(data); 42 message_proto->set_payload_utf8(data);
46 } 43 }
47 break; 44 break;
48 // JS ArrayBuffer 45 // JS ArrayBuffer
49 case base::Value::TYPE_BINARY: 46 case base::Value::TYPE_BINARY:
50 real_value = static_cast<base::BinaryValue*>(message.data.get()); 47 real_value = static_cast<base::BinaryValue*>(message.data.get());
51 if (real_value->GetBuffer()) { 48 if (real_value->GetBuffer()) {
52 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); 49 message_proto->set_payload_type(CastMessage_PayloadType_BINARY);
53 message_proto->set_payload_binary(real_value->GetBuffer(), 50 message_proto->set_payload_binary(real_value->GetBuffer(),
54 real_value->GetSize()); 51 real_value->GetSize());
55 } 52 }
56 break; 53 break;
57 default: 54 default:
58 // Unknown value type. message_proto will remain uninitialized because 55 // Unknown value type. message_proto will remain uninitialized because
59 // payload_type is unset. 56 // payload_type is unset.
60 break; 57 break;
61 } 58 }
62 return message_proto->IsInitialized(); 59 return message_proto->IsInitialized();
63 } 60 }
64 61
65 bool CastMessageToMessageInfo(const CastMessage& message_proto, 62 bool CastMessageToMessageInfo(const CastMessage& message_proto,
66 MessageInfo* message) { 63 MessageInfo* message) {
67 DCHECK(message); 64 DCHECK(message);
68 message->source_id = message_proto.source_id(); 65 message->source_id = message_proto.source_id();
69 message->destination_id = message_proto.destination_id(); 66 message->destination_id = message_proto.destination_id();
70 message->namespace_ = message_proto.namespace_(); 67 message->namespace_ = message_proto.namespace_();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 message_proto->set_payload_binary(auth_message_string); 137 message_proto->set_payload_binary(auth_message_string);
141 } 138 }
142 139
143 bool IsAuthMessage(const CastMessage& message) { 140 bool IsAuthMessage(const CastMessage& message) {
144 return message.namespace_() == kAuthNamespace; 141 return message.namespace_() == kAuthNamespace;
145 } 142 }
146 143
147 } // namespace cast_channel 144 } // namespace cast_channel
148 } // namespace api 145 } // namespace api
149 } // namespace extensions 146 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | trunk/src/chrome/browser/extensions/api/cast_channel/cast_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698