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

Side by Side Diff: net/websockets/websocket_deflate_parameters.h

Issue 1324113002: Introduce WebSocketDeflateParameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(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 <stdint.h>
9 #include <string>
10
11 #include "base/logging.h"
12 #include "net/base/net_export.h"
13 #include "net/websockets/websocket_deflater.h"
14 #include "net/websockets/websocket_extension.h"
15
16 namespace net {
17
18 // A WebSocketDeflateParameters represents permessage-deflate extension
19 // parameters. This class is used either for request and response.
20 class NET_EXPORT_PRIVATE WebSocketDeflateParameters {
21 public:
22 using ContextTakeOverMode = WebSocketDeflater::ContextTakeOverMode;
23
24 // Returns a WebSocketExtension instance containing the parameters stored in
25 // this object.
26 WebSocketExtension AsExtension() const;
27
28 // Returns true when succeeded.
29 // Returns false and stores the failure message to |failure_message|
30 // otherwise.
31 // Note that even if this function succeeds it is not guaranteed that the
32 // object is valid. To check it, call IsValidAsRequest or IsValidAsResponse.
33 bool Initialize(const WebSocketExtension& input,
34 std::string* failure_message);
35
36 // Returns true when |*this| and |response| are compatible.
37 // |*this| must be valid as a request and |response| must be valid as a
38 // response.
39 bool IsCompatibleWith(const WebSocketDeflateParameters& response) const;
40
41 bool IsValidAsRequest(std::string* failure_message) const;
42 bool IsValidAsResponse(std::string* failure_message) const;
43 bool IsValidAsRequest() const {
44 std::string message;
45 return IsValidAsRequest(&message);
46 }
47 bool IsValidAsResponse() const {
48 std::string message;
49 return IsValidAsResponse(&message);
50 }
51
52 ContextTakeOverMode server_context_take_over_mode() const {
53 return server_context_take_over_mode_;
54 }
55 ContextTakeOverMode client_context_take_over_mode() const {
56 return client_context_take_over_mode_;
57 }
58 bool is_server_max_window_bits_specified() const {
59 return server_max_window_bits_.is_specified;
60 }
61 int server_max_window_bits() const {
62 DCHECK(is_server_max_window_bits_specified());
63 return server_max_window_bits_.bits;
64 }
65 bool is_client_max_window_bits_specified() const {
66 return client_max_window_bits_.is_specified;
67 }
68 bool has_client_max_window_bits_value() const {
69 DCHECK(is_client_max_window_bits_specified());
70 return client_max_window_bits_.has_value;
71 }
72 int client_max_window_bits() const {
73 DCHECK(has_client_max_window_bits_value());
74 return client_max_window_bits_.bits;
75 }
76 void SetServerNoContextTakeOver() {
77 server_context_take_over_mode_ =
78 WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT;
79 }
80 void SetClientNoContextTakeOver() {
81 client_context_take_over_mode_ =
82 WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT;
83 }
84 // |bits| must be valid as a max_window_bits value.
85 void SetServerMaxWindowBits(int bits) {
86 DCHECK(IsValidWindowBits(bits));
87 server_max_window_bits_ = WindowBits(bits, true, true);
88 }
89 void SetClientMaxWindowBits() {
90 client_max_window_bits_ = WindowBits(0, true, false);
91 }
92 // |bits| must be valid as a max_window_bits value.
93 void SetClientMaxWindowBits(int bits) {
94 DCHECK(IsValidWindowBits(bits));
95 client_max_window_bits_ = WindowBits(bits, true, true);
96 }
97
98 // Return true if |bits| is valid as a max_window_bits value.
99 static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; }
100
101 private:
102 struct WindowBits {
103 WindowBits() : WindowBits(0, false, false) {}
104 WindowBits(int16_t bits, bool is_specified, bool has_value)
105 : bits(bits), is_specified(is_specified), has_value(has_value) {}
106
107 int16_t bits;
108 // True when "window bits" parameter appears in the parameters.
109 bool is_specified;
110 // True when "window bits" parameter has the value.
111 bool has_value;
112 };
113
114 // |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.
116 ContextTakeOverMode server_context_take_over_mode_ =
117 WebSocketDeflater::TAKE_OVER_CONTEXT;
118 // |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.
120 ContextTakeOverMode client_context_take_over_mode_ =
121 WebSocketDeflater::TAKE_OVER_CONTEXT;
122 WindowBits server_max_window_bits_;
123 WindowBits client_max_window_bits_;
124 };
125
126 } // namespace net
127
128 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_
OLDNEW
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('k') | net/websockets/websocket_deflate_parameters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698