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

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

Issue 2065793002: Return a unique_ptr from BinaryValue::CreateWithCopiedBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android and CrOS Created 4 years, 6 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 <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 message->namespace_ = message_proto.namespace_(); 82 message->namespace_ = message_proto.namespace_();
83 // Determine the type of the payload and fill base::Value appropriately. 83 // Determine the type of the payload and fill base::Value appropriately.
84 std::unique_ptr<base::Value> value; 84 std::unique_ptr<base::Value> value;
85 switch (message_proto.payload_type()) { 85 switch (message_proto.payload_type()) {
86 case CastMessage_PayloadType_STRING: 86 case CastMessage_PayloadType_STRING:
87 if (message_proto.has_payload_utf8()) 87 if (message_proto.has_payload_utf8())
88 value.reset(new base::StringValue(message_proto.payload_utf8())); 88 value.reset(new base::StringValue(message_proto.payload_utf8()));
89 break; 89 break;
90 case CastMessage_PayloadType_BINARY: 90 case CastMessage_PayloadType_BINARY:
91 if (message_proto.has_payload_binary()) 91 if (message_proto.has_payload_binary())
92 value.reset(base::BinaryValue::CreateWithCopiedBuffer( 92 value = base::BinaryValue::CreateWithCopiedBuffer(
93 message_proto.payload_binary().data(), 93 message_proto.payload_binary().data(),
94 message_proto.payload_binary().size())); 94 message_proto.payload_binary().size());
95 break; 95 break;
96 default: 96 default:
97 // Unknown payload type. value will remain unset. 97 // Unknown payload type. value will remain unset.
98 break; 98 break;
99 } 99 }
100 if (value.get()) { 100 if (value.get()) {
101 DCHECK(!message->data.get()); 101 DCHECK(!message->data.get());
102 message->data.reset(value.release()); 102 message->data.reset(value.release());
103 return true; 103 return true;
104 } else { 104 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 message_proto->set_payload_binary(auth_message_string); 153 message_proto->set_payload_binary(auth_message_string);
154 } 154 }
155 155
156 bool IsAuthMessage(const CastMessage& message) { 156 bool IsAuthMessage(const CastMessage& message) {
157 return message.namespace_() == kAuthNamespace; 157 return message.namespace_() == kAuthNamespace;
158 } 158 }
159 159
160 } // namespace cast_channel 160 } // namespace cast_channel
161 } // namespace api 161 } // namespace api
162 } // namespace extensions 162 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698