Chromium Code Reviews| Index: chrome/browser/net/http_pipelining_compatibility_client.h |
| diff --git a/chrome/browser/net/http_pipelining_compatibility_client.h b/chrome/browser/net/http_pipelining_compatibility_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31665cb55571397077cf9936d540c091c7edff3b |
| --- /dev/null |
| +++ b/chrome/browser/net/http_pipelining_compatibility_client.h |
| @@ -0,0 +1,123 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
mmenke
2012/02/01 19:08:07
nit: All these files should be updated to 2012.
James Simonsen
2012/02/07 00:01:37
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ |
| +#define CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/memory/scoped_vector.h" |
| +#include "net/base/completion_callback.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/url_request/url_request.h" |
| + |
| +namespace chrome_browser_net { |
| + |
| +// Class for performing a background test of users' internet connections. |
| +// Fetches a collection of resources on a test server and verifies all were |
| +// received correctly. This will be used to determine whether or not proxies are |
| +// interfering with a user's ability to use HTTP pipelining. Results are |
| +// recorded with UMA. |
| +// |
| +// TODO(simonjam): Connect this to something. We should start with a field trial |
| +// that affects a subset of canary channel users. But first, we need a test |
| +// server. |
| +class HttpPipeliningCompatibilityClient { |
| + public: |
| + struct RequestInfo { |
| + std::string filename; // The path relative to the test server's base_url. |
| + std::string expected_response; // The expected body of the response. |
| + }; |
| + |
| + enum Status { |
| + SUCCESS, |
| + REDIRECTED, |
| + CERT_ERROR, |
| + BAD_RESPONSE_CODE, |
| + NETWORK_ERROR, |
| + TOO_LARGE, |
| + TOO_SMALL, |
| + CONTENT_MISMATCH, |
| + STATUS_MAX, |
| + }; |
| + |
| + HttpPipeliningCompatibilityClient(); |
| + |
| + // Launches the asynchronous URLRequests to fetch the URLs specified by |
| + // |requests| combined with |base_url|. |base_url| should match the pattern |
| + // "http://host/". |callback| is invoked once all the requests have completed. |
| + // URLRequests are initiated in |url_request_context|. Results are recorded to |
| + // UMA as they are received. |
| + void Start(const std::string& base_url, |
| + std::vector<RequestInfo>& requests, |
| + const net::CompletionCallback& callback, |
| + net::URLRequestContext* url_request_context); |
| + |
| + private: |
| + // There is one Request per RequestInfo passed in to Start() above. |
| + class Request : public net::URLRequest::Delegate { |
| + public: |
| + Request(int request_id, |
| + const std::string& base_url, |
| + const RequestInfo& info, |
| + HttpPipeliningCompatibilityClient* client, |
| + net::URLRequestContext* url_request_context); |
| + |
| + // net::URLRequest::Delegate interface |
| + virtual void OnReceivedRedirect(net::URLRequest* request, |
| + const GURL& new_url, |
| + bool* defer_redirect) OVERRIDE; |
| + virtual void OnSSLCertificateError(net::URLRequest* request, |
| + const net::SSLInfo& ssl_info, |
| + bool fatal) OVERRIDE; |
| + virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| + virtual void OnReadCompleted(net::URLRequest* request, |
| + int bytes_read) OVERRIDE; |
| + |
| + private: |
| + // Called when a response can be read. Reads bytes into |response_| until it |
| + // consumes the entire response or it encounters an error. |
| + void DoRead(); |
| + |
| + // Called when all bytes have been received. Compares the |response_| to |
| + // |info_|'s expected response. |
| + void DoReadFinished(); |
| + |
| + // Called when this request has determined its result. Returns the result to |
| + // the |client_|. |
| + void Finished(Status result); |
|
mmenke
2012/02/01 19:08:07
nit: Suggest you call this RequestFinished or OnR
James Simonsen
2012/02/07 00:01:37
Done.
|
| + |
| + int request_id_; |
|
mmenke
2012/02/01 19:08:07
nit: this can be const.
James Simonsen
2012/02/07 00:01:37
Done.
|
| + net::URLRequest request_; |
| + const RequestInfo info_; |
| + HttpPipeliningCompatibilityClient* client_; |
| + bool finished_; |
| + scoped_refptr<net::IOBuffer> read_buffer_; |
| + std::string response_; |
| + }; |
| + |
| + friend class Request; |
|
mmenke
2012/02/01 19:08:07
nit: Don't think this is needed. An inner classe
James Simonsen
2012/02/07 00:01:37
Done.
|
| + |
| + // Called when a Request determines its result. Reports to UMA. |
| + void Finished(int request_id, Status status); |
| + |
| + // Called when a Request encounters a network error. Reports to UMA. |
| + void ReportNetworkError(int request_id, int error_code); |
| + |
| + // Called when a Request determines its HTTP response code. Reports to UMA. |
| + void ReportResponseCode(int request_id, int response_code); |
| + |
| + // Returns the full UMA metric name based on |request_id| and |description|. |
| + std::string GetMetricName(int request_id, const char* description); |
| + |
| + ScopedVector<Request> requests_; |
| + net::CompletionCallback finished_callback_; |
| + size_t num_finished_; |
| +}; |
| + |
| +} // namespace chrome_browser_net |
| + |
| +#endif // CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_ |