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

Side by Side Diff: content/common/android/gin_java_bridge_value.cc

Issue 2841623003: Remove base::Value::Get{Buffer,Size} (Closed)
Patch Set: std::vector::assign instead of std::vector::operator= Created 3 years, 8 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 "content/common/android/gin_java_bridge_value.h" 5 #include "content/common/android/gin_java_bridge_value.h"
6 6
7 namespace content { 7 namespace content {
8 8
9 namespace { 9 namespace {
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int32_t in_value) { 50 int32_t in_value) {
51 GinJavaBridgeValue gin_value(TYPE_OBJECT_ID); 51 GinJavaBridgeValue gin_value(TYPE_OBJECT_ID);
52 gin_value.pickle_.WriteInt(in_value); 52 gin_value.pickle_.WriteInt(in_value);
53 return gin_value.SerializeToBinaryValue(); 53 return gin_value.SerializeToBinaryValue();
54 } 54 }
55 55
56 // static 56 // static
57 bool GinJavaBridgeValue::ContainsGinJavaBridgeValue(const base::Value* value) { 57 bool GinJavaBridgeValue::ContainsGinJavaBridgeValue(const base::Value* value) {
58 if (!value->IsType(base::Value::Type::BINARY)) 58 if (!value->IsType(base::Value::Type::BINARY))
59 return false; 59 return false;
60 if (value->GetSize() < sizeof(Header)) 60 if (value->GetBlob().size() < sizeof(Header))
61 return false; 61 return false;
62 base::Pickle pickle(value->GetBuffer(), value->GetSize()); 62 base::Pickle pickle(value->GetBlob().data(), value->GetBlob().size());
63 // Broken binary value: payload or header size is wrong 63 // Broken binary value: payload or header size is wrong
64 if (!pickle.data() || pickle.size() - pickle.payload_size() != sizeof(Header)) 64 if (!pickle.data() || pickle.size() - pickle.payload_size() != sizeof(Header))
65 return false; 65 return false;
66 Header* header = pickle.headerT<Header>(); 66 Header* header = pickle.headerT<Header>();
67 return (header->magic == kHeaderMagic && 67 return (header->magic == kHeaderMagic &&
68 header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE); 68 header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE);
69 } 69 }
70 70
71 // static 71 // static
72 std::unique_ptr<const GinJavaBridgeValue> GinJavaBridgeValue::FromValue( 72 std::unique_ptr<const GinJavaBridgeValue> GinJavaBridgeValue::FromValue(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 GinJavaBridgeValue::GinJavaBridgeValue(Type type) : 107 GinJavaBridgeValue::GinJavaBridgeValue(Type type) :
108 pickle_(sizeof(Header)) { 108 pickle_(sizeof(Header)) {
109 Header* header = pickle_.headerT<Header>(); 109 Header* header = pickle_.headerT<Header>();
110 header->magic = kHeaderMagic; 110 header->magic = kHeaderMagic;
111 header->type = type; 111 header->type = type;
112 } 112 }
113 113
114 GinJavaBridgeValue::GinJavaBridgeValue(const base::Value* value) 114 GinJavaBridgeValue::GinJavaBridgeValue(const base::Value* value)
115 : pickle_(value->GetBuffer(), value->GetSize()) { 115 : pickle_(value->GetBlob().data(), value->GetBlob().size()) {
116 DCHECK(ContainsGinJavaBridgeValue(value)); 116 DCHECK(ContainsGinJavaBridgeValue(value));
117 } 117 }
118 118
119 std::unique_ptr<base::Value> GinJavaBridgeValue::SerializeToBinaryValue() { 119 std::unique_ptr<base::Value> GinJavaBridgeValue::SerializeToBinaryValue() {
120 return base::Value::CreateWithCopiedBuffer( 120 return base::Value::CreateWithCopiedBuffer(
121 reinterpret_cast<const char*>(pickle_.data()), pickle_.size()); 121 reinterpret_cast<const char*>(pickle_.data()), pickle_.size());
122 } 122 }
123 123
124 } // namespace content 124 } // namespace content
OLDNEW
« no previous file with comments | « content/child/v8_value_converter_impl.cc ('k') | extensions/browser/api/cast_channel/cast_message_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698