OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/prerender/prerender_util.h" | 5 #include "chrome/browser/prerender/prerender_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "content/public/browser/resource_request_info.h" | 10 #include "content/public/browser/resource_request_info.h" |
11 #include "googleurl/src/url_canon.h" | 11 #include "googleurl/src/url_canon.h" |
12 #include "googleurl/src/url_parse.h" | 12 #include "googleurl/src/url_parse.h" |
13 #include "googleurl/src/url_util.h" | 13 #include "googleurl/src/url_util.h" |
14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
16 | 16 |
17 namespace prerender { | 17 namespace prerender { |
18 | 18 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 void URLRequestResponseStarted(net::URLRequest* request) { | 96 void URLRequestResponseStarted(net::URLRequest* request) { |
97 static const char* kModPagespeedHeader = "X-Mod-Pagespeed"; | 97 static const char* kModPagespeedHeader = "X-Mod-Pagespeed"; |
98 static const char* kModPagespeedHistogram = "Prerender.ModPagespeedHeader"; | 98 static const char* kModPagespeedHistogram = "Prerender.ModPagespeedHeader"; |
99 const content::ResourceRequestInfo* info = | 99 const content::ResourceRequestInfo* info = |
100 content::ResourceRequestInfo::ForRequest(request); | 100 content::ResourceRequestInfo::ForRequest(request); |
101 // Gather histogram information about the X-Mod-Pagespeed header. | 101 // Gather histogram information about the X-Mod-Pagespeed header. |
102 if (info->GetResourceType() == ResourceType::MAIN_FRAME && | 102 if (info->GetResourceType() == ResourceType::MAIN_FRAME && |
103 IsWebURL(request->url())) { | 103 IsWebURL(request->url())) { |
104 UMA_HISTOGRAM_ENUMERATION(kModPagespeedHistogram, 0, 101); | 104 UMA_HISTOGRAM_SPARSE_SLOWLY(kModPagespeedHistogram, 0); |
105 if (request->response_headers() && | 105 if (request->response_headers() && |
106 request->response_headers()->HasHeader(kModPagespeedHeader)) { | 106 request->response_headers()->HasHeader(kModPagespeedHeader)) { |
107 UMA_HISTOGRAM_ENUMERATION(kModPagespeedHistogram, 1, 101); | 107 UMA_HISTOGRAM_SPARSE_SLOWLY(kModPagespeedHistogram, 1); |
108 | 108 |
109 // Attempt to parse the version number, and encode it in buckets | 109 // Attempt to parse the version number, and encode it in buckets |
110 // 2 through 99. 0 and 1 are used to store all pageviews and | 110 // 2 through 99. 0 and 1 are used to store all pageviews and |
111 // # pageviews with the MPS header (see above). | 111 // # pageviews with the MPS header (see above). |
112 void* iter = NULL; | 112 void* iter = NULL; |
113 std::string mps_version; | 113 std::string mps_version; |
114 if (request->response_headers()->EnumerateHeader( | 114 if (request->response_headers()->EnumerateHeader( |
115 &iter, kModPagespeedHeader, &mps_version) && | 115 &iter, kModPagespeedHeader, &mps_version) && |
116 !mps_version.empty()) { | 116 !mps_version.empty()) { |
117 // Mod Pagespeed versions are of the form a.b.c.d-e | 117 // Mod Pagespeed versions are of the form a.b.c.d-e |
118 int a, b, c, d, e; | 118 int a, b, c, d, e; |
119 int num_parsed = sscanf(mps_version.c_str(), "%d.%d.%d.%d-%d", | 119 int num_parsed = sscanf(mps_version.c_str(), "%d.%d.%d.%d-%d", |
120 &a, &b, &c, &d, &e); | 120 &a, &b, &c, &d, &e); |
121 if (num_parsed == 5) { | 121 if (num_parsed == 5) { |
122 int output = 2; | 122 int output = 2; |
123 if (c > 10) | 123 if (c > 10) |
124 output += 2 * (c - 10); | 124 output += 2 * (c - 10); |
125 if (d > 1) | 125 if (d > 1) |
126 output++; | 126 output++; |
127 if (output < 2 || output >= 99) | 127 if (output < 2 || output >= 99) |
128 output = 99; | 128 output = 99; |
129 UMA_HISTOGRAM_ENUMERATION(kModPagespeedHistogram, output, 101); | 129 UMA_HISTOGRAM_SPARSE_SLOWLY(kModPagespeedHistogram, output); |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 } // namespace prerender | 136 } // namespace prerender |
OLD | NEW |