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

Side by Side Diff: chrome/browser/net/network_stats.h

Issue 10206035: NetConnectivity - Collect stats for TCP/UDP network (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/net/network_stats.cc » ('j') | chrome/browser/net/network_stats.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_NETWORK_STATS_H_ 5 #ifndef CHROME_BROWSER_NET_NETWORK_STATS_H_
6 #define CHROME_BROWSER_NET_NETWORK_STATS_H_ 6 #define CHROME_BROWSER_NET_NETWORK_STATS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/io_thread.h" 16 #include "chrome/browser/io_thread.h"
17 #include "net/base/address_list.h" 17 #include "net/base/address_list.h"
18 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
19 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
20 #include "net/base/host_resolver.h" 20 #include "net/base/host_resolver.h"
21 #include "net/base/io_buffer.h" 21 #include "net/base/io_buffer.h"
22 #include "net/base/ip_endpoint.h" 22 #include "net/base/ip_endpoint.h"
23 #include "net/base/test_data_stream.h" 23 #include "net/base/test_data_stream.h"
24 #include "net/proxy/proxy_info.h"
24 #include "net/socket/socket.h" 25 #include "net/socket/socket.h"
25 namespace chrome_browser_net { 26 namespace chrome_browser_net {
26 27
27 // This class is used for live experiment of network connectivity (either TCP or 28 // This class is used for live experiment of network connectivity (either TCP or
28 // UDP) metrics. A small percentage of users participate in this experiment. All 29 // UDP) metrics. A small percentage of users participate in this experiment. All
29 // users (who are in the experiment) must have enabled "UMA upload". 30 // users (who are in the experiment) must have enabled "UMA upload".
30 // 31 //
31 // This class collects the following stats from users who have opted in. 32 // This class collects the following stats from users who have opted in.
32 // a) What percentage of users can get a message end-to-end to a UDP server? 33 // a) What percentage of users can get a message end-to-end to a UDP server?
33 // b) What percentage of users can get a message end-to-end to a TCP server? 34 // b) What percentage of users can get a message end-to-end to a TCP server?
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Starts the client, connecting to |server|. 95 // Starts the client, connecting to |server|.
95 // Client will send |bytes_to_send| bytes to |server|. 96 // Client will send |bytes_to_send| bytes to |server|.
96 // When client has received all echoed bytes from the server, or 97 // When client has received all echoed bytes from the server, or
97 // when an error occurs causing the client to stop, |Finish| will be 98 // when an error occurs causing the client to stop, |Finish| will be
98 // called with a net status code. 99 // called with a net status code.
99 // |Finish| will collect histogram stats. 100 // |Finish| will collect histogram stats.
100 // Returns true if successful in starting the client. 101 // Returns true if successful in starting the client.
101 bool Start(net::HostResolver* host_resolver, 102 bool Start(net::HostResolver* host_resolver,
102 const net::HostPortPair& server, 103 const net::HostPortPair& server,
103 HistogramPortSelector histogram_port, 104 HistogramPortSelector histogram_port,
105 bool has_proxy_server,
104 uint32 bytes_to_send, 106 uint32 bytes_to_send,
105 uint32 packets_to_send, 107 uint32 packets_to_send,
106 const net::CompletionCallback& callback); 108 const net::CompletionCallback& callback);
107 109
108 protected: 110 protected:
109 // Constructs an NetworkStats object that collects metrics for network 111 // Constructs an NetworkStats object that collects metrics for network
110 // connectivity (either TCP or UDP). 112 // connectivity (either TCP or UDP).
111 NetworkStats(); 113 NetworkStats();
114 // NetworkStats is deleted when Finish() is called.
112 virtual ~NetworkStats(); 115 virtual ~NetworkStats();
113 116
114 // Initializes |finished_callback_| and the number of bytes to send to the 117 // Initializes |finished_callback_| and the number of bytes to send to the
115 // server. |finished_callback| is called when we are done with the test. 118 // server. |finished_callback| is called when we are done with the test.
116 // |finished_callback| is mainly useful for unittests. 119 // |finished_callback| is mainly useful for unittests.
117 void Initialize(uint32 bytes_to_send, 120 void Initialize(uint32 bytes_to_send,
118 HistogramPortSelector histogram_port, 121 HistogramPortSelector histogram_port,
122 bool has_proxy_server,
119 uint32 packets_to_send, 123 uint32 packets_to_send,
120 const net::CompletionCallback& finished_callback); 124 const net::CompletionCallback& finished_callback);
121 125
122 // Called after host is resolved. UDPStatsClient and TCPStatsClient implement 126 // Called after host is resolved. UDPStatsClient and TCPStatsClient implement
123 // this method. They create the socket and connect to the server. 127 // this method. They create the socket and connect to the server.
124 virtual bool DoConnect(int result) = 0; 128 virtual bool DoConnect(int result) = 0;
125 129
126 // This method is called after socket connection is completed. It will start 130 // This method is called after socket connection is completed. It will start
127 // the process of sending packets to |server| by calling SendPacket(). Returns 131 // the process of sending packets to |server| by calling SendPacket(). Returns
128 // false if connection is not established (result is less than 0). 132 // false if connection is not established (result is less than 0).
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 std::string encoded_message_; 268 std::string encoded_message_;
265 269
266 // |stream_| is used to generate data to be sent to the server and it is also 270 // |stream_| is used to generate data to be sent to the server and it is also
267 // used to verify the data received from the server. 271 // used to verify the data received from the server.
268 net::TestDataStream stream_; 272 net::TestDataStream stream_;
269 273
270 // |histogram_port_| specifies the port for which we are testing the network 274 // |histogram_port_| specifies the port for which we are testing the network
271 // connectivity. 275 // connectivity.
272 HistogramPortSelector histogram_port_; 276 HistogramPortSelector histogram_port_;
273 277
278 // |has_proxy_server_| specifies if there is a proxy server or not.
279 bool has_proxy_server_;
280
274 // HostResolver fills out the |addresses_| after host resolution is completed. 281 // HostResolver fills out the |addresses_| after host resolution is completed.
275 net::AddressList addresses_; 282 net::AddressList addresses_;
276 283
277 // Callback to call when echo protocol is successefully finished or whenever 284 // Callback to call when echo protocol is successefully finished or whenever
278 // there is an error (this allows unittests to wait until echo protocol's 285 // there is an error (this allows unittests to wait until echo protocol's
279 // round trip is finished). 286 // round trip is finished).
280 net::CompletionCallback finished_callback_; 287 net::CompletionCallback finished_callback_;
281 288
282 // The time when the session was started. 289 // The time when the session was started.
283 base::TimeTicks start_time_; 290 base::TimeTicks start_time_;
284 291
285 // Data to track number of packets to send to the server and the packets we 292 // Data to track number of packets to send to the server and the packets we
286 // have received from the server. 293 // have received from the server.
287 uint32 packets_to_send_; 294 uint32 packets_to_send_;
288 uint32 packets_sent_; 295 uint32 packets_sent_;
289 uint32 base_packet_number_; 296 uint32 base_packet_number_;
290 uint32 packets_received_mask_; 297 uint32 packets_received_mask_;
291 298
292 // We use this factory to create timeout tasks for socket's ReadData. 299 // We use this factory to create timeout tasks for socket's ReadData.
293 base::WeakPtrFactory<NetworkStats> weak_factory_; 300 base::WeakPtrFactory<NetworkStats> weak_factory_;
294 }; 301 };
295 302
296 class UDPStatsClient : public NetworkStats { 303 class UDPStatsClient : public NetworkStats {
297 public: 304 public:
298 // Constructs an UDPStatsClient object that collects metrics for UDP 305 // Constructs an UDPStatsClient object that collects metrics for UDP
299 // connectivity. 306 // connectivity.
300 UDPStatsClient(); 307 UDPStatsClient();
308 // UDPStatsClient is deleted when Finish() is called.
301 virtual ~UDPStatsClient(); 309 virtual ~UDPStatsClient();
302 310
303 protected: 311 protected:
304 // Allow tests to access our innards for testing purposes. 312 // Allow tests to access our innards for testing purposes.
305 friend class NetworkStatsTestUDP; 313 friend class NetworkStatsTestUDP;
306 314
307 // Called after host is resolved. Creates UDClientSocket and connects to the 315 // Called after host is resolved. Creates UDClientSocket and connects to the
308 // server. If successfully connected, then calls ConnectComplete() to start 316 // server. If successfully connected, then calls ConnectComplete() to start
309 // the echo protocol. Returns |false| if there is any error. 317 // the echo protocol. Returns |false| if there is any error.
310 virtual bool DoConnect(int result) OVERRIDE; 318 virtual bool DoConnect(int result) OVERRIDE;
311 319
312 // This method calls NetworkStats::ReadComplete() to verify the data and calls 320 // This method calls NetworkStats::ReadComplete() to verify the data and calls
313 // Finish() if there is an error or if read callback didn't return any data 321 // Finish() if there is an error or if read callback didn't return any data
314 // (|result| is less than or equal to 0). 322 // (|result| is less than or equal to 0).
315 virtual bool ReadComplete(int result) OVERRIDE; 323 virtual bool ReadComplete(int result) OVERRIDE;
316 324
317 // Collects stats for UDP connectivity. This is called when all the data from 325 // Collects stats for UDP connectivity. This is called when all the data from
318 // server is read or when there is a failure during connect/read/write. 326 // server is read or when there is a failure during connect/read/write. This
327 // object is deleted at the end of this method.
319 virtual void Finish(Status status, int result) OVERRIDE; 328 virtual void Finish(Status status, int result) OVERRIDE;
320 }; 329 };
321 330
322 class TCPStatsClient : public NetworkStats { 331 class TCPStatsClient : public NetworkStats {
323 public: 332 public:
324 // Constructs a TCPStatsClient object that collects metrics for TCP 333 // Constructs a TCPStatsClient object that collects metrics for TCP
325 // connectivity. 334 // connectivity.
326 TCPStatsClient(); 335 TCPStatsClient();
336 // TCPStatsClient is deleted when Finish() is called.
327 virtual ~TCPStatsClient(); 337 virtual ~TCPStatsClient();
328 338
329 protected: 339 protected:
330 // Allow tests to access our innards for testing purposes. 340 // Allow tests to access our innards for testing purposes.
331 friend class NetworkStatsTestTCP; 341 friend class NetworkStatsTestTCP;
332 342
333 // Called after host is resolved. Creates TCPClientSocket and connects to the 343 // Called after host is resolved. Creates TCPClientSocket and connects to the
334 // server. 344 // server.
335 virtual bool DoConnect(int result) OVERRIDE; 345 virtual bool DoConnect(int result) OVERRIDE;
336 346
337 // This method calls NetworkStats::ReadComplete() to verify the data and calls 347 // This method calls NetworkStats::ReadComplete() to verify the data and calls
338 // Finish() if there is an error (|result| is less than 0). 348 // Finish() if there is an error (|result| is less than 0).
339 virtual bool ReadComplete(int result) OVERRIDE; 349 virtual bool ReadComplete(int result) OVERRIDE;
340 350
341 // Collects stats for TCP connectivity. This is called when all the data from 351 // Collects stats for TCP connectivity. This is called when all the data from
342 // server is read or when there is a failure during connect/read/write. 352 // server is read or when there is a failure during connect/read/write. This
353 // object is deleted at the end of this method.
343 virtual void Finish(Status status, int result) OVERRIDE; 354 virtual void Finish(Status status, int result) OVERRIDE;
344 355
345 private: 356 private:
346 // Callback that is called when connect is completed and calls 357 // Callback that is called when connect is completed and calls
347 // ConnectComplete() to start the echo protocol. 358 // ConnectComplete() to start the echo protocol.
348 void OnConnectComplete(int result); 359 void OnConnectComplete(int result);
349 }; 360 };
350 361
362 class ProxyDetector {
363 public:
364 // Constructs a ProxyDetector object that resolves if access to
365 // network_stats_server goes through a proxy server or not.
366 ProxyDetector(const std::string& network_stats_server,
367 NetworkStats::HistogramPortSelector histogram_port,
eroman 2012/05/04 23:08:48 nit: align
ramant (doing other things) 2012/05/07 23:35:47 Done.
368 IOThread* io_thread);
369 virtual ~ProxyDetector();
eroman 2012/05/04 23:08:48 nit: why virtual?
ramant (doing other things) 2012/05/07 23:35:47 Done.
370
371 // This method uses system ProxyService to resolve the proxy for the given
372 // |network_stats_server| and |histogram_port|.
373 void ResolveProxy();
374
375 // Collects the network connectivity stats for UDP and TCP protocols.
376 void OnResolveProxyComplete(int result);
eroman 2012/05/04 23:08:48 This can be private, since it is only an implement
ramant (doing other things) 2012/05/07 23:35:47 Done.
377
378 private:
379 // |network_stats_server_| specifies the TCP/UDP echo server name.
380 std::string network_stats_server_;
381
382 // |histogram_port_| specifies the port for which we are testing the network
383 // connectivity.
384 NetworkStats::HistogramPortSelector histogram_port_;
385
386 // |proxy_info_| holds proxy information returned by ResolveProxy.
387 net::ProxyInfo proxy_info_;
388
389 // The IOThread for accessing global HostResolver to resolve
390 // network_stats_server_ host and for accessing global system ProxyService.
391 // |io_thread_| is accessed on IO thread and it is safe to access it on IO
392 // thread.
393 IOThread* io_thread_;
394 };
395
351 // This collects the network connectivity stats for UDP and TCP for small 396 // This collects the network connectivity stats for UDP and TCP for small
352 // percentage of users who are participating in the experiment. All users must 397 // percentage of users who are participating in the experiment. All users must
353 // have enabled "UMA upload". This method gets called only if UMA upload to the 398 // have enabled "UMA upload". This method gets called only if UMA upload to the
354 // server has succeeded. 399 // server has succeeded.
355 void CollectNetworkStats(const std::string& network_stats_server_url, 400 void CollectNetworkStats(const std::string& network_stats_server_url,
356 IOThread* io_thread); 401 IOThread* io_thread);
357 402
403 // This starts a test randomly selected among "TCP test with small packet size",
404 // "TCP test with large packet size", "UDP test with small packet size", "UDP
405 // test with large packet size" and "UDP multi packet loss" tests to collect the
406 // network connectivity stats.
407 void StartNetworkStatsTest(const std::string& network_stats_server,
408 NetworkStats::HistogramPortSelector histogram_port,
409 bool has_proxy_server,
410 IOThread* io_thread);
411
358 } // namespace chrome_browser_net 412 } // namespace chrome_browser_net
359 413
360 #endif // CHROME_BROWSER_NET_NETWORK_STATS_H_ 414 #endif // CHROME_BROWSER_NET_NETWORK_STATS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/network_stats.cc » ('j') | chrome/browser/net/network_stats.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698