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

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

Issue 9302024: Add client for background testing of HTTP pipelining. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 10 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
OLDNEW
(Empty)
1 // 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.
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.
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,
38 CERT_ERROR,
39 BAD_RESPONSE_CODE,
40 NETWORK_ERROR,
41 TOO_LARGE,
42 TOO_SMALL,
43 CONTENT_MISMATCH,
44 STATUS_MAX,
45 };
46
47 HttpPipeliningCompatibilityClient();
48
49 // Launches the asynchronous URLRequests to fetch the URLs specified by
50 // |requests| combined with |base_url|. |base_url| should match the pattern
51 // "http://host/". |callback| is invoked once all the requests have completed.
52 // URLRequests are initiated in |url_request_context|. Results are recorded to
53 // UMA as they are received.
54 void Start(const std::string& base_url,
55 std::vector<RequestInfo>& requests,
56 const net::CompletionCallback& callback,
57 net::URLRequestContext* url_request_context);
58
59 private:
60 // There is one Request per RequestInfo passed in to Start() above.
61 class Request : public net::URLRequest::Delegate {
62 public:
63 Request(int request_id,
64 const std::string& base_url,
65 const RequestInfo& info,
66 HttpPipeliningCompatibilityClient* client,
67 net::URLRequestContext* url_request_context);
68
69 // net::URLRequest::Delegate interface
70 virtual void OnReceivedRedirect(net::URLRequest* request,
71 const GURL& new_url,
72 bool* defer_redirect) OVERRIDE;
73 virtual void OnSSLCertificateError(net::URLRequest* request,
74 const net::SSLInfo& ssl_info,
75 bool fatal) OVERRIDE;
76 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
77 virtual void OnReadCompleted(net::URLRequest* request,
78 int bytes_read) OVERRIDE;
79
80 private:
81 // Called when a response can be read. Reads bytes into |response_| until it
82 // consumes the entire response or it encounters an error.
83 void DoRead();
84
85 // Called when all bytes have been received. Compares the |response_| to
86 // |info_|'s expected response.
87 void DoReadFinished();
88
89 // Called when this request has determined its result. Returns the result to
90 // the |client_|.
91 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.
92
93 int request_id_;
mmenke 2012/02/01 19:08:07 nit: this can be const.
James Simonsen 2012/02/07 00:01:37 Done.
94 net::URLRequest request_;
95 const RequestInfo info_;
96 HttpPipeliningCompatibilityClient* client_;
97 bool finished_;
98 scoped_refptr<net::IOBuffer> read_buffer_;
99 std::string response_;
100 };
101
102 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.
103
104 // Called when a Request determines its result. Reports to UMA.
105 void Finished(int request_id, Status status);
106
107 // Called when a Request encounters a network error. Reports to UMA.
108 void ReportNetworkError(int request_id, int error_code);
109
110 // Called when a Request determines its HTTP response code. Reports to UMA.
111 void ReportResponseCode(int request_id, int response_code);
112
113 // Returns the full UMA metric name based on |request_id| and |description|.
114 std::string GetMetricName(int request_id, const char* description);
115
116 ScopedVector<Request> requests_;
117 net::CompletionCallback finished_callback_;
118 size_t num_finished_;
119 };
120
121 } // namespace chrome_browser_net
122
123 #endif // CHROME_BROWSER_NET_HTTP_PIPELINING_COMPATIBILITY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698