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

Side by Side Diff: net/spdy/spdy_frame_builder.cc

Issue 6314010: Even more reordering the methods in headers and implementation in net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_proxy_client_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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <limits> 5 #include <limits>
6 6
7 #include "net/spdy/spdy_frame_builder.h" 7 #include "net/spdy/spdy_frame_builder.h"
8 #include "net/spdy/spdy_protocol.h" 8 #include "net/spdy/spdy_protocol.h"
9 9
10 namespace spdy { 10 namespace spdy {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 DCHECK(iter); 96 DCHECK(iter);
97 DCHECK(data); 97 DCHECK(data);
98 DCHECK(length); 98 DCHECK(length);
99 99
100 if (!ReadUInt16(iter, length)) 100 if (!ReadUInt16(iter, length))
101 return false; 101 return false;
102 102
103 return ReadBytes(iter, data, *length); 103 return ReadBytes(iter, data, *length);
104 } 104 }
105 105
106 char* SpdyFrameBuilder::BeginWrite(size_t length) { 106 bool SpdyFrameBuilder::WriteString(const std::string& value) {
107 size_t needed_size = length_ + length; 107 if (value.size() > 0xffff)
108 if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size))) 108 return false;
109 return NULL;
110 109
111 #ifdef ARCH_CPU_64_BITS 110 if (!WriteUInt16(static_cast<int>(value.size())))
112 DCHECK_LE(length, std::numeric_limits<uint32>::max()); 111 return false;
113 #endif
114 112
115 return buffer_ + length_; 113 return WriteBytes(value.data(), static_cast<uint16>(value.size()));
116 }
117
118 void SpdyFrameBuilder::EndWrite(char* dest, int length) {
119 } 114 }
120 115
121 bool SpdyFrameBuilder::WriteBytes(const void* data, uint16 data_len) { 116 bool SpdyFrameBuilder::WriteBytes(const void* data, uint16 data_len) {
122 DCHECK(capacity_ != kCapacityReadOnly); 117 DCHECK(capacity_ != kCapacityReadOnly);
123 118
124 char* dest = BeginWrite(data_len); 119 char* dest = BeginWrite(data_len);
125 if (!dest) 120 if (!dest)
126 return false; 121 return false;
127 122
128 memcpy(dest, data, data_len); 123 memcpy(dest, data, data_len);
129 124
130 EndWrite(dest, data_len); 125 EndWrite(dest, data_len);
131 length_ += data_len; 126 length_ += data_len;
132 return true; 127 return true;
133 } 128 }
134 129
135 bool SpdyFrameBuilder::WriteString(const std::string& value) {
136 if (value.size() > 0xffff)
137 return false;
138
139 if (!WriteUInt16(static_cast<int>(value.size())))
140 return false;
141
142 return WriteBytes(value.data(), static_cast<uint16>(value.size()));
143 }
144
145 char* SpdyFrameBuilder::BeginWriteData(uint16 length) { 130 char* SpdyFrameBuilder::BeginWriteData(uint16 length) {
146 DCHECK_EQ(variable_buffer_offset_, 0U) << 131 DCHECK_EQ(variable_buffer_offset_, 0U) <<
147 "There can only be one variable buffer in a SpdyFrameBuilder"; 132 "There can only be one variable buffer in a SpdyFrameBuilder";
148 133
149 if (!WriteUInt16(length)) 134 if (!WriteUInt16(length))
150 return NULL; 135 return NULL;
151 136
152 char *data_ptr = BeginWrite(length); 137 char *data_ptr = BeginWrite(length);
153 if (!data_ptr) 138 if (!data_ptr)
154 return NULL; 139 return NULL;
155 140
156 variable_buffer_offset_ = data_ptr - buffer_ - sizeof(int); 141 variable_buffer_offset_ = data_ptr - buffer_ - sizeof(int);
157 142
158 // EndWrite doesn't necessarily have to be called after the write operation, 143 // EndWrite doesn't necessarily have to be called after the write operation,
159 // so we call it here to pad out what the caller will eventually write. 144 // so we call it here to pad out what the caller will eventually write.
160 EndWrite(data_ptr, length); 145 EndWrite(data_ptr, length);
161 return data_ptr; 146 return data_ptr;
162 } 147 }
163 148
149 char* SpdyFrameBuilder::BeginWrite(size_t length) {
150 size_t needed_size = length_ + length;
151 if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size)))
152 return NULL;
153
154 #ifdef ARCH_CPU_64_BITS
155 DCHECK_LE(length, std::numeric_limits<uint32>::max());
156 #endif
157
158 return buffer_ + length_;
159 }
160
161 void SpdyFrameBuilder::EndWrite(char* dest, int length) {
162 }
163
164 bool SpdyFrameBuilder::Resize(size_t new_capacity) { 164 bool SpdyFrameBuilder::Resize(size_t new_capacity) {
165 if (new_capacity <= capacity_) 165 if (new_capacity <= capacity_)
166 return true; 166 return true;
167 167
168 char* p = new char[new_capacity]; 168 char* p = new char[new_capacity];
169 if (!p) 169 if (!p)
170 return false; 170 return false;
171 if (buffer_) { 171 if (buffer_) {
172 memcpy(p, buffer_, capacity_); 172 memcpy(p, buffer_, capacity_);
173 delete[] buffer_; 173 delete[] buffer_;
174 } 174 }
175 buffer_ = p; 175 buffer_ = p;
176 capacity_ = new_capacity; 176 capacity_ = new_capacity;
177 return true; 177 return true;
178 } 178 }
179 179
180 } // namespace spdy 180 } // namespace spdy
OLDNEW
« no previous file with comments | « net/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698