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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "extensions/browser/api/cast_channel/cast_framer.h" 5 #include "extensions/browser/api/cast_channel/cast_framer.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 22 matching lines...) Expand all
33 DCHECK_GT(size, 0U); 33 DCHECK_GT(size, 0U);
34 message_size = size; 34 message_size = size;
35 } 35 }
36 36
37 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle, 37 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle,
38 // if bit-for-bit compatible. 38 // if bit-for-bit compatible.
39 void MessageFramer::MessageHeader::PrependToString(std::string* str) { 39 void MessageFramer::MessageHeader::PrependToString(std::string* str) {
40 MessageHeader output = *this; 40 MessageHeader output = *this;
41 output.message_size = base::HostToNet32(message_size); 41 output.message_size = base::HostToNet32(message_size);
42 size_t header_size = MessageHeader::header_size(); 42 size_t header_size = MessageHeader::header_size();
43 scoped_ptr<char, base::FreeDeleter> char_array( 43 std::unique_ptr<char, base::FreeDeleter> char_array(
44 static_cast<char*>(malloc(header_size))); 44 static_cast<char*>(malloc(header_size)));
45 memcpy(char_array.get(), &output, header_size); 45 memcpy(char_array.get(), &output, header_size);
46 str->insert(0, char_array.get(), header_size); 46 str->insert(0, char_array.get(), header_size);
47 } 47 }
48 48
49 // TODO(mfoltz): Investigate replacing header deserialization with base::Pickle, 49 // TODO(mfoltz): Investigate replacing header deserialization with base::Pickle,
50 // if bit-for-bit compatible. 50 // if bit-for-bit compatible.
51 void MessageFramer::MessageHeader::Deserialize(char* data, 51 void MessageFramer::MessageHeader::Deserialize(char* data,
52 MessageHeader* header) { 52 MessageHeader* header) {
53 uint32_t message_size; 53 uint32_t message_size;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 bytes_left, 106 bytes_left,
107 MessageHeader::max_message_size() - MessageHeader::header_size()); 107 MessageHeader::max_message_size() - MessageHeader::header_size());
108 VLOG(2) << "Bytes needed for body: " << bytes_left; 108 VLOG(2) << "Bytes needed for body: " << bytes_left;
109 return bytes_left; 109 return bytes_left;
110 default: 110 default:
111 NOTREACHED() << "Unhandled packet element type."; 111 NOTREACHED() << "Unhandled packet element type.";
112 return 0; 112 return 0;
113 } 113 }
114 } 114 }
115 115
116 scoped_ptr<CastMessage> MessageFramer::Ingest(size_t num_bytes, 116 std::unique_ptr<CastMessage> MessageFramer::Ingest(size_t num_bytes,
117 size_t* message_length, 117 size_t* message_length,
118 ChannelError* error) { 118 ChannelError* error) {
119 DCHECK(error); 119 DCHECK(error);
120 DCHECK(message_length); 120 DCHECK(message_length);
121 if (error_) { 121 if (error_) {
122 *error = CHANNEL_ERROR_INVALID_MESSAGE; 122 *error = CHANNEL_ERROR_INVALID_MESSAGE;
123 return nullptr; 123 return nullptr;
124 } 124 }
125 125
126 DCHECK_EQ(base::checked_cast<int32_t>(message_bytes_received_), 126 DCHECK_EQ(base::checked_cast<int32_t>(message_bytes_received_),
127 input_buffer_->offset()); 127 input_buffer_->offset());
128 CHECK_LE(num_bytes, BytesRequested()); 128 CHECK_LE(num_bytes, BytesRequested());
(...skipping 11 matching lines...) Expand all
140 *error = CHANNEL_ERROR_INVALID_MESSAGE; 140 *error = CHANNEL_ERROR_INVALID_MESSAGE;
141 error_ = true; 141 error_ = true;
142 return nullptr; 142 return nullptr;
143 } 143 }
144 current_element_ = BODY; 144 current_element_ = BODY;
145 body_size_ = header.message_size; 145 body_size_ = header.message_size;
146 } 146 }
147 break; 147 break;
148 case BODY: 148 case BODY:
149 if (BytesRequested() == 0) { 149 if (BytesRequested() == 0) {
150 scoped_ptr<CastMessage> parsed_message(new CastMessage); 150 std::unique_ptr<CastMessage> parsed_message(new CastMessage);
151 if (!parsed_message->ParseFromArray( 151 if (!parsed_message->ParseFromArray(
152 input_buffer_->StartOfBuffer() + MessageHeader::header_size(), 152 input_buffer_->StartOfBuffer() + MessageHeader::header_size(),
153 body_size_)) { 153 body_size_)) {
154 VLOG(1) << "Error parsing packet body."; 154 VLOG(1) << "Error parsing packet body.";
155 *error = CHANNEL_ERROR_INVALID_MESSAGE; 155 *error = CHANNEL_ERROR_INVALID_MESSAGE;
156 error_ = true; 156 error_ = true;
157 return nullptr; 157 return nullptr;
158 } 158 }
159 *message_length = body_size_; 159 *message_length = body_size_;
160 Reset(); 160 Reset();
(...skipping 12 matching lines...) Expand all
173 void MessageFramer::Reset() { 173 void MessageFramer::Reset() {
174 current_element_ = HEADER; 174 current_element_ = HEADER;
175 message_bytes_received_ = 0; 175 message_bytes_received_ = 0;
176 body_size_ = 0; 176 body_size_ = 0;
177 input_buffer_->set_offset(0); 177 input_buffer_->set_offset(0);
178 } 178 }
179 179
180 } // namespace cast_channel 180 } // namespace cast_channel
181 } // namespace api 181 } // namespace api
182 } // namespace extensions 182 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_framer.h ('k') | extensions/browser/api/cast_channel/cast_framer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698