OLD | NEW |
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/sparse_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" |
11 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 11 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
15 #include "net/url_request/redirect_info.h" | 15 #include "net/url_request/redirect_info.h" |
16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
17 #include "ui/base/page_transition_types.h" | 17 #include "ui/base/page_transition_types.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
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_SPARSE_SLOWLY("ManagedUsers.SafetyFilter", value); |
| 100 else |
| 101 UMA_HISTOGRAM_SPARSE_SLOWLY("ManagedUsers.FilteringResult", value); |
91 } | 102 } |
92 | 103 |
93 } // namespace | 104 } // namespace |
94 | 105 |
95 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle( | 106 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle( |
96 const net::URLRequest* request, | 107 const net::URLRequest* request, |
97 bool is_main_frame, | 108 bool is_main_frame, |
98 const SupervisedUserURLFilter* url_filter) | 109 const SupervisedUserURLFilter* url_filter) |
99 : request_(request), | 110 : request_(request), |
100 is_main_frame_(is_main_frame), | 111 is_main_frame_(is_main_frame), |
101 url_filter_(url_filter), | 112 url_filter_(url_filter), |
102 deferred_(false), | 113 deferred_(false), |
103 behavior_(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE), | 114 behavior_(SupervisedUserURLFilter::INVALID), |
104 weak_ptr_factory_(this) {} | 115 weak_ptr_factory_(this) {} |
105 | 116 |
106 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {} | 117 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {} |
107 | 118 |
108 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, | 119 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, |
109 const GURL& url, | 120 const GURL& url, |
110 bool* defer) { | 121 bool* defer) { |
111 // Only treat main frame requests for now (ignoring subresources). | 122 // Only treat main frame requests for now (ignoring subresources). |
112 if (!is_main_frame_) | 123 if (!is_main_frame_) |
113 return; | 124 return; |
114 | 125 |
115 deferred_ = false; | 126 deferred_ = false; |
116 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); | 127 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_); |
117 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( | 128 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( |
118 url, | 129 url, |
119 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone, | 130 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone, |
120 weak_ptr_factory_.GetWeakPtr(), url)); | 131 weak_ptr_factory_.GetWeakPtr(), url)); |
121 DCHECK_EQ(got_result, | 132 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. | 133 // If we got a "not blocked" result synchronously, don't defer. |
124 *defer = deferred_ = !got_result || | 134 *defer = deferred_ = !got_result || |
125 (behavior_ == SupervisedUserURLFilter::BLOCK); | 135 (behavior_ == SupervisedUserURLFilter::BLOCK); |
126 if (got_result) | 136 if (got_result) |
127 behavior_ = SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE; | 137 behavior_ = SupervisedUserURLFilter::INVALID; |
128 } | 138 } |
129 | 139 |
130 void SupervisedUserResourceThrottle::ShowInterstitial( | 140 void SupervisedUserResourceThrottle::ShowInterstitial( |
131 const GURL& url, | 141 const GURL& url, |
132 SupervisedUserURLFilter::FilteringBehaviorReason reason) { | 142 SupervisedUserURLFilter::FilteringBehaviorReason reason) { |
133 const content::ResourceRequestInfo* info = | 143 const content::ResourceRequestInfo* info = |
134 content::ResourceRequestInfo::ForRequest(request_); | 144 content::ResourceRequestInfo::ForRequest(request_); |
135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 145 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
136 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked, | 146 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked, |
137 info->GetChildID(), info->GetRouteID(), url, reason, | 147 info->GetChildID(), info->GetRouteID(), url, reason, |
(...skipping 14 matching lines...) Expand all Loading... |
152 | 162 |
153 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { | 163 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { |
154 return "SupervisedUserResourceThrottle"; | 164 return "SupervisedUserResourceThrottle"; |
155 } | 165 } |
156 | 166 |
157 void SupervisedUserResourceThrottle::OnCheckDone( | 167 void SupervisedUserResourceThrottle::OnCheckDone( |
158 const GURL& url, | 168 const GURL& url, |
159 SupervisedUserURLFilter::FilteringBehavior behavior, | 169 SupervisedUserURLFilter::FilteringBehavior behavior, |
160 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 170 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
161 bool uncertain) { | 171 bool uncertain) { |
162 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); | 172 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_); |
163 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. | 173 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. |
164 if (!deferred_) | 174 if (!deferred_) |
165 behavior_ = behavior; | 175 behavior_ = behavior; |
166 | 176 |
167 // If both the static blacklist and SafeSites are enabled, record UMA events. | 177 ui::PageTransition transition = |
| 178 content::ResourceRequestInfo::ForRequest(request_)->GetPageTransition(); |
| 179 |
| 180 RecordFilterResultEvent(false, behavior, reason, uncertain, transition); |
| 181 |
| 182 // If both the static blacklist and the async checker are enabled, also record |
| 183 // SafeSites-only UMA events. |
168 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && | 184 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && |
169 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || | 185 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || |
170 reason == SupervisedUserURLFilter::BLACKLIST)) { | 186 reason == SupervisedUserURLFilter::BLACKLIST)) { |
171 const content::ResourceRequestInfo* info = | 187 RecordFilterResultEvent(true, behavior, reason, uncertain, transition); |
172 content::ResourceRequestInfo::ForRequest(request_); | |
173 RecordFilterResultEvent(behavior, reason, uncertain, | |
174 info->GetPageTransition()); | |
175 } | 188 } |
176 | 189 |
177 if (behavior == SupervisedUserURLFilter::BLOCK) | 190 if (behavior == SupervisedUserURLFilter::BLOCK) |
178 ShowInterstitial(url, reason); | 191 ShowInterstitial(url, reason); |
179 else if (deferred_) | 192 else if (deferred_) |
180 controller()->Resume(); | 193 controller()->Resume(); |
181 } | 194 } |
182 | 195 |
183 void SupervisedUserResourceThrottle::OnInterstitialResult( | 196 void SupervisedUserResourceThrottle::OnInterstitialResult( |
184 bool continue_request) { | 197 bool continue_request) { |
185 if (continue_request) | 198 if (continue_request) |
186 controller()->Resume(); | 199 controller()->Resume(); |
187 else | 200 else |
188 controller()->Cancel(); | 201 controller()->Cancel(); |
189 } | 202 } |
OLD | NEW |