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

Side by Side Diff: mojo/services/network/web_socket_impl.cc

Issue 1468803002: Switch to static_assert. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@assert1
Patch Set: message cleanup Created 5 years 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 | « mojo/environment/default_logger_impl.cc ('k') | sandbox/linux/services/namespace_utils.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 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 "mojo/services/network/web_socket_impl.h" 5 #include "mojo/services/network/web_socket_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "mojo/message_pump/handle_watcher.h" 9 #include "mojo/message_pump/handle_watcher.h"
10 #include "mojo/services/network/network_context.h" 10 #include "mojo/services/network/network_context.h"
(...skipping 13 matching lines...) Expand all
24 struct TypeConverter<net::WebSocketFrameHeader::OpCode, 24 struct TypeConverter<net::WebSocketFrameHeader::OpCode,
25 WebSocket::MessageType> { 25 WebSocket::MessageType> {
26 static net::WebSocketFrameHeader::OpCode Convert( 26 static net::WebSocketFrameHeader::OpCode Convert(
27 WebSocket::MessageType type) { 27 WebSocket::MessageType type) {
28 DCHECK(type == WebSocket::MESSAGE_TYPE_CONTINUATION || 28 DCHECK(type == WebSocket::MESSAGE_TYPE_CONTINUATION ||
29 type == WebSocket::MESSAGE_TYPE_TEXT || 29 type == WebSocket::MESSAGE_TYPE_TEXT ||
30 type == WebSocket::MESSAGE_TYPE_BINARY); 30 type == WebSocket::MESSAGE_TYPE_BINARY);
31 typedef net::WebSocketFrameHeader::OpCode OpCode; 31 typedef net::WebSocketFrameHeader::OpCode OpCode;
32 // These compile asserts verify that the same underlying values are used for 32 // These compile asserts verify that the same underlying values are used for
33 // both types, so we can simply cast between them. 33 // both types, so we can simply cast between them.
34 COMPILE_ASSERT(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_CONTINUATION) == 34 static_assert(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_CONTINUATION) ==
35 net::WebSocketFrameHeader::kOpCodeContinuation, 35 net::WebSocketFrameHeader::kOpCodeContinuation,
36 enum_values_must_match_for_opcode_continuation); 36 "enum values must match for opcode continuation");
37 COMPILE_ASSERT(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_TEXT) == 37 static_assert(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_TEXT) ==
38 net::WebSocketFrameHeader::kOpCodeText, 38 net::WebSocketFrameHeader::kOpCodeText,
39 enum_values_must_match_for_opcode_text); 39 "enum values must match for opcode text");
40 COMPILE_ASSERT(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_BINARY) == 40 static_assert(static_cast<OpCode>(WebSocket::MESSAGE_TYPE_BINARY) ==
41 net::WebSocketFrameHeader::kOpCodeBinary, 41 net::WebSocketFrameHeader::kOpCodeBinary,
42 enum_values_must_match_for_opcode_binary); 42 "enum values must match for opcode binary");
43 return static_cast<OpCode>(type); 43 return static_cast<OpCode>(type);
44 } 44 }
45 }; 45 };
46 46
47 template <> 47 template <>
48 struct TypeConverter<WebSocket::MessageType, 48 struct TypeConverter<WebSocket::MessageType,
49 net::WebSocketFrameHeader::OpCode> { 49 net::WebSocketFrameHeader::OpCode> {
50 static WebSocket::MessageType Convert( 50 static WebSocket::MessageType Convert(
51 net::WebSocketFrameHeader::OpCode type) { 51 net::WebSocketFrameHeader::OpCode type) {
52 DCHECK(type == net::WebSocketFrameHeader::kOpCodeContinuation || 52 DCHECK(type == net::WebSocketFrameHeader::kOpCodeContinuation ||
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 uint32_t num_bytes, 230 uint32_t num_bytes,
231 const char* data) { 231 const char* data) {
232 std::vector<char> buffer(num_bytes); 232 std::vector<char> buffer(num_bytes);
233 memcpy(&buffer[0], data, num_bytes); 233 memcpy(&buffer[0], data, num_bytes);
234 DCHECK(channel_); 234 DCHECK(channel_);
235 channel_->SendFrame( 235 channel_->SendFrame(
236 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); 236 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer);
237 } 237 }
238 238
239 } // namespace mojo 239 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/environment/default_logger_impl.cc ('k') | sandbox/linux/services/namespace_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698