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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_deflate_parameters.h
diff --git a/net/websockets/websocket_deflate_parameters.h b/net/websockets/websocket_deflate_parameters.h
new file mode 100644
index 0000000000000000000000000000000000000000..11f896741ab1fa51650f97d3efd69e4ef30a8f24
--- /dev/null
+++ b/net/websockets/websocket_deflate_parameters.h
@@ -0,0 +1,126 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_
+#define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_
+
+#include <string>
+
+#include "base/logging.h"
+#include "net/base/net_export.h"
+#include "net/websockets/websocket_deflater.h"
+#include "net/websockets/websocket_extension.h"
+
+namespace net {
+
+// A WebSocketDeflateParameters represents permessage-deflate extension
+// parameters. This class is used either for request and response.
+class NET_EXPORT_PRIVATE WebSocketDeflateParameters {
+ public:
+ 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.
+ // Returns a WebSocketExtension instance containing the parameters stored in
+ // this object.
+ WebSocketExtension AsExtension() const;
+
+ // Returns true when succeeded.
+ // Returns false and stores the failure message to |failure_message|
+ // otherwise.
+ // Note that even if this function succeeds it is not guaranteed that the
+ // object is valid. To check it, call IsValidAsRequest or IsValidAsResponse.
+ bool Initialize(const WebSocketExtension& input,
+ std::string* failure_message);
+
+ // Returns true when |*this| and |response| are compatible.
+ // |*this| must be valid as a request and |response| must be valid as a
+ // response.
+ bool IsCompatibleWith(const WebSocketDeflateParameters& response) const;
+
+ bool IsValidAsRequest(std::string* failure_message) const;
+ bool IsValidAsResponse(std::string* failure_message) const;
+ bool IsValidAsRequest() const {
+ std::string message;
+ return IsValidAsRequest(&message);
+ }
+ bool IsValidAsResponse() const {
+ std::string message;
+ return IsValidAsResponse(&message);
+ }
+
+ ContextTakeOverMode server_context_take_over_mode() const {
+ return server_context_take_over_mode_;
+ }
+ ContextTakeOverMode client_context_take_over_mode() const {
+ return client_context_take_over_mode_;
+ }
+ bool is_server_max_window_bits_specified() const {
+ return server_max_window_bits_.is_specified;
+ }
+ int server_max_window_bits() const {
+ DCHECK(is_server_max_window_bits_specified());
+ return server_max_window_bits_.bits;
+ }
+ bool is_client_max_window_bits_specified() const {
+ return client_max_window_bits_.is_specified;
+ }
+ bool has_client_max_window_bits_value() const {
+ DCHECK(is_client_max_window_bits_specified());
+ return client_max_window_bits_.has_value;
+ }
+ int client_max_window_bits() const {
+ DCHECK(has_client_max_window_bits_value());
+ return client_max_window_bits_.bits;
+ }
+ void SetServerNoContextTakeOver() {
+ server_context_take_over_mode_ =
+ WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT;
+ }
+ void SetClientNoContextTakeOver() {
+ client_context_take_over_mode_ =
+ WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT;
+ }
+ // |bits| must be valid as a max_window_bits value.
+ void SetServerMaxWindowBits(int bits) {
+ DCHECK(IsValidWindowBits(bits));
+ server_max_window_bits_ = WindowBits(bits, true, true);
+ }
+ void SetClientMaxWindowBits() {
+ client_max_window_bits_ = WindowBits(0, true, false);
+ }
+ // |bits| must be valid as a max_window_bits value.
+ void SetClientMaxWindowBits(int bits) {
+ DCHECK(IsValidWindowBits(bits));
+ client_max_window_bits_ = WindowBits(bits, true, true);
+ }
+
+ // Return true if |bits| is valid as a max_window_bits value.
+ static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; }
+
+ private:
+ struct WindowBits {
+ WindowBits() : WindowBits(0, false, false) {}
+ 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.
+ : bits(bits), is_specified(is_specified), has_value(has_value) {}
+
+ int16 bits;
+ // True when "window bits" parameter appears in the parameters.
+ bool is_specified;
+ // True when "window bits" parameter has the value.
+ bool has_value;
+ };
+
+ // |server_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and
+ // only if |server_no_context_takeover| is set in the parameters.
+ ContextTakeOverMode server_context_take_over_mode_ =
+ WebSocketDeflater::TAKE_OVER_CONTEXT;
+ // |client_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and
+ // only if |client_no_context_takeover| is set in the parameters.
+ ContextTakeOverMode client_context_take_over_mode_ =
+ WebSocketDeflater::TAKE_OVER_CONTEXT;
+ WindowBits server_max_window_bits_;
+ WindowBits client_max_window_bits_;
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_
« 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