Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ | |
| 6 #define CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/scoped_vector.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 #include "net/base/io_buffer.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 | |
| 17 namespace chrome_browser_net { | |
| 18 | |
| 19 // Class for performing a background test of users' internet connections. | |
|
mmenke
2012/02/08 15:50:51
nit: Internet. Doesn't really matter, but more w
James Simonsen
2012/02/10 01:28:48
Done.
| |
| 20 // Fetches a collection of resources on a test server and verifies all were | |
| 21 // received correctly. This will be used to determine whether or not proxies are | |
| 22 // interfering with a user's ability to use HTTP pipelining. Results are | |
| 23 // recorded with UMA. | |
| 24 // | |
| 25 // TODO(simonjam): Connect this to something. We should start with a field trial | |
| 26 // that affects a subset of canary channel users. But first, we need a test | |
| 27 // server. | |
| 28 class HttpPipeliningCompatibilityClient { | |
| 29 public: | |
| 30 struct RequestInfo { | |
| 31 std::string filename; // The path relative to the test server's base_url. | |
| 32 std::string expected_response; // The expected body of the response. | |
| 33 }; | |
| 34 | |
| 35 enum Status { | |
| 36 SUCCESS, | |
| 37 REDIRECTED, // Response was redirected. We won't follow. | |
| 38 CERT_ERROR, // Any certificate problem. | |
| 39 BAD_RESPONSE_CODE, // Any non-200 response. | |
| 40 NETWORK_ERROR, // Any socket error reported by the network layer. | |
| 41 TOO_LARGE, // The response matched, but had extra data on the end. | |
| 42 TOO_SMALL, // The response was shorter than expected, but what we | |
| 43 // got matched. | |
| 44 CONTENT_MISMATCH, // The response didn't match the expected value. | |
| 45 BAD_HTTP_VERSION, // Any version older than HTTP/1.1. | |
| 46 STATUS_MAX, | |
| 47 }; | |
| 48 | |
| 49 HttpPipeliningCompatibilityClient(); | |
| 50 ~HttpPipeliningCompatibilityClient(); | |
| 51 | |
| 52 // Launches the asynchronous URLRequests to fetch the URLs specified by | |
| 53 // |requests| combined with |base_url|. |base_url| should match the pattern | |
| 54 // "http://host/". |callback| is invoked once all the requests have completed. | |
| 55 // URLRequests are initiated in |url_request_context|. Results are recorded to | |
| 56 // UMA as they are received. | |
| 57 void Start(const std::string& base_url, | |
| 58 std::vector<RequestInfo>& requests, | |
| 59 const net::CompletionCallback& callback, | |
| 60 net::URLRequestContext* url_request_context); | |
| 61 | |
| 62 private: | |
| 63 // There is one Request per RequestInfo passed in to Start() above. | |
| 64 class Request : public net::URLRequest::Delegate { | |
| 65 public: | |
| 66 Request(int request_id, | |
| 67 const std::string& base_url, | |
| 68 const RequestInfo& info, | |
| 69 HttpPipeliningCompatibilityClient* client, | |
| 70 net::URLRequestContext* url_request_context); | |
| 71 virtual ~Request(); | |
| 72 | |
| 73 // net::URLRequest::Delegate interface | |
| 74 virtual void OnReceivedRedirect(net::URLRequest* request, | |
| 75 const GURL& new_url, | |
| 76 bool* defer_redirect) OVERRIDE; | |
| 77 virtual void OnSSLCertificateError(net::URLRequest* request, | |
| 78 const net::SSLInfo& ssl_info, | |
| 79 bool fatal) OVERRIDE; | |
| 80 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | |
| 81 virtual void OnReadCompleted(net::URLRequest* request, | |
| 82 int bytes_read) OVERRIDE; | |
| 83 | |
| 84 private: | |
| 85 // Called when a response can be read. Reads bytes into |response_| until it | |
| 86 // consumes the entire response or it encounters an error. | |
| 87 void DoRead(); | |
| 88 | |
| 89 // Called when all bytes have been received. Compares the |response_| to | |
| 90 // |info_|'s expected response. | |
| 91 void DoReadFinished(); | |
| 92 | |
| 93 // Called when this request has determined its result. Returns the result to | |
| 94 // the |client_|. | |
| 95 void Finished(Status result); | |
| 96 | |
| 97 const int request_id_; | |
| 98 net::URLRequest request_; | |
| 99 const RequestInfo info_; | |
| 100 HttpPipeliningCompatibilityClient* client_; | |
| 101 bool finished_; | |
| 102 scoped_refptr<net::IOBuffer> read_buffer_; | |
| 103 std::string response_; | |
| 104 }; | |
| 105 | |
| 106 // Called when a Request determines its result. Reports to UMA. | |
| 107 void OnRequestFinished(int request_id, Status status); | |
| 108 | |
| 109 // Called when a Request encounters a network error. Reports to UMA. | |
| 110 void ReportNetworkError(int request_id, int error_code); | |
| 111 | |
| 112 // Called when a Request determines its HTTP response code. Reports to UMA. | |
| 113 void ReportResponseCode(int request_id, int response_code); | |
| 114 | |
| 115 // Returns the full UMA metric name based on |request_id| and |description|. | |
| 116 std::string GetMetricName(int request_id, const char* description); | |
| 117 | |
| 118 ScopedVector<Request> requests_; | |
| 119 net::CompletionCallback finished_callback_; | |
| 120 size_t num_finished_; | |
| 121 }; | |
| 122 | |
| 123 } // namespace chrome_browser_net | |
| 124 | |
| 125 #endif // CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ | |
| OLD | NEW |