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

Side by Side Diff: net/websockets/websocket_basic_stream.cc

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 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 | « media/base/audio_bus.cc ('k') | net/websockets/websocket_channel.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 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_basic_stream.h" 5 #include "net/websockets/websocket_basic_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/safe_numerics.h" 15 #include "base/numerics/safe_conversions.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/socket/client_socket_handle.h" 18 #include "net/socket/client_socket_handle.h"
19 #include "net/websockets/websocket_errors.h" 19 #include "net/websockets/websocket_errors.h"
20 #include "net/websockets/websocket_frame.h" 20 #include "net/websockets/websocket_frame.h"
21 #include "net/websockets/websocket_frame_parser.h" 21 #include "net/websockets/websocket_frame_parser.h"
22 22
23 namespace net { 23 namespace net {
24 24
25 namespace { 25 namespace {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 DCHECK(is_final_chunk); 340 DCHECK(is_final_chunk);
341 *frame = CreateFrame(is_final_chunk, body); 341 *frame = CreateFrame(is_final_chunk, body);
342 return OK; 342 return OK;
343 } 343 }
344 } 344 }
345 345
346 // Apply basic sanity checks to the |payload_length| field from the frame 346 // Apply basic sanity checks to the |payload_length| field from the frame
347 // header. A check for exact equality can only be used when the whole frame 347 // header. A check for exact equality can only be used when the whole frame
348 // arrives in one chunk. 348 // arrives in one chunk.
349 DCHECK_GE(current_frame_header_->payload_length, 349 DCHECK_GE(current_frame_header_->payload_length,
350 base::checked_numeric_cast<uint64>(chunk_size)); 350 base::checked_cast<uint64>(chunk_size));
351 DCHECK(!is_first_chunk || !is_final_chunk || 351 DCHECK(!is_first_chunk || !is_final_chunk ||
352 current_frame_header_->payload_length == 352 current_frame_header_->payload_length ==
353 base::checked_numeric_cast<uint64>(chunk_size)); 353 base::checked_cast<uint64>(chunk_size));
354 354
355 // Convert the chunk to a complete frame. 355 // Convert the chunk to a complete frame.
356 *frame = CreateFrame(is_final_chunk, data_buffer); 356 *frame = CreateFrame(is_final_chunk, data_buffer);
357 return OK; 357 return OK;
358 } 358 }
359 359
360 scoped_ptr<WebSocketFrame> WebSocketBasicStream::CreateFrame( 360 scoped_ptr<WebSocketFrame> WebSocketBasicStream::CreateFrame(
361 bool is_final_chunk, 361 bool is_final_chunk,
362 const scoped_refptr<IOBufferWithSize>& data) { 362 const scoped_refptr<IOBufferWithSize>& data) {
363 scoped_ptr<WebSocketFrame> result_frame; 363 scoped_ptr<WebSocketFrame> result_frame;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 const CompletionCallback& callback, 406 const CompletionCallback& callback,
407 int result) { 407 int result) {
408 result = HandleReadResult(result, frames); 408 result = HandleReadResult(result, frames);
409 if (result == ERR_IO_PENDING) 409 if (result == ERR_IO_PENDING)
410 result = ReadFrames(frames, callback); 410 result = ReadFrames(frames, callback);
411 if (result != ERR_IO_PENDING) 411 if (result != ERR_IO_PENDING)
412 callback.Run(result); 412 callback.Run(result);
413 } 413 }
414 414
415 } // namespace net 415 } // namespace net
OLDNEW
« no previous file with comments | « media/base/audio_bus.cc ('k') | net/websockets/websocket_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698