summaryrefslogtreecommitdiffstats
path: root/net/socket/client_socket.cc
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 07:10:24 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 07:10:24 +0000
commit9008c86f2a99b112300ef7833d35f2ff1696a88a (patch)
tree9ba3e6a50b61f76612f3db42b18e5f10ae6f364a /net/socket/client_socket.cc
parent6a054ffaae82f5ac8d6b876d7c85f0d87d892e42 (diff)
downloadchromium_src-9008c86f2a99b112300ef7833d35f2ff1696a88a.zip
chromium_src-9008c86f2a99b112300ef7833d35f2ff1696a88a.tar.gz
chromium_src-9008c86f2a99b112300ef7833d35f2ff1696a88a.tar.bz2
Reland 54771 (and 54795) To enable TCP Preconnection by default
I pulled out the code to update the socket connectivity stats. I added defensive code which should preclude the crash that was reported on the stability bot. I added a second call to update the stats from ~ClientSocketHandle to ensure that we updated the related ClientSocket when we are torn down. As noted in the original checkin: Enable speculative preconnection by default Added histogram to track preconnection utilization (vs waste). BUG=42694 r=mbelshe Review URL: http://codereview.chromium.org/3050040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket.cc')
-rw-r--r--net/socket/client_socket.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/net/socket/client_socket.cc b/net/socket/client_socket.cc
new file mode 100644
index 0000000..c0c62cd
--- /dev/null
+++ b/net/socket/client_socket.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 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.
+
+#include "net/socket/client_socket.h"
+
+#include "base/histogram.h"
+
+namespace net {
+
+ClientSocket::ClientSocket()
+ : was_ever_connected_(false),
+ omnibox_speculation_(false),
+ subresource_speculation_(false),
+ was_used_to_transmit_data_(false) {}
+
+ClientSocket::~ClientSocket() {
+ EmitPreconnectionHistograms();
+}
+
+void ClientSocket::EmitPreconnectionHistograms() const {
+ DCHECK(!subresource_speculation_ || !omnibox_speculation_);
+ // 0 ==> non-speculative, never connected.
+ // 1 ==> non-speculative never used (but connected).
+ // 2 ==> non-speculative and used.
+ // 3 ==> omnibox_speculative never connected.
+ // 4 ==> omnibox_speculative never used (but connected).
+ // 5 ==> omnibox_speculative and used.
+ // 6 ==> subresource_speculative never connected.
+ // 7 ==> subresource_speculative never used (but connected).
+ // 8 ==> subresource_speculative and used.
+ int result;
+ if (was_used_to_transmit_data_)
+ result = 2;
+ else if (was_ever_connected_)
+ result = 1;
+ else
+ result = 0; // Never used, and not really connected.
+
+ if (omnibox_speculation_)
+ result += 3;
+ else if (subresource_speculation_)
+ result += 6;
+ UMA_HISTOGRAM_ENUMERATION("Net.PreconnectUtilization", result, 9);
+}
+
+void ClientSocket::SetSubresourceSpeculation() {
+ if (was_used_to_transmit_data_)
+ return;
+ subresource_speculation_ = true;
+}
+
+void ClientSocket::SetOmniboxSpeculation() {
+ if (was_used_to_transmit_data_)
+ return;
+ omnibox_speculation_ = true;
+}
+
+void ClientSocket::UpdateConnectivityState(bool is_reused) {
+ // Record if this connection has every actually connected successfully.
+ // Note that IsConnected() won't be defined at destruction time, so we need
+ // to record this data now, while the derived class is present.
+ was_ever_connected_ |= IsConnected();
+ // A socket is_reused only after it has transmitted some data.
+ was_used_to_transmit_data_ |= is_reused;
+}
+
+} // namespace net
+