OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_frame_parser.h" | 5 #include "net/websockets/websocket_frame_parser.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/big_endian.h" | 12 #include "base/big_endian.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
16 #include "net/websockets/websocket_frame.h" | 17 #include "net/websockets/websocket_frame.h" |
17 | 18 |
18 namespace { | 19 namespace { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // If frame header is incomplete, then carry over the remaining | 65 // If frame header is incomplete, then carry over the remaining |
65 // data to the next round of Decode(). | 66 // data to the next round of Decode(). |
66 if (!current_frame_header_.get()) | 67 if (!current_frame_header_.get()) |
67 break; | 68 break; |
68 first_chunk = true; | 69 first_chunk = true; |
69 } | 70 } |
70 | 71 |
71 scoped_ptr<WebSocketFrameChunk> frame_chunk = | 72 scoped_ptr<WebSocketFrameChunk> frame_chunk = |
72 DecodeFramePayload(first_chunk); | 73 DecodeFramePayload(first_chunk); |
73 DCHECK(frame_chunk.get()); | 74 DCHECK(frame_chunk.get()); |
74 frame_chunks->push_back(frame_chunk.Pass()); | 75 frame_chunks->push_back(std::move(frame_chunk)); |
75 | 76 |
76 if (current_frame_header_.get()) { | 77 if (current_frame_header_.get()) { |
77 DCHECK(current_read_pos_ == buffer_.size()); | 78 DCHECK(current_read_pos_ == buffer_.size()); |
78 break; | 79 break; |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
82 // Drain unnecessary data. TODO(yutak): Remove copy. (but how?) | 83 // Drain unnecessary data. TODO(yutak): Remove copy. (but how?) |
83 buffer_.erase(buffer_.begin(), buffer_.begin() + current_read_pos_); | 84 buffer_.erase(buffer_.begin(), buffer_.begin() + current_read_pos_); |
84 current_read_pos_ = 0; | 85 current_read_pos_ = 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 frame_offset_ += next_size; | 197 frame_offset_ += next_size; |
197 } | 198 } |
198 | 199 |
199 DCHECK_LE(frame_offset_, current_frame_header_->payload_length); | 200 DCHECK_LE(frame_offset_, current_frame_header_->payload_length); |
200 if (frame_offset_ == current_frame_header_->payload_length) { | 201 if (frame_offset_ == current_frame_header_->payload_length) { |
201 frame_chunk->final_chunk = true; | 202 frame_chunk->final_chunk = true; |
202 current_frame_header_.reset(); | 203 current_frame_header_.reset(); |
203 frame_offset_ = 0; | 204 frame_offset_ = 0; |
204 } | 205 } |
205 | 206 |
206 return frame_chunk.Pass(); | 207 return frame_chunk; |
207 } | 208 } |
208 | 209 |
209 } // namespace net | 210 } // namespace net |
OLD | NEW |