Commit bf5fddf9 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Add a histogram showing which URL schemes are used by explicitly configured PAC scripts.

Bug: 839566

Change-Id: I51eb05bc52587d84592966870387ccae9d8db5d7
Reviewed-on: https://chromium-review.googlesource.com/1044751
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556992}
parent 348044d8
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -385,6 +386,34 @@ GURL SanitizeUrl(const GURL& url, ...@@ -385,6 +386,34 @@ GURL SanitizeUrl(const GURL& url,
return url.ReplaceComponents(replacements); return url.ReplaceComponents(replacements);
} }
// Do not change the enumerated value as it is relied on by histograms.
enum class PacUrlSchemeForHistogram {
kOther = 0,
kHttp = 1,
kHttps = 2,
kFtp = 3,
kFile = 4,
kData = 5,
kMaxValue = kData,
};
PacUrlSchemeForHistogram GetPacUrlScheme(const GURL& pac_url) {
if (pac_url.SchemeIs("http"))
return PacUrlSchemeForHistogram::kHttp;
if (pac_url.SchemeIs("https"))
return PacUrlSchemeForHistogram::kHttps;
if (pac_url.SchemeIs("data"))
return PacUrlSchemeForHistogram::kData;
if (pac_url.SchemeIs("ftp"))
return PacUrlSchemeForHistogram::kFtp;
if (pac_url.SchemeIs("file"))
return PacUrlSchemeForHistogram::kFile;
return PacUrlSchemeForHistogram::kOther;
}
} // namespace } // namespace
// ProxyResolutionService::InitProxyResolver ---------------------------------- // ProxyResolutionService::InitProxyResolver ----------------------------------
...@@ -1576,6 +1605,11 @@ void ProxyResolutionService::OnProxyConfigChanged( ...@@ -1576,6 +1605,11 @@ void ProxyResolutionService::OnProxyConfigChanged(
&fetched_config_, &effective_config)); &fetched_config_, &effective_config));
} }
if (config.value().has_pac_url()) {
UMA_HISTOGRAM_ENUMERATION("Net.ProxyResolutionService.PacUrlScheme",
GetPacUrlScheme(config.value().pac_url()));
}
// Set the new configuration as the most recently fetched one. // Set the new configuration as the most recently fetched one.
fetched_config_ = effective_config; fetched_config_ = effective_config;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/histogram_tester.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/proxy_delegate.h" #include "net/base/proxy_delegate.h"
#include "net/base/proxy_server.h" #include "net/base/proxy_server.h"
...@@ -171,6 +172,12 @@ class MockProxyConfigService: public ProxyConfigService { ...@@ -171,6 +172,12 @@ class MockProxyConfigService: public ProxyConfigService {
observer.OnProxyConfigChanged(config_, availability_); observer.OnProxyConfigChanged(config_, availability_);
} }
void SetPacUrlConfig(base::StringPiece pac_url) {
SetConfig(ProxyConfigWithAnnotation(
ProxyConfig::CreateFromCustomPacURL(GURL(pac_url)),
TRAFFIC_ANNOTATION_FOR_TESTS));
}
private: private:
ConfigAvailability availability_; ConfigAvailability availability_;
ProxyConfigWithAnnotation config_; ProxyConfigWithAnnotation config_;
...@@ -333,6 +340,42 @@ JobMap GetCancelledJobsForURLs(const MockAsyncProxyResolver& resolver, ...@@ -333,6 +340,42 @@ JobMap GetCancelledJobsForURLs(const MockAsyncProxyResolver& resolver,
return GetJobsForURLs(map, urls); return GetJobsForURLs(map, urls);
} }
// Helper class to verify the bucket counts for PacUrlScheme histogram.
class PacUrlSchemeHistogramTester {
public:
void VerifyHistogram() const {
const char kPacUrlSchemeHistogram[] =
"Net.ProxyResolutionService.PacUrlScheme";
int total = GetTotal();
histograms_.ExpectTotalCount(kPacUrlSchemeHistogram, total);
if (total > 0) {
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 0, num_other);
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 1, num_http);
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 2, num_https);
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 3, num_ftp);
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 4, num_file);
histograms_.ExpectBucketCount(kPacUrlSchemeHistogram, 5, num_data);
}
}
int num_http = 0;
int num_https = 0;
int num_ftp = 0;
int num_data = 0;
int num_file = 0;
int num_other = 0;
private:
int GetTotal() const {
return num_http + num_https + num_ftp + num_data + num_file + num_other;
}
base::HistogramTester histograms_;
};
} // namespace } // namespace
TEST_F(ProxyResolutionServiceTest, Direct) { TEST_F(ProxyResolutionServiceTest, Direct) {
...@@ -3576,4 +3619,58 @@ TEST_F(ProxyResolutionServiceTest, OnShutdownFollowedByRequest) { ...@@ -3576,4 +3619,58 @@ TEST_F(ProxyResolutionServiceTest, OnShutdownFollowedByRequest) {
EXPECT_TRUE(info.is_direct()); EXPECT_TRUE(info.is_direct());
} }
// Tests that the URL scheme for PAC files gets output to the histogram.
TEST_F(ProxyResolutionServiceTest, PacUrlSchemeHistogram) {
PacUrlSchemeHistogramTester pac_histogram;
MockProxyConfigService* config_service =
new MockProxyConfigService(ProxyConfig::CreateDirect());
ProxyResolutionService service(
base::WrapUnique(config_service),
std::make_unique<MockAsyncProxyResolverFactory>(false), nullptr);
pac_histogram.VerifyHistogram();
// Set an http:// PAC.
config_service->SetPacUrlConfig("http://example.test/");
pac_histogram.num_http++;
pac_histogram.VerifyHistogram();
// Set an https:// PAC.
config_service->SetPacUrlConfig("hTTps://example.test/wpad.dat");
pac_histogram.num_https++;
pac_histogram.VerifyHistogram();
// Set an ftp:// PAC.
config_service->SetPacUrlConfig("ftp://example.test/pac.js");
pac_histogram.num_ftp++;
pac_histogram.VerifyHistogram();
// Set an file:// PAC.
config_service->SetPacUrlConfig("file://example.test/boo");
pac_histogram.num_file++;
pac_histogram.VerifyHistogram();
// Set an mailto: PAC.
config_service->SetPacUrlConfig("mailto:foo@example.test");
pac_histogram.num_other++;
pac_histogram.VerifyHistogram();
// Set an data: PAC.
config_service->SetPacUrlConfig("data:,Hello%2C%20World!");
pac_histogram.num_data++;
pac_histogram.VerifyHistogram();
// Set an filesystem: PAC.
config_service->SetPacUrlConfig("filesystem:http://example.test/pac.js");
pac_histogram.num_other++;
pac_histogram.VerifyHistogram();
// Set another https:// as PAC.
config_service->SetPacUrlConfig("https://example2.test/wpad.dat");
pac_histogram.num_https++;
pac_histogram.VerifyHistogram();
}
} // namespace net } // namespace net
...@@ -34324,6 +34324,15 @@ Called by update_net_trust_anchors.py.--> ...@@ -34324,6 +34324,15 @@ Called by update_net_trust_anchors.py.-->
<int value="7" label="FAIL_DIFFERENT_PROXY_LIST"/> <int value="7" label="FAIL_DIFFERENT_PROXY_LIST"/>
</enum> </enum>
<enum name="PacUrlScheme">
<int value="0" label="Other"/>
<int value="1" label="Http"/>
<int value="2" label="Https"/>
<int value="3" label="Ftp"/>
<int value="4" label="File"/>
<int value="5" label="Data"/>
</enum>
<enum name="PageEndReason"> <enum name="PageEndReason">
<int value="0" label="END_NONE"> <int value="0" label="END_NONE">
Page lifetime has not yet ended (page is still active) Page lifetime has not yet ended (page is still active)
...@@ -48413,6 +48413,16 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -48413,6 +48413,16 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="Net.ProxyResolutionService.PacUrlScheme" enum="PacUrlScheme">
<owner>eroman@chromium.org</owner>
<summary>
The breakdown of URL schemes seen for explicitly configured ProxyAutoConfig
(PAC). This metric is emitted once each time the proxy settings change
(including initial value). Note that this does not count implicitly inferred
PAC URLs (from WPAD).
</summary>
</histogram>
<histogram name="Net.ProxyResolver.AbandonedExecutionTotalTime" units="ms"> <histogram name="Net.ProxyResolver.AbandonedExecutionTotalTime" units="ms">
<obsolete> <obsolete>
Removed in Chrome 39. Removed in Chrome 39.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment