OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/websockets/websocket_deflate_stream.h" | 5 #include "net/websockets/websocket_deflate_stream.h" |
6 | 6 |
| 7 #include <stdint.h> |
7 #include <algorithm> | 8 #include <algorithm> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 const WebSocketFrameHeader::OpCode opcode = current_writing_opcode_; | 237 const WebSocketFrameHeader::OpCode opcode = current_writing_opcode_; |
237 scoped_refptr<IOBufferWithSize> compressed_payload = | 238 scoped_refptr<IOBufferWithSize> compressed_payload = |
238 deflater_.GetOutput(deflater_.CurrentOutputSize()); | 239 deflater_.GetOutput(deflater_.CurrentOutputSize()); |
239 if (!compressed_payload.get()) { | 240 if (!compressed_payload.get()) { |
240 DVLOG(1) << "WebSocket protocol error. " | 241 DVLOG(1) << "WebSocket protocol error. " |
241 << "deflater_.GetOutput() returns an error."; | 242 << "deflater_.GetOutput() returns an error."; |
242 return ERR_WS_PROTOCOL_ERROR; | 243 return ERR_WS_PROTOCOL_ERROR; |
243 } | 244 } |
244 | 245 |
245 uint64 original_payload_length = 0; | 246 uint64_t original_payload_length = 0; |
246 for (size_t i = 0; i < frames->size(); ++i) { | 247 for (size_t i = 0; i < frames->size(); ++i) { |
247 WebSocketFrame* frame = (*frames)[i]; | 248 WebSocketFrame* frame = (*frames)[i]; |
248 // Asserts checking that frames represent one whole data message. | 249 // Asserts checking that frames represent one whole data message. |
249 DCHECK(WebSocketFrameHeader::IsKnownDataOpCode(frame->header.opcode)); | 250 DCHECK(WebSocketFrameHeader::IsKnownDataOpCode(frame->header.opcode)); |
250 DCHECK_EQ(i == 0, | 251 DCHECK_EQ(i == 0, |
251 WebSocketFrameHeader::kOpCodeContinuation != | 252 WebSocketFrameHeader::kOpCodeContinuation != |
252 frame->header.opcode); | 253 frame->header.opcode); |
253 DCHECK_EQ(i == frames->size() - 1, frame->header.final); | 254 DCHECK_EQ(i == frames->size() - 1, frame->header.final); |
254 original_payload_length += frame->header.payload_length; | 255 original_payload_length += frame->header.payload_length; |
255 } | 256 } |
256 if (original_payload_length <= | 257 if (original_payload_length <= |
257 static_cast<uint64>(compressed_payload->size())) { | 258 static_cast<uint64_t>(compressed_payload->size())) { |
258 // Compression is not effective. Use the original frames. | 259 // Compression is not effective. Use the original frames. |
259 for (size_t i = 0; i < frames->size(); ++i) { | 260 for (size_t i = 0; i < frames->size(); ++i) { |
260 WebSocketFrame* frame = (*frames)[i]; | 261 WebSocketFrame* frame = (*frames)[i]; |
261 frames_to_write->push_back(frame); | 262 frames_to_write->push_back(frame); |
262 predictor_->RecordWrittenDataFrame(frame); | 263 predictor_->RecordWrittenDataFrame(frame); |
263 (*frames)[i] = NULL; | 264 (*frames)[i] = NULL; |
264 } | 265 } |
265 frames->weak_clear(); | 266 frames->weak_clear(); |
266 return OK; | 267 return OK; |
267 } | 268 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 DCHECK(!frames->empty()); | 390 DCHECK(!frames->empty()); |
390 | 391 |
391 result = Inflate(frames); | 392 result = Inflate(frames); |
392 } | 393 } |
393 if (result < 0) | 394 if (result < 0) |
394 frames->clear(); | 395 frames->clear(); |
395 return result; | 396 return result; |
396 } | 397 } |
397 | 398 |
398 } // namespace net | 399 } // namespace net |
OLD | NEW |