OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ |
6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 88 } |
89 void SetClientMaxWindowBits() { | 89 void SetClientMaxWindowBits() { |
90 client_max_window_bits_ = WindowBits(0, true, false); | 90 client_max_window_bits_ = WindowBits(0, true, false); |
91 } | 91 } |
92 // |bits| must be valid as a max_window_bits value. | 92 // |bits| must be valid as a max_window_bits value. |
93 void SetClientMaxWindowBits(int bits) { | 93 void SetClientMaxWindowBits(int bits) { |
94 DCHECK(IsValidWindowBits(bits)); | 94 DCHECK(IsValidWindowBits(bits)); |
95 client_max_window_bits_ = WindowBits(bits, true, true); | 95 client_max_window_bits_ = WindowBits(bits, true, true); |
96 } | 96 } |
97 | 97 |
98 int PermissiveServerMaxWindowBits() const { | |
99 return server_max_window_bits_.PermissiveBits(); | |
100 } | |
101 int PermissiveClientMaxWindowBits() const { | |
102 return client_max_window_bits_.PermissiveBits(); | |
103 } | |
104 | |
98 // Return true if |bits| is valid as a max_window_bits value. | 105 // Return true if |bits| is valid as a max_window_bits value. |
99 static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; } | 106 static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; } |
100 | 107 |
101 private: | 108 private: |
102 struct WindowBits { | 109 struct WindowBits { |
103 WindowBits() : WindowBits(0, false, false) {} | 110 WindowBits() : WindowBits(0, false, false) {} |
104 WindowBits(int16_t bits, bool is_specified, bool has_value) | 111 WindowBits(int16_t bits, bool is_specified, bool has_value) |
105 : bits(bits), is_specified(is_specified), has_value(has_value) {} | 112 : bits(bits), is_specified(is_specified), has_value(has_value) {} |
106 | 113 |
114 int PermissiveBits() const { return is_specified && has_value ? bits : 15; } | |
davidben
2015/09/22 19:44:01
Nit: I'd put parens around the conditional. Not ob
yhirano
2015/09/28 03:17:06
Done.
| |
115 | |
107 int16_t bits; | 116 int16_t bits; |
108 // True when "window bits" parameter appears in the parameters. | 117 // True when "window bits" parameter appears in the parameters. |
109 bool is_specified; | 118 bool is_specified; |
110 // True when "window bits" parameter has the value. | 119 // True when "window bits" parameter has the value. |
111 bool has_value; | 120 bool has_value; |
112 }; | 121 }; |
113 | 122 |
114 // |server_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | 123 // |server_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and |
115 // only if |server_no_context_takeover| is set in the parameters. | 124 // only if |server_no_context_takeover| is set in the parameters. |
116 ContextTakeOverMode server_context_take_over_mode_ = | 125 ContextTakeOverMode server_context_take_over_mode_ = |
117 WebSocketDeflater::TAKE_OVER_CONTEXT; | 126 WebSocketDeflater::TAKE_OVER_CONTEXT; |
118 // |client_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | 127 // |client_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and |
119 // only if |client_no_context_takeover| is set in the parameters. | 128 // only if |client_no_context_takeover| is set in the parameters. |
120 ContextTakeOverMode client_context_take_over_mode_ = | 129 ContextTakeOverMode client_context_take_over_mode_ = |
121 WebSocketDeflater::TAKE_OVER_CONTEXT; | 130 WebSocketDeflater::TAKE_OVER_CONTEXT; |
122 WindowBits server_max_window_bits_; | 131 WindowBits server_max_window_bits_; |
123 WindowBits client_max_window_bits_; | 132 WindowBits client_max_window_bits_; |
124 }; | 133 }; |
125 | 134 |
126 } // namespace net | 135 } // namespace net |
127 | 136 |
128 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | 137 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ |
OLD | NEW |