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

Side by Side Diff: chrome/browser/renderer_host/safe_browsing_resource_throttle.cc

Issue 1515703005: WebRequest API: add more resource types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace == with && 2x Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/safe_browsing_resource_throttle.h" 5 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 13 matching lines...) Expand all
24 using safe_browsing::SafeBrowsingUIManager; 24 using safe_browsing::SafeBrowsingUIManager;
25 25
26 namespace { 26 namespace {
27 27
28 // Maximum time in milliseconds to wait for the safe browsing service to 28 // Maximum time in milliseconds to wait for the safe browsing service to
29 // verify a URL. After this amount of time the outstanding check will be 29 // verify a URL. After this amount of time the outstanding check will be
30 // aborted, and the URL will be treated as if it were safe. 30 // aborted, and the URL will be treated as if it were safe.
31 const int kCheckUrlTimeoutMs = 5000; 31 const int kCheckUrlTimeoutMs = 5000;
32 32
33 void RecordHistogramResourceTypeSafe(content::ResourceType resource_type) { 33 void RecordHistogramResourceTypeSafe(content::ResourceType resource_type) {
34 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Safe", resource_type, 34 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Safe", resource_type,
35 content::RESOURCE_TYPE_LAST_TYPE); 35 content::RESOURCE_TYPE_LAST_TYPE);
36 } 36 }
37 37
38 // Return a dictionary with "url"=|url-spec| and optionally 38 // Return a dictionary with "url"=|url-spec| and optionally
39 // |name|=|value| (if not null), for netlogging. 39 // |name|=|value| (if not null), for netlogging.
40 // This will also add a reference to the original request's net_log ID. 40 // This will also add a reference to the original request's net_log ID.
41 scoped_ptr<base::Value> NetLogUrlCallback( 41 scoped_ptr<base::Value> NetLogUrlCallback(
42 const net::URLRequest* request, 42 const net::URLRequest* request,
43 const GURL& url, 43 const GURL& url,
44 const char* name, 44 const char* name,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 ResumeRequest(); 226 ResumeRequest();
227 } else { 227 } else {
228 ui_manager_->LogPauseDelay(base::TimeDelta()); 228 ui_manager_->LogPauseDelay(base::TimeDelta());
229 } 229 }
230 return; 230 return;
231 } 231 }
232 232
233 if (request_->load_flags() & net::LOAD_PREFETCH) { 233 if (request_->load_flags() & net::LOAD_PREFETCH) {
234 // Don't prefetch resources that fail safe browsing, disallow them. 234 // Don't prefetch resources that fail safe browsing, disallow them.
235 controller()->Cancel(); 235 controller()->Cancel();
236 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.UnsafePrefetchCanceled", 236 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.UnsafePrefetchCanceled",
237 resource_type_, content::RESOURCE_TYPE_LAST_TYPE); 237 resource_type_, content::RESOURCE_TYPE_LAST_TYPE);
238 return; 238 return;
239 } 239 }
240 240
241 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Unsafe", resource_type_, 241 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Unsafe", resource_type_,
242 content::RESOURCE_TYPE_LAST_TYPE); 242 content::RESOURCE_TYPE_LAST_TYPE);
243 243
244 const content::ResourceRequestInfo* info = 244 const content::ResourceRequestInfo* info =
245 content::ResourceRequestInfo::ForRequest(request_); 245 content::ResourceRequestInfo::ForRequest(request_);
246 246
247 SafeBrowsingUIManager::UnsafeResource resource; 247 SafeBrowsingUIManager::UnsafeResource resource;
248 resource.url = url; 248 resource.url = url;
249 resource.original_url = request_->original_url(); 249 resource.original_url = request_->original_url();
250 resource.redirect_urls = redirect_urls_; 250 resource.redirect_urls = redirect_urls_;
251 resource.is_subresource = resource_type_ != content::RESOURCE_TYPE_MAIN_FRAME; 251 resource.is_subresource = resource_type_ != content::RESOURCE_TYPE_MAIN_FRAME;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } else { 316 } else {
317 controller()->Cancel(); 317 controller()->Cancel();
318 } 318 }
319 } 319 }
320 320
321 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { 321 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) {
322 CHECK_EQ(state_, STATE_NONE); 322 CHECK_EQ(state_, STATE_NONE);
323 // To reduce aggregate latency on mobile, check only the most dangerous 323 // To reduce aggregate latency on mobile, check only the most dangerous
324 // resource types. 324 // resource types.
325 if (!database_manager_->CanCheckResourceType(resource_type_)) { 325 if (!database_manager_->CanCheckResourceType(resource_type_)) {
326 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Skipped", resource_type_, 326 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Skipped", resource_type_,
327 content::RESOURCE_TYPE_LAST_TYPE); 327 content::RESOURCE_TYPE_LAST_TYPE);
328 return true; 328 return true;
329 } 329 }
330 330
331 bool succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this); 331 bool succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this);
332 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes.Checked", resource_type_, 332 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Checked", resource_type_,
333 content::RESOURCE_TYPE_LAST_TYPE); 333 content::RESOURCE_TYPE_LAST_TYPE);
334 334
335 if (succeeded_synchronously) { 335 if (succeeded_synchronously) {
336 RecordHistogramResourceTypeSafe(resource_type_); 336 RecordHistogramResourceTypeSafe(resource_type_);
337 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; 337 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE;
338 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. 338 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay.
339 return true; 339 return true;
340 } 340 }
341 341
342 state_ = STATE_CHECKING_URL; 342 state_ = STATE_CHECKING_URL;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 unchecked_redirect_url_, "defer_reason", 378 unchecked_redirect_url_, "defer_reason",
379 "resumed_redirect"); 379 "resumed_redirect");
380 } 380 }
381 } 381 }
382 382
383 if (resume) { 383 if (resume) {
384 defer_state_ = DEFERRED_NONE; 384 defer_state_ = DEFERRED_NONE;
385 controller()->Resume(); 385 controller()->Resume();
386 } 386 }
387 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698