Chromium Code Reviews| 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/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 Loading... | |
| 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: |
| 63 return FILTERING_BEHAVIOR_BLOCK_SAFESITES; | |
| 64 case SupervisedUserURLFilter::MANUAL: | |
| 65 return FILTERING_BEHAVIOR_BLOCK_MANUAL; | |
| 66 case SupervisedUserURLFilter::DEFAULT: | |
| 67 return FILTERING_BEHAVIOR_BLOCK_DEFAULT; | |
| 68 } | |
| 61 // Fall through. | 69 // Fall through. |
|
Bernhard Bauer
2015/04/07 11:43:47
We don't really have a case where we fall through
Marc Treib
2015/04/07 11:52:59
Right. If we ever add a new value, the compiler sh
| |
| 62 default: | 70 default: |
|
Bernhard Bauer
2015/04/07 11:43:48
You could also replace this with the last value (I
Marc Treib
2015/04/07 11:52:59
Done.
| |
| 63 NOTREACHED(); | 71 NOTREACHED(); |
| 64 } | 72 } |
| 65 return 0; | 73 return 0; |
| 66 } | 74 } |
| 67 | 75 |
| 68 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) { | 76 int GetHistogramValueForTransitionType(ui::PageTransition transition_type) { |
| 69 int value = | 77 int value = |
| 70 static_cast<int>(ui::PageTransitionStripQualifier(transition_type)); | 78 static_cast<int>(ui::PageTransitionStripQualifier(transition_type)); |
| 71 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue) | 79 if (0 <= value && value <= kHistogramPageTransitionMaxKnownValue) |
| 72 return value; | 80 return value; |
| 73 NOTREACHED(); | 81 NOTREACHED(); |
| 74 return kHistogramPageTransitionFallbackValue; | 82 return kHistogramPageTransitionFallbackValue; |
| 75 } | 83 } |
| 76 | 84 |
| 77 void RecordFilterResultEvent( | 85 void RecordFilterResultEvent( |
| 86 bool safesites_histogram, | |
| 78 SupervisedUserURLFilter::FilteringBehavior behavior, | 87 SupervisedUserURLFilter::FilteringBehavior behavior, |
| 79 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 88 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
| 80 bool uncertain, | 89 bool uncertain, |
| 81 ui::PageTransition transition_type) { | 90 ui::PageTransition transition_type) { |
| 82 DCHECK(reason == SupervisedUserURLFilter::ASYNC_CHECKER || | |
| 83 reason == SupervisedUserURLFilter::BLACKLIST); | |
| 84 int value = | 91 int value = |
| 85 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) * | 92 GetHistogramValueForFilteringBehavior(behavior, reason, uncertain) * |
| 86 kHistogramFilteringBehaviorSpacing + | 93 kHistogramFilteringBehaviorSpacing + |
| 87 GetHistogramValueForTransitionType(transition_type); | 94 GetHistogramValueForTransitionType(transition_type); |
| 88 DCHECK_LT(value, kHistogramMax); | 95 DCHECK_LT(value, kHistogramMax); |
| 89 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.SafetyFilter", | 96 // Note: We can't pass in the histogram name as a parameter to this function |
| 90 value, kHistogramMax); | 97 // because of how the macro works (look up the histogram on the first |
| 98 // invocation and cache it in a static variable). | |
| 99 if (safesites_histogram) { | |
| 100 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.SafetyFilter", | |
| 101 value, kHistogramMax); | |
| 102 } else { | |
| 103 UMA_HISTOGRAM_ENUMERATION("ManagedUsers.FilteringResult", | |
| 104 value, kHistogramMax); | |
| 105 } | |
| 91 } | 106 } |
| 92 | 107 |
| 93 } // namespace | 108 } // namespace |
| 94 | 109 |
| 95 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle( | 110 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle( |
| 96 const net::URLRequest* request, | 111 const net::URLRequest* request, |
| 97 bool is_main_frame, | 112 bool is_main_frame, |
| 98 const SupervisedUserURLFilter* url_filter) | 113 const SupervisedUserURLFilter* url_filter) |
| 99 : request_(request), | 114 : request_(request), |
| 100 is_main_frame_(is_main_frame), | 115 is_main_frame_(is_main_frame), |
| 101 url_filter_(url_filter), | 116 url_filter_(url_filter), |
| 102 deferred_(false), | 117 deferred_(false), |
| 103 behavior_(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE), | 118 behavior_(SupervisedUserURLFilter::INVALID), |
| 104 weak_ptr_factory_(this) {} | 119 weak_ptr_factory_(this) {} |
| 105 | 120 |
| 106 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {} | 121 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {} |
| 107 | 122 |
| 108 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, | 123 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, |
| 109 const GURL& url, | 124 const GURL& url, |
| 110 bool* defer) { | 125 bool* defer) { |
| 111 // Only treat main frame requests for now (ignoring subresources). | 126 // Only treat main frame requests for now (ignoring subresources). |
| 112 if (!is_main_frame_) | 127 if (!is_main_frame_) |
| 113 return; | 128 return; |
| 114 | 129 |
| 115 deferred_ = false; | 130 deferred_ = false; |
| 116 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); | 131 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_); |
| 117 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( | 132 bool got_result = url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( |
| 118 url, | 133 url, |
| 119 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone, | 134 base::Bind(&SupervisedUserResourceThrottle::OnCheckDone, |
| 120 weak_ptr_factory_.GetWeakPtr(), url)); | 135 weak_ptr_factory_.GetWeakPtr(), url)); |
| 121 DCHECK_EQ(got_result, | 136 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. | 137 // If we got a "not blocked" result synchronously, don't defer. |
| 124 *defer = deferred_ = !got_result || | 138 *defer = deferred_ = !got_result || |
| 125 (behavior_ == SupervisedUserURLFilter::BLOCK); | 139 (behavior_ == SupervisedUserURLFilter::BLOCK); |
| 126 if (got_result) | 140 if (got_result) |
| 127 behavior_ = SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE; | 141 behavior_ = SupervisedUserURLFilter::INVALID; |
| 128 } | 142 } |
| 129 | 143 |
| 130 void SupervisedUserResourceThrottle::ShowInterstitial( | 144 void SupervisedUserResourceThrottle::ShowInterstitial( |
| 131 const GURL& url, | 145 const GURL& url, |
| 132 SupervisedUserURLFilter::FilteringBehaviorReason reason) { | 146 SupervisedUserURLFilter::FilteringBehaviorReason reason) { |
| 133 const content::ResourceRequestInfo* info = | 147 const content::ResourceRequestInfo* info = |
| 134 content::ResourceRequestInfo::ForRequest(request_); | 148 content::ResourceRequestInfo::ForRequest(request_); |
| 135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 149 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 136 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked, | 150 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked, |
| 137 info->GetChildID(), info->GetRouteID(), url, reason, | 151 info->GetChildID(), info->GetRouteID(), url, reason, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 152 | 166 |
| 153 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { | 167 const char* SupervisedUserResourceThrottle::GetNameForLogging() const { |
| 154 return "SupervisedUserResourceThrottle"; | 168 return "SupervisedUserResourceThrottle"; |
| 155 } | 169 } |
| 156 | 170 |
| 157 void SupervisedUserResourceThrottle::OnCheckDone( | 171 void SupervisedUserResourceThrottle::OnCheckDone( |
| 158 const GURL& url, | 172 const GURL& url, |
| 159 SupervisedUserURLFilter::FilteringBehavior behavior, | 173 SupervisedUserURLFilter::FilteringBehavior behavior, |
| 160 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 174 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
| 161 bool uncertain) { | 175 bool uncertain) { |
| 162 DCHECK_EQ(SupervisedUserURLFilter::HISTOGRAM_BOUNDING_VALUE, behavior_); | 176 DCHECK_EQ(SupervisedUserURLFilter::INVALID, behavior_); |
| 163 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. | 177 // If we got a result synchronously, pass it back to ShowInterstitialIfNeeded. |
| 164 if (!deferred_) | 178 if (!deferred_) |
| 165 behavior_ = behavior; | 179 behavior_ = behavior; |
| 166 | 180 |
| 167 // If both the static blacklist and SafeSites are enabled, record UMA events. | 181 ui::PageTransition transition = |
| 182 content::ResourceRequestInfo::ForRequest(request_)->GetPageTransition(); | |
| 183 | |
| 184 RecordFilterResultEvent(false, behavior, reason, uncertain, transition); | |
| 185 | |
| 186 // If both the static blacklist and the async checker are enabled, also record | |
| 187 // SafeSites-only UMA events. | |
| 168 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && | 188 if (url_filter_->HasBlacklist() && url_filter_->HasAsyncURLChecker() && |
| 169 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || | 189 (reason == SupervisedUserURLFilter::ASYNC_CHECKER || |
| 170 reason == SupervisedUserURLFilter::BLACKLIST)) { | 190 reason == SupervisedUserURLFilter::BLACKLIST)) { |
| 171 const content::ResourceRequestInfo* info = | 191 RecordFilterResultEvent(true, behavior, reason, uncertain, transition); |
| 172 content::ResourceRequestInfo::ForRequest(request_); | |
| 173 RecordFilterResultEvent(behavior, reason, uncertain, | |
| 174 info->GetPageTransition()); | |
| 175 } | 192 } |
| 176 | 193 |
| 177 if (behavior == SupervisedUserURLFilter::BLOCK) | 194 if (behavior == SupervisedUserURLFilter::BLOCK) |
| 178 ShowInterstitial(url, reason); | 195 ShowInterstitial(url, reason); |
| 179 else if (deferred_) | 196 else if (deferred_) |
| 180 controller()->Resume(); | 197 controller()->Resume(); |
| 181 } | 198 } |
| 182 | 199 |
| 183 void SupervisedUserResourceThrottle::OnInterstitialResult( | 200 void SupervisedUserResourceThrottle::OnInterstitialResult( |
| 184 bool continue_request) { | 201 bool continue_request) { |
| 185 if (continue_request) | 202 if (continue_request) |
| 186 controller()->Resume(); | 203 controller()->Resume(); |
| 187 else | 204 else |
| 188 controller()->Cancel(); | 205 controller()->Cancel(); |
| 189 } | 206 } |
| OLD | NEW |