Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "net/base/net_export.h" | |
| 12 #include "net/websockets/websocket_deflater.h" | |
| 13 #include "net/websockets/websocket_extension.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 // A WebSocketDeflateParameters represents permessage-deflate extension | |
| 18 // parameters. This class is used either for request and response. | |
| 19 class NET_EXPORT_PRIVATE WebSocketDeflateParameters { | |
| 20 public: | |
| 21 using ContextTakeOverMode = WebSocketDeflater::ContextTakeOverMode; | |
|
davidben
2015/09/11 15:40:49
Nit: I'd probably stick a newline here.
yhirano
2015/09/14 02:01:10
Done.
| |
| 22 // Returns a WebSocketExtension instance containing the parameters stored in | |
| 23 // this object. | |
| 24 WebSocketExtension AsExtension() const; | |
| 25 | |
| 26 // Returns true when succeeded. | |
| 27 // Returns false and stores the failure message to |failure_message| | |
| 28 // otherwise. | |
| 29 // Note that even if this function succeeds it is not guaranteed that the | |
| 30 // object is valid. To check it, call IsValidAsRequest or IsValidAsResponse. | |
| 31 bool Initialize(const WebSocketExtension& input, | |
| 32 std::string* failure_message); | |
| 33 | |
| 34 // Returns true when |*this| and |response| are compatible. | |
| 35 // |*this| must be valid as a request and |response| must be valid as a | |
| 36 // response. | |
| 37 bool IsCompatibleWith(const WebSocketDeflateParameters& response) const; | |
| 38 | |
| 39 bool IsValidAsRequest(std::string* failure_message) const; | |
| 40 bool IsValidAsResponse(std::string* failure_message) const; | |
| 41 bool IsValidAsRequest() const { | |
| 42 std::string message; | |
| 43 return IsValidAsRequest(&message); | |
| 44 } | |
| 45 bool IsValidAsResponse() const { | |
| 46 std::string message; | |
| 47 return IsValidAsResponse(&message); | |
| 48 } | |
| 49 | |
| 50 ContextTakeOverMode server_context_take_over_mode() const { | |
| 51 return server_context_take_over_mode_; | |
| 52 } | |
| 53 ContextTakeOverMode client_context_take_over_mode() const { | |
| 54 return client_context_take_over_mode_; | |
| 55 } | |
| 56 bool is_server_max_window_bits_specified() const { | |
| 57 return server_max_window_bits_.is_specified; | |
| 58 } | |
| 59 int server_max_window_bits() const { | |
| 60 DCHECK(is_server_max_window_bits_specified()); | |
| 61 return server_max_window_bits_.bits; | |
| 62 } | |
| 63 bool is_client_max_window_bits_specified() const { | |
| 64 return client_max_window_bits_.is_specified; | |
| 65 } | |
| 66 bool has_client_max_window_bits_value() const { | |
| 67 DCHECK(is_client_max_window_bits_specified()); | |
| 68 return client_max_window_bits_.has_value; | |
| 69 } | |
| 70 int client_max_window_bits() const { | |
| 71 DCHECK(has_client_max_window_bits_value()); | |
| 72 return client_max_window_bits_.bits; | |
| 73 } | |
| 74 void SetServerNoContextTakeOver() { | |
| 75 server_context_take_over_mode_ = | |
| 76 WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT; | |
| 77 } | |
| 78 void SetClientNoContextTakeOver() { | |
| 79 client_context_take_over_mode_ = | |
| 80 WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT; | |
| 81 } | |
| 82 // |bits| must be valid as a max_window_bits value. | |
| 83 void SetServerMaxWindowBits(int bits) { | |
| 84 DCHECK(IsValidWindowBits(bits)); | |
| 85 server_max_window_bits_ = WindowBits(bits, true, true); | |
| 86 } | |
| 87 void SetClientMaxWindowBits() { | |
| 88 client_max_window_bits_ = WindowBits(0, true, false); | |
| 89 } | |
| 90 // |bits| must be valid as a max_window_bits value. | |
| 91 void SetClientMaxWindowBits(int bits) { | |
| 92 DCHECK(IsValidWindowBits(bits)); | |
| 93 client_max_window_bits_ = WindowBits(bits, true, true); | |
| 94 } | |
| 95 | |
| 96 // Return true if |bits| is valid as a max_window_bits value. | |
| 97 static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; } | |
| 98 | |
| 99 private: | |
| 100 struct WindowBits { | |
| 101 WindowBits() : WindowBits(0, false, false) {} | |
| 102 WindowBits(int16 bits, bool is_specified, bool has_value) | |
|
davidben
2015/09/11 15:40:49
Nit: New code should use int16_t per http://google
yhirano
2015/09/14 02:01:10
Done.
| |
| 103 : bits(bits), is_specified(is_specified), has_value(has_value) {} | |
| 104 | |
| 105 int16 bits; | |
| 106 // True when "window bits" parameter appears in the parameters. | |
| 107 bool is_specified; | |
| 108 // True when "window bits" parameter has the value. | |
| 109 bool has_value; | |
| 110 }; | |
| 111 | |
| 112 // |server_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | |
| 113 // only if |server_no_context_takeover| is set in the parameters. | |
| 114 ContextTakeOverMode server_context_take_over_mode_ = | |
| 115 WebSocketDeflater::TAKE_OVER_CONTEXT; | |
| 116 // |client_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | |
| 117 // only if |client_no_context_takeover| is set in the parameters. | |
| 118 ContextTakeOverMode client_context_take_over_mode_ = | |
| 119 WebSocketDeflater::TAKE_OVER_CONTEXT; | |
| 120 WindowBits server_max_window_bits_; | |
| 121 WindowBits client_max_window_bits_; | |
| 122 }; | |
| 123 | |
| 124 } // namespace net | |
| 125 | |
| 126 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
| OLD | NEW |