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

Side by Side Diff: components/cast_channel/cast_framer.cc

Issue 2913033003: [cast_channel] Move cast_channel related files from //extensions to //components (Closed)
Patch Set: fix buildbot compile errors Created 3 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
« no previous file with comments | « components/cast_channel/cast_framer.h ('k') | components/cast_channel/cast_framer_unittest.cc » ('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 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 "components/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
11 #include "base/memory/free_deleter.h" 11 #include "base/memory/free_deleter.h"
12 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/sys_byteorder.h" 14 #include "base/sys_byteorder.h"
15 #include "extensions/common/api/cast_channel/cast_channel.pb.h" 15 #include "components/cast_channel/proto/cast_channel.pb.h"
16 16
17 namespace extensions {
18 namespace api {
19 namespace cast_channel { 17 namespace cast_channel {
20 MessageFramer::MessageFramer(scoped_refptr<net::GrowableIOBuffer> input_buffer) 18 MessageFramer::MessageFramer(scoped_refptr<net::GrowableIOBuffer> input_buffer)
21 : input_buffer_(input_buffer), error_(false) { 19 : input_buffer_(input_buffer), error_(false) {
22 Reset(); 20 Reset();
23 } 21 }
24 22
25 MessageFramer::~MessageFramer() { 23 MessageFramer::~MessageFramer() {}
26 }
27 24
28 MessageFramer::MessageHeader::MessageHeader() : message_size(0) { 25 MessageFramer::MessageHeader::MessageHeader() : message_size(0) {}
29 }
30 26
31 void MessageFramer::MessageHeader::SetMessageSize(size_t size) { 27 void MessageFramer::MessageHeader::SetMessageSize(size_t size) {
32 DCHECK_LT(size, static_cast<size_t>(std::numeric_limits<uint32_t>::max())); 28 DCHECK_LT(size, static_cast<size_t>(std::numeric_limits<uint32_t>::max()));
33 DCHECK_GT(size, 0U); 29 DCHECK_GT(size, 0U);
34 message_size = size; 30 message_size = size;
35 } 31 }
36 32
37 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle, 33 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle,
38 // if bit-for-bit compatible. 34 // if bit-for-bit compatible.
39 void MessageFramer::MessageHeader::PrependToString(std::string* str) { 35 void MessageFramer::MessageHeader::PrependToString(std::string* str) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 91
96 switch (current_element_) { 92 switch (current_element_) {
97 case HEADER: 93 case HEADER:
98 bytes_left = MessageHeader::header_size() - message_bytes_received_; 94 bytes_left = MessageHeader::header_size() - message_bytes_received_;
99 DCHECK_LE(bytes_left, MessageHeader::header_size()); 95 DCHECK_LE(bytes_left, MessageHeader::header_size());
100 VLOG(2) << "Bytes needed for header: " << bytes_left; 96 VLOG(2) << "Bytes needed for header: " << bytes_left;
101 return bytes_left; 97 return bytes_left;
102 case BODY: 98 case BODY:
103 bytes_left = 99 bytes_left =
104 (body_size_ + MessageHeader::header_size()) - message_bytes_received_; 100 (body_size_ + MessageHeader::header_size()) - message_bytes_received_;
105 DCHECK_LE( 101 DCHECK_LE(bytes_left, MessageHeader::max_message_size() -
106 bytes_left, 102 MessageHeader::header_size());
107 MessageHeader::max_message_size() - MessageHeader::header_size());
108 VLOG(2) << "Bytes needed for body: " << bytes_left; 103 VLOG(2) << "Bytes needed for body: " << bytes_left;
109 return bytes_left; 104 return bytes_left;
110 default: 105 default:
111 NOTREACHED() << "Unhandled packet element type."; 106 NOTREACHED() << "Unhandled packet element type.";
112 return 0; 107 return 0;
113 } 108 }
114 } 109 }
115 110
116 std::unique_ptr<CastMessage> MessageFramer::Ingest(size_t num_bytes, 111 std::unique_ptr<CastMessage> MessageFramer::Ingest(size_t num_bytes,
117 size_t* message_length, 112 size_t* message_length,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 165 }
171 166
172 void MessageFramer::Reset() { 167 void MessageFramer::Reset() {
173 current_element_ = HEADER; 168 current_element_ = HEADER;
174 message_bytes_received_ = 0; 169 message_bytes_received_ = 0;
175 body_size_ = 0; 170 body_size_ = 0;
176 input_buffer_->set_offset(0); 171 input_buffer_->set_offset(0);
177 } 172 }
178 173
179 } // namespace cast_channel 174 } // namespace cast_channel
180 } // namespace api
181 } // namespace extensions
OLDNEW
« no previous file with comments | « components/cast_channel/cast_framer.h ('k') | components/cast_channel/cast_framer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698