blob: bdcdc82c4dce8963cf1301fdac439d27b2ff7464 [file] [log] [blame]
ttuttle05ae3f342015-07-13 17:38:351// 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
avi6846aef2015-12-26 01:09:387#include <stdint.h>
8
ttuttle05ae3f342015-07-13 17:38:359#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
14namespace {
15
16enum Bucket {
17 BUCKET_UNKNOWN,
18 BUCKET_RENDERER,
19 BUCKET_BROWSER,
20 BUCKET_MAX,
21};
22
23bool ShouldHistogramRequest(const net::URLRequest* request, bool started) {
24 return started &&
25 !request->was_cached() &&
26 request->url().SchemeIsHTTPOrHTTPS();
27}
28
29Bucket 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
avi6846aef2015-12-26 01:09:3845void LogRequest(Bucket bucket, int64_t bytes) {