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.
5 #include "chrome/browser/net/request_source_bandwidth_histograms.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "content/public/browser/resource_request_info.h"
9 #include "content/public/common/process_type.h"
10 #include "net/url_request/url_request.h"
21 bool ShouldHistogramRequest(const net::URLRequest
* request
, bool started
) {
23 !request
->was_cached() &&
24 request
->url().SchemeIsHTTPOrHTTPS();
27 Bucket
GetBucketForRequest(const net::URLRequest
* request
) {
28 const content::ResourceRequestInfo
* info
=
29 content::ResourceRequestInfo::ForRequest(request
);
31 return BUCKET_BROWSER
;
32 else if (info
->GetProcessType() == content::PROCESS_TYPE_RENDERER
)
33 return BUCKET_RENDERER
;
35 return BUCKET_UNKNOWN
;
38 // Histogram response sizes in kilobytes, from 1 KB to 4 GB.
39 #define UMA_HISTOGRAM_RESPONSE_KB(bucket, sample) \
40 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResponseSizeByProcess." bucket, sample, \
41 1, 4 * 1024 * 1024, 100)
43 void LogRequest(Bucket bucket
, int64 bytes
) {
44 int64 kilobytes
= bytes
/ 1024;
47 UMA_HISTOGRAM_RESPONSE_KB("Unknown", kilobytes
);
50 UMA_HISTOGRAM_RESPONSE_KB("Renderer", kilobytes
);
53 UMA_HISTOGRAM_RESPONSE_KB("Browser", kilobytes
);
62 void RecordRequestSourceBandwidth(const net::URLRequest
* request
,
64 if (ShouldHistogramRequest(request
, started
))
65 LogRequest(GetBucketForRequest(request
), request
->GetTotalReceivedBytes());