[WebSocket] Add --websocket-read-buffer-size command line flag.

This patch adds the flag that overrides default read buffer size
(32k Bytes) for WebSocket.
The buffer is the first pool to receive date from network socket.
This flag will be used to investigate the performance issue.

You can use this flag both on chrome and content_shell:
$ ./chrome.exe --websocket-read-buffer-size=3000000
This flag sets the buffer size 300k Bytes.

Bug: 865001
Change-Id: I57aeb9e2feb9b249f1265596d6da5524a63f801a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635079
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Yutaka Hirano <[email protected]>
Reviewed-by: Adam Rice <[email protected]>
Commit-Queue: Yoichi Osato <[email protected]>
Cr-Commit-Position: refs/heads/master@{#665867}
diff --git a/net/websockets/websocket_basic_stream.cc b/net/websockets/websocket_basic_stream.cc
index 0fa933d..3862ec3 100644
--- a/net/websockets/websocket_basic_stream.cc
+++ b/net/websockets/websocket_basic_stream.cc
@@ -11,9 +11,11 @@
 #include <utility>
 
 #include "base/bind.h"
+#include "base/command_line.h"
 #include "base/logging.h"
 #include "base/metrics/histogram_macros.h"
 #include "base/numerics/safe_conversions.h"
+#include "base/strings/string_number_conversions.h"
 #include "net/base/io_buffer.h"
 #include "net/base/net_errors.h"
 #include "net/socket/client_socket_handle.h"
@@ -94,13 +96,17 @@
 
 }  // namespace
 
+// Overrides default read buffer size for WebSocket. This flag will be used to
+// investigate the performance issue of crbug.com/865001 and be deleted later
+// on.
+const char kWebSocketReadBufferSize[] = "websocket-read-buffer-size";
+
 WebSocketBasicStream::WebSocketBasicStream(
     std::unique_ptr<Adapter> connection,
     const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
     const std::string& sub_protocol,
     const std::string& extensions)
-    : read_buffer_(base::MakeRefCounted<IOBufferWithSize>(kReadBufferSize)),
-      connection_(std::move(connection)),
+    : connection_(std::move(connection)),
       http_read_buffer_(http_read_buffer),
       sub_protocol_(sub_protocol),
       extensions_(extensions),
@@ -109,6 +115,21 @@
   if (http_read_buffer_.get() && http_read_buffer_->offset() == 0)
     http_read_buffer_ = nullptr;
   DCHECK(connection_->is_initialized());
+  base::CommandLine* const command_line =
+      base::CommandLine::ForCurrentProcess();
+  DCHECK(command_line);
+  int websocket_buffer_size = kReadBufferSize;
+  if (command_line->HasSwitch(kWebSocketReadBufferSize)) {
+    std::string size_string =
+        command_line->GetSwitchValueASCII(kWebSocketReadBufferSize);
+    if (!base::StringToInt(size_string, &websocket_buffer_size) ||
+        websocket_buffer_size <= 0) {
+      websocket_buffer_size = kReadBufferSize;
+    }
+  }
+  DVLOG(1) << "WebSocketReadBufferSize is " << websocket_buffer_size;
+  read_buffer_ =
+      (base::MakeRefCounted<IOBufferWithSize>(websocket_buffer_size));
 }
 
 WebSocketBasicStream::~WebSocketBasicStream() { Close(); }