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