ttuttle | 05ae3f34 | 2015-07-13 17:38:35 | [diff] [blame] | 1 | // Copyright 2015 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 | #include "chrome/browser/net/request_source_bandwidth_histograms.h" |
| 6 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
ttuttle | 05ae3f34 | 2015-07-13 17:38:35 | [diff] [blame] | 9 | #include "base/metrics/histogram_macros.h" |
| 10 | #include "content/public/browser/resource_request_info.h" |
| 11 | #include "content/public/common/process_type.h" |
| 12 | #include "net/url_request/url_request.h" |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | enum Bucket { |
| 17 | BUCKET_UNKNOWN, |
| 18 | BUCKET_RENDERER, |
| 19 | BUCKET_BROWSER, |
| 20 | BUCKET_MAX, |
| 21 | }; |
| 22 | |
| 23 | bool ShouldHistogramRequest(const net::URLRequest* request, bool started) { |
| 24 | return started && |
| 25 | !request->was_cached() && |
| 26 | request->url().SchemeIsHTTPOrHTTPS(); |
| 27 | } |
| 28 | |
| 29 | Bucket GetBucketForRequest(const net::URLRequest* request) { |
| 30 | const content::ResourceRequestInfo* info = |
| 31 | content::ResourceRequestInfo::ForRequest(request); |
| 32 | if (!info) |
| 33 | return BUCKET_BROWSER; |
| 34 | else if (info->GetProcessType() == content::PROCESS_TYPE_RENDERER) |
| 35 | return BUCKET_RENDERER; |
| 36 | else |
| 37 | return BUCKET_UNKNOWN; |
| 38 | } |
| 39 | |
| 40 | // Histogram response sizes in kilobytes, from 1 KB to 4 GB. |
| 41 | #define UMA_HISTOGRAM_RESPONSE_KB(bucket, sample) \ |
| 42 | UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResponseSizeByProcess." bucket, sample, \ |
| 43 | 1, 4 * 1024 * 1024, 100) |
| 44 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 45 | void LogRequest(Bucket bucket, int64_t bytes) { |
|
|