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

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: Use enum for test cases 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) 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.
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 ~HttpPipeliningCompatibilityClient();
49
50 // Launches the asynchronous URLRequests to fetch the URLs specified by
51 // |requests| combined with |base_url|. |base_url| should match the pattern
52 // "http://host/". |callback| is invoked once all the requests have completed.
53 // URLRequests are initiated in |url_request_context|. Results are recorded to
54 // UMA as they are received.
55 void Start(const std::string& base_url,
56 std::vector<RequestInfo>& requests,
57 const net::CompletionCallback& callback,
58 net::URLRequestContext* url_request_context);
59
60 private:
61 // There is one Request per RequestInfo passed in to Start() above.
62 class Request : public net::URLRequest::Delegate {
63 public:
64 Request(int request_id,
65 const std::string& base_url,
66 const RequestInfo& info,
67 HttpPipeliningCompatibilityClient* client,
68 net::URLRequestContext* url_request_context);
69 virtual ~Request();
70
71 // net::URLRequest::Delegate interface
72 virtual void OnReceivedRedirect(net::URLRequest* request,
73 const GURL& new_url,
74 bool* defer_redirect) OVERRIDE;
75 virtual void OnSSLCertificateError(net::URLRequest* request,
76 const net::SSLInfo& ssl_info,
77 bool fatal) OVERRIDE;
78 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
79 virtual void OnReadCompleted(net::URLRequest* request,
80 int bytes_read) OVERRIDE;
81
82 private:
83 // Called when a response can be read. Reads bytes into |response_| until it
84 // consumes the entire response or it encounters an error.
85 void DoRead();
86
87 // Called when all bytes have been received. Compares the |response_| to
88 // |info_|'s expected response.
89 void DoReadFinished();
90
91 // Called when this request has determined its result. Returns the result to
92 // the |client_|.
93 void Finished(Status result);
94
95 const int request_id_;
96 net::URLRequest request_;
97 const RequestInfo info_;
98 HttpPipeliningCompatibilityClient* client_;
99 bool finished_;
100 scoped_refptr<net::IOBuffer> read_buffer_;
101 std::string response_;
102 };
103
104 // Called when a Request determines its result. Reports to UMA.
105 void OnRequestFinished(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