1 // Copyright (c) 2011 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 // Collect metrics of SocketStream usage. 6 // TODO(ukai): collect WebSocket specific metrics (e.g. handshake time, etc). 7 8 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 9 #define NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 10 11 #include "base/basictypes.h" 12 #include "base/time/time.h" 13 #include "net/base/net_export.h" 14 15 class GURL; 16 17 namespace net { 18 19 class NET_EXPORT_PRIVATE SocketStreamMetrics { 20 public: 21 enum ProtocolType { 22 PROTOCOL_UNKNOWN, 23 PROTOCOL_WEBSOCKET, 24 PROTOCOL_WEBSOCKET_SECURE, 25 NUM_PROTOCOL_TYPES, 26 }; 27 28 enum ConnectionType { 29 CONNECTION_NONE, 30 ALL_CONNECTIONS, 31 TUNNEL_CONNECTION, 32 SOCKS_CONNECTION, 33 SSL_CONNECTION, 34 SECURE_PROXY_CONNECTION, 35 NUM_CONNECTION_TYPES, 36 }; 37 38 enum WireProtocolType { 39 WIRE_PROTOCOL_WEBSOCKET, 40 WIRE_PROTOCOL_SPDY, 41 NUM_WIRE_PROTOCOL_TYPES, 42 }; 43 44 explicit SocketStreamMetrics(const GURL& url); 45 ~SocketStreamMetrics(); 46 47 void OnWaitConnection(); 48 void OnStartConnection(); 49 void OnConnected(); 50 void OnRead(int len); 51 void OnWrite(int len); 52 void OnClose(); 53 void OnCountConnectionType(ConnectionType type); 54 void OnCountWireProtocolType(WireProtocolType type); 55 56 private: 57 base::TimeTicks wait_start_time_; 58 base::TimeTicks connect_start_time_; 59 base::TimeTicks connect_establish_time_; 60 int received_bytes_; 61 int received_counts_; 62 int sent_bytes_; 63 int sent_counts_; 64 65 DISALLOW_COPY_AND_ASSIGN(SocketStreamMetrics); 66 }; 67 68 } // namespace net 69 70 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 71