Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: chrome/browser/supervised_user/supervised_user_resource_throttle.cc

Issue 1043113002: Supervised users: Add histogram to record filtering results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review2 Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/supervised_user/supervised_user_url_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/supervised_user_resource_throttle.h" 5 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" 9 #include "chrome/browser/supervised_user/supervised_user_interstitial.h"
10 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" 10 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
(...skipping 10 matching lines...) Expand all
21 namespace { 21 namespace {
22 22
23 // These values corresponds to SupervisedUserSafetyFilterResult in 23 // These values corresponds to SupervisedUserSafetyFilterResult in
24 // tools/metrics/histograms/histograms.xml. If you change anything here, make 24 // tools/metrics/histograms/histograms.xml. If you change anything here, make
25 // sure to also update histograms.xml accordingly. 25 // sure to also update histograms.xml accordingly.
26 enum { 26 enum {
27 FILTERING_BEHAVIOR_ALLOW = 1, 27 FILTERING_BEHAVIOR_ALLOW = 1,
28 FILTERING_BEHAVIOR_ALLOW_UNCERTAIN, 28 FILTERING_BEHAVIOR_ALLOW_UNCERTAIN,
29 FILTERING_BEHAVIOR_BLOCK_BLACKLIST, 29 FILTERING_BEHAVIOR_BLOCK_BLACKLIST,
30 FILTERING_BEHAVIOR_BLOCK_SAFESITES, 30 FILTERING_BEHAVIOR_BLOCK_SAFESITES,
31 FILTERING_BEHAVIOR_MAX = FILTERING_BEHAVIOR_BLOCK_SAFESITES 31 FILTERING_BEHAVIOR_BLOCK_MANUAL,
32 FILTERING_BEHAVIOR_BLOCK_DEFAULT,
33 FILTERING_BEHAVIOR_MAX = FILTERING_BEHAVIOR_BLOCK_DEFAULT
32 }; 34 };
33 const int kHistogramFilteringBehaviorSpacing = 100; 35 const int kHistogramFilteringBehaviorSpacing = 100;
34 const int kHistogramPageTransitionMaxKnownValue = 36 const int kHistogramPageTransitionMaxKnownValue =
35 static_cast<int>(ui::PAGE_TRANSITION_KEYWORD_GENERATED); 37 static_cast<int>(ui::PAGE_TRANSITION_KEYWORD_GENERATED);
36 const int kHistogramPageTransitionFallbackValue = 38 const int kHistogramPageTransitionFallbackValue =
37 kHistogramFilteringBehaviorSpacing - 1; 39 kHistogramFilteringBehaviorSpacing - 1;
38 const int kHistogramMax = 500; 40 const int kHistogramMax = 700;
39 41
40 static_assert(kHistogramPageTransitionMaxKnownValue < 42 static_assert(kHistogramPageTransitionMaxKnownValue <
41 kHistogramPageTransitionFallbackValue, 43 kHistogramPageTransitionFallbackValue,
42 "HistogramPageTransition MaxKnownValue must be < FallbackValue"); 44 "HistogramPageTransition MaxKnownValue must be < FallbackValue");
43 static_assert(FILTERING_BEHAVIOR_MAX * kHistogramFilteringBehaviorSpacing + 45 static_assert(FILTERING_BEHAVIOR_MAX * kHistogramFilteringBehaviorSpacing +
44 kHistogramPageTransitionFallbackValue < kHistogramMax, 46 kHistogramPageTransitionFallbackValue < kHistogramMax,
45 "Invalid HistogramMax value"); 47 "Invalid HistogramMax value");
46 48
47 int GetHistogramValueForFilteringBehavior( 49 int GetHistogramValueForFilteringBehavior(
48 SupervisedUserURLFilter::FilteringBehavior behavior, 50 SupervisedUserURLFilter::FilteringBehavior behavior,
49 SupervisedUserURLFilter::FilteringBehaviorReason reason, 51 SupervisedUserURLFilter::FilteringBehaviorReason reason,
50 bool uncertain) { 52 bool uncertain) {
51 switch (behavior) { 53 switch (behavior) {
52 case SupervisedUserURLFilter::ALLOW: 54 case SupervisedUserURLFilter::ALLOW:
53 case SupervisedUserURLFilter::WARN: 55 case SupervisedUserURLFilter::WARN:
54 return uncertain ? FILTERING_BEHAVIOR_ALLOW_UNCERTAIN 56 return uncertain ? FILTERING_BEHAVIOR_ALLOW_UNCERTAIN
55 : FILTERING_BEHAVIOR_ALLOW; 57 : FILTERING_BEHAVIOR_ALLOW;
56 case SupervisedUserURLFilter::BLOCK: 58 case SupervisedUserURLFilter::BLOCK:
57 if (reason == SupervisedUserURLFilter::BLACKLIST) 59 switch (reason) {
58 return FILTERING_BEHAVIOR_BLOCK_BLACKLIST; 60 case SupervisedUserURLFilter::BLACKLIST:
59 else if (reason == SupervisedUserURLFilter::ASYNC_CHECKER) 61 return FILTERING_BEHAVIOR_BLOCK_BLACKLIST;
60 return FILTERING_BEHAVIOR_BLOCK_SAFESITES; 62 case SupervisedUserURLFilter::ASYNC_CHECKER:
61 // Fall through. 63 return FILTERING_BEHAVIOR_BLOCK_SAFESITES;
62 default: 64 case SupervisedUserURLFilter::MANUAL:
65 return FILTERING_BEHAVIOR_BLOCK_MANUAL;
66 case SupervisedUserURLFilter::DEFAULT:
67 return FILTERING_BEHAVIOR_BLOCK_DEFAULT;
68 }
69 case SupervisedUserURLFilter::INVALID:
63 NOTREACHED(); 70 NOTREACHED();
64 } 71 }
65 return 0; 72 return 0;
66 } 73 }
67 74
68 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) { 75 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) {
69 int value = 76 int value =
70 static_cast<int>(ui::PageTransitionStripQualifier(transition_type)); 77 static_cast<int>(ui::PageTransitionStripQualifier(transition_type));
71 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue) 78 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue)
72 return value; 79 return value;
73 NOTREACHED(); 80 NOTREACHED();
74 return kHistogramPageTransitionFallbackValue; 81 return kHistogramPageTransitionFallbackValue;
75 } 82 }
76 83
77 void RecordFilterResultEvent( 84 void RecordFilterResultEvent(
85 bool safesites_histogram,
78 SupervisedUserURLFilter::FilteringBehavior behavior, 86 SupervisedUserURLFilter::FilteringBehavior behavior,
79 SupervisedUserURLFilter::FilteringBehaviorReason reason, 87 SupervisedUserURLFilter::FilteringBehaviorReason reason,
80 bool uncertain, 88 bool uncertain,
81 ui::PageTransition transition_type) { 89 ui::PageTransition transition_type) {
82 DCHECK(reason == SupervisedUserURLFilter::ASYNC_CHECKER ||
83 reason == SupervisedUserURLFilter::BLACKLIST);
84 int value = 90 int value =
85 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) * 91 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) *
86 kHistogramFilteringBehaviorSpacing + 92 kHistogramFilteringBehaviorSpacing +
87 GetHistogramValueForTransitionType(transition_type); 93 GetHistogramValueForTransitionType(transition_type);
88 DCHECK_LT(value, kHistogramMax); 94 DCHECK_LT(value, kHistogramMax);
89 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.SafetyFilter", 95 // Note: We can't pass in the histogram name as a parameter to this function
90 value, kHistogramMax); 96 // because of how the macro works (look up the histogram on the first
97 // invocation and cache it in a static variable).
98 if (safesites_histogram) {
99 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.SafetyFilter",
100 value, kHistogramMax);
101 } else {
102 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.FilteringResult",
Alexei Svitkine (slow) 2015/04/07 15:05:49 Please change both of these to UMA_HISTOGRAM_SPARS
Marc Treib 2015/04/07 15:20:09 Today I learned. Thanks, done!
103 value, kHistogramMax);
104 }
91 } 105 }
92 106
93 } // namespace 107 } // namespace
94 108
95 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle( 109 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle(
96 const net::URLRequest* request, 110 const net::URLRequest* request,
97 bool is_main_frame, 111 bool is_main_frame,
98 const SupervisedUserURLFilter* url_filter) 112 const SupervisedUserURLFilter* url_filter)
99 : request_(request), 113 : request_(request),
100 is_main_frame_(is_main_frame), 114 is_main_frame_(is_main_frame),
101 url_filter_(url_filter), 115 url_filter_(url_filter),
102 deferred_(false), 116 deferred_(false),
103 behavior_(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE), 117 behavior_(SupervisedUserURLFilter::INVALID),
104 weak_ptr_factory_(this) {} 118 weak_ptr_factory_(this) {}
105 119
106 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {} 120 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {}
107 121
108 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, 122 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect,
109 const GURL& url, 123 const GURL& url,
110 bool* defer) { 124 bool* defer) {
111 // Only treat main frame requests for now (ignoring subresources). 125 // Only treat main frame requests for now (ignoring subresources).
112 if (!is_main_frame_) 126 if (!is_main_frame_)
113 return; 127 return;
114 128
115 deferred_ = false; 129 deferred_ = false;
116 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); 130 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_);
117 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( 131 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks(
118 url, 132 url,
119 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone, 133 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone,
120 weak_ptr_factory_.GetWeakPtr(), url)); 134 weak_ptr_factory_.GetWeakPtr(), url));
121 DCHECK_EQ(got_result, 135 DCHECK_EQ(got_result, behavior_ != SupervisedUserURLFilter::INVALID);
122 (behavior_ != SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE));
123 // If we got a "not blocked" result synchronously, don't defer. 136 // If we got a "not blocked" result synchronously, don't defer.
124 *defer = deferred_ = !got_result || 137 *defer = deferred_ = !got_result ||
125 (behavior_ == SupervisedUserURLFilter::BLOCK); 138 (behavior_ == SupervisedUserURLFilter::BLOCK);
126 if (got_result) 139 if (got_result)
127 behavior_ = SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE; 140 behavior_ = SupervisedUserURLFilter::INVALID;
128 } 141 }
129 142
130 void SupervisedUserResourceThrottle::ShowInterstitial( 143 void SupervisedUserResourceThrottle::ShowInterstitial(
131 const GURL& url, 144 const GURL& url,
132 SupervisedUserURLFilter::FilteringBehaviorReason reason) { 145 SupervisedUserURLFilter::FilteringBehaviorReason reason) {
133 const content::ResourceRequestInfo* info = 146 const content::ResourceRequestInfo* info =
134 content::ResourceRequestInfo::ForRequest(request_); 147 content::ResourceRequestInfo::ForRequest(request_);
135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
136 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked, 149 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked,
137 info->GetChildID(), info->GetRouteID(), url, reason, 150 info->GetChildID(), info->GetRouteID(), url, reason,
(...skipping 14 matching lines...) Expand all
152 165
153 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { 166 const char* SupervisedUserResourceThrottle::GetNameForLogging() const {
154 return "SupervisedUserResourceThrottle"; 167 return "SupervisedUserResourceThrottle";
155 } 168 }
156 169
157 void SupervisedUserResourceThrottle::OnCheckDone( 170 void SupervisedUserResourceThrottle::OnCheckDone(
158 const GURL& url, 171 const GURL& url,
159 SupervisedUserURLFilter::FilteringBehavior behavior, 172 SupervisedUserURLFilter::FilteringBehavior behavior,
160 SupervisedUserURLFilter::FilteringBehaviorReason reason, 173 SupervisedUserURLFilter::FilteringBehaviorReason reason,
161 bool uncertain) { 174 bool uncertain) {
162 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); 175 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_);
163 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. 176 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded.
164 if (!deferred_) 177 if (!deferred_)
165 behavior_ = behavior; 178 behavior_ = behavior;
166 179
167 // If both the static blacklist and SafeSites are enabled, record UMA events. 180 ui::PageTransition transition =
181 content::ResourceRequestInfo::ForRequest(request_)->GetPageTransition();
182
183 RecordFilterResultEvent(false, behavior, reason, uncertain, transition);
184
185 // If both the static blacklist and the async checker are enabled, also record
186 // SafeSites-only UMA events.
168 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && 187 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() &&
169 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || 188 (reason == SupervisedUserURLFilter::ASYNC_CHECKER ||
170 reason == SupervisedUserURLFilter::BLACKLIST)) { 189 reason == SupervisedUserURLFilter::BLACKLIST)) {
171 const content::ResourceRequestInfo* info = 190 RecordFilterResultEvent(true, behavior, reason, uncertain, transition);
172 content::ResourceRequestInfo::ForRequest(request_);
173 RecordFilterResultEvent(behavior, reason, uncertain,
174 info->GetPageTransition());
175 } 191 }
176 192
177 if (behavior == SupervisedUserURLFilter::BLOCK) 193 if (behavior == SupervisedUserURLFilter::BLOCK)
178 ShowInterstitial(url, reason); 194 ShowInterstitial(url, reason);
179 else if (deferred_) 195 else if (deferred_)
180 controller()->Resume(); 196 controller()->Resume();
181 } 197 }
182 198
183 void SupervisedUserResourceThrottle::OnInterstitialResult( 199 void SupervisedUserResourceThrottle::OnInterstitialResult(
184 bool continue_request) { 200 bool continue_request) {
185 if (continue_request) 201 if (continue_request)
186 controller()->Resume(); 202 controller()->Resume();
187 else 203 else
188 controller()->Cancel(); 204 controller()->Cancel();
189 } 205 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/supervised_user/supervised_user_url_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698