Socket Pools Refactor 21: Make HttpStreamParser use StreamSockets.

Previously it used ClientSocketHandles.

This change will make it easier to have it sit on top of a socket that
is not in a socket pool.

This is part of an effort to flatten the socket pools.
https://docs.google.com/document/d/1g0EA4iDqaDhNXA_mq-YK3SlSX-xRkoKvZetAQqdRrxM/edit

Bug: 472729
Change-Id: I77507a408ed5bcf1546f903e7fb7c82f7bb8a7c5
Reviewed-on: https://chromium-review.googlesource.com/c/1450864
Commit-Queue: Matt Menke <[email protected]>
Reviewed-by: Eric Roman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#629279}
diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc
index 08547fc..e91f713 100644
--- a/net/websockets/websocket_basic_handshake_stream.cc
+++ b/net/websockets/websocket_basic_handshake_stream.cc
@@ -33,6 +33,8 @@
 #include "net/socket/ssl_client_socket.h"
 #include "net/socket/websocket_endpoint_lock_manager.h"
 #include "net/socket/websocket_transport_client_socket_pool.h"
+#include "net/ssl/ssl_cert_request_info.h"
+#include "net/ssl/ssl_info.h"
 #include "net/websockets/websocket_basic_stream.h"
 #include "net/websockets/websocket_basic_stream_adapters.h"
 #include "net/websockets/websocket_deflate_parameters.h"
@@ -278,8 +280,12 @@
 void WebSocketBasicHandshakeStream::Close(bool not_reusable) {
   // This class ignores the value of |not_reusable| and never lets the socket be
   // re-used.
-  if (parser())
-    parser()->Close(true);
+  if (!parser())
+    return;
+  StreamSocket* socket = state_.connection()->socket();
+  if (socket)
+    socket->Disconnect();
+  state_.connection()->Reset();
 }
 
 bool WebSocketBasicHandshakeStream::IsResponseBodyComplete() const {
@@ -287,15 +293,16 @@
 }
 
 bool WebSocketBasicHandshakeStream::IsConnectionReused() const {
-  return parser()->IsConnectionReused();
+  return state_.IsConnectionReused();
 }
 
 void WebSocketBasicHandshakeStream::SetConnectionReused() {
-  parser()->SetConnectionReused();
+  state_.connection()->set_reuse_type(ClientSocketHandle::REUSED_IDLE);
 }
 
 bool WebSocketBasicHandshakeStream::CanReuseConnection() const {
-  return parser() && parser()->CanReuseConnection();
+  return parser() && state_.connection()->socket() &&
+         parser()->CanReuseConnection();
 }
 
 int64_t WebSocketBasicHandshakeStream::GetTotalReceivedBytes() const {
@@ -318,11 +325,19 @@
 }
 
 void WebSocketBasicHandshakeStream::GetSSLInfo(SSLInfo* ssl_info) {
+  if (!state_.connection()->socket()) {
+    ssl_info->Reset();
+    return;
+  }
   parser()->GetSSLInfo(ssl_info);
 }
 
 void WebSocketBasicHandshakeStream::GetSSLCertRequestInfo(
     SSLCertRequestInfo* cert_request_info) {
+  if (!state_.connection()->socket()) {
+    cert_request_info->Reset();
+    return;
+  }
   parser()->GetSSLCertRequestInfo(cert_request_info);
 }