| OLD | NEW |
| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 15 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 16 #include "components/safe_browsing_db/util.h" | 17 #include "components/safe_browsing_db/util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 defer_state_(DEFERRED_NONE), | 92 defer_state_(DEFERRED_NONE), |
| 92 threat_type_(safe_browsing::SB_THREAT_TYPE_SAFE), | 93 threat_type_(safe_browsing::SB_THREAT_TYPE_SAFE), |
| 93 database_manager_(sb_service->database_manager()), | 94 database_manager_(sb_service->database_manager()), |
| 94 ui_manager_(sb_service->ui_manager()), | 95 ui_manager_(sb_service->ui_manager()), |
| 95 request_(request), | 96 request_(request), |
| 96 resource_type_(resource_type), | 97 resource_type_(resource_type), |
| 97 bound_net_log_(net::BoundNetLog::Make(request->net_log().net_log(), | 98 bound_net_log_(net::BoundNetLog::Make(request->net_log().net_log(), |
| 98 NetLog::SOURCE_SAFE_BROWSING)) {} | 99 NetLog::SOURCE_SAFE_BROWSING)) {} |
| 99 | 100 |
| 100 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { | 101 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { |
| 102 TRACE_EVENT0("toplevel", |
| 103 "SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle"); |
| 104 |
| 101 if (defer_state_ != DEFERRED_NONE) { | 105 if (defer_state_ != DEFERRED_NONE) { |
| 102 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); | 106 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_DEFERRED, nullptr, nullptr); |
| 103 } | 107 } |
| 104 | 108 |
| 105 if (state_ == STATE_CHECKING_URL) { | 109 if (state_ == STATE_CHECKING_URL) { |
| 106 database_manager_->CancelCheck(this); | 110 database_manager_->CancelCheck(this); |
| 107 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, "result", | 111 EndNetLogEvent(NetLog::TYPE_SAFE_BROWSING_CHECKING_URL, "result", |
| 108 "request_canceled"); | 112 "request_canceled"); |
| 109 } | 113 } |
| 110 } | 114 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 125 void SafeBrowsingResourceThrottle::EndNetLogEvent(NetLog::EventType type, | 129 void SafeBrowsingResourceThrottle::EndNetLogEvent(NetLog::EventType type, |
| 126 const char* name, | 130 const char* name, |
| 127 const char* value) { | 131 const char* value) { |
| 128 bound_net_log_.EndEvent( | 132 bound_net_log_.EndEvent( |
| 129 type, base::Bind(&NetLogStringCallback, name, value)); | 133 type, base::Bind(&NetLogStringCallback, name, value)); |
| 130 request_->net_log().AddEvent( | 134 request_->net_log().AddEvent( |
| 131 type, bound_net_log_.source().ToEventParametersCallback()); | 135 type, bound_net_log_.source().ToEventParametersCallback()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { | 138 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { |
| 139 TRACE_EVENT0("toplevel", "SafeBrowsingResourceThrottle::WillStartRequest"); |
| 140 |
| 135 // We need to check the new URL before starting the request. | 141 // We need to check the new URL before starting the request. |
| 136 if (CheckUrl(request_->url())) | 142 if (CheckUrl(request_->url())) |
| 137 return; | 143 return; |
| 138 | 144 |
| 139 // We let the check run in parallel with resource load only if this | 145 // We let the check run in parallel with resource load only if this |
| 140 // db_manager only supports asynchronous checks, like on mobile. | 146 // db_manager only supports asynchronous checks, like on mobile. |
| 141 // Otherwise, we defer now. | 147 // Otherwise, we defer now. |
| 142 if (database_manager_->ChecksAreAlwaysAsync()) | 148 if (database_manager_->ChecksAreAlwaysAsync()) |
| 143 return; | 149 return; |
| 144 | 150 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; | 322 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; |
| 317 if (defer_state_ != DEFERRED_NONE) { | 323 if (defer_state_ != DEFERRED_NONE) { |
| 318 ResumeRequest(); | 324 ResumeRequest(); |
| 319 } | 325 } |
| 320 } else { | 326 } else { |
| 321 controller()->Cancel(); | 327 controller()->Cancel(); |
| 322 } | 328 } |
| 323 } | 329 } |
| 324 | 330 |
| 325 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { | 331 bool SafeBrowsingResourceThrottle::CheckUrl(const GURL& url) { |
| 332 TRACE_EVENT0("toplevel", "SafeBrowsingResourceThrottle::CheckUrl"); |
| 326 TRACE_EVENT1("loader", "SafeBrowsingResourceThrottle::CheckUrl", "url", | 333 TRACE_EVENT1("loader", "SafeBrowsingResourceThrottle::CheckUrl", "url", |
| 327 url.spec()); | 334 url.spec()); |
| 328 CHECK_EQ(state_, STATE_NONE); | 335 CHECK_EQ(state_, STATE_NONE); |
| 329 // To reduce aggregate latency on mobile, check only the most dangerous | 336 // To reduce aggregate latency on mobile, check only the most dangerous |
| 330 // resource types. | 337 // resource types. |
| 331 if (!database_manager_->CanCheckResourceType(resource_type_)) { | 338 if (!database_manager_->CanCheckResourceType(resource_type_)) { |
| 332 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Skipped", resource_type_, | 339 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Skipped", resource_type_, |
| 333 content::RESOURCE_TYPE_LAST_TYPE); | 340 content::RESOURCE_TYPE_LAST_TYPE); |
| 334 return true; | 341 return true; |
| 335 } | 342 } |
| 336 | 343 |
| 337 bool succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this); | 344 bool succeeded_synchronously; |
| 345 { |
| 346 TRACE_EVENT0("toplevel", "SafeBrowsingDatabaseManaager::CheckBrowseUrl"); |
| 347 succeeded_synchronously = database_manager_->CheckBrowseUrl(url, this); |
| 348 } |
| 349 |
| 338 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Checked", resource_type_, | 350 UMA_HISTOGRAM_ENUMERATION("SB2.ResourceTypes2.Checked", resource_type_, |
| 339 content::RESOURCE_TYPE_LAST_TYPE); | 351 content::RESOURCE_TYPE_LAST_TYPE); |
| 340 | 352 |
| 341 if (succeeded_synchronously) { | 353 if (succeeded_synchronously) { |
| 342 RecordHistogramResourceTypeSafe(resource_type_); | 354 RecordHistogramResourceTypeSafe(resource_type_); |
| 343 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; | 355 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; |
| 344 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. | 356 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. |
| 345 return true; | 357 return true; |
| 346 } | 358 } |
| 347 | 359 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 unchecked_redirect_url_, "defer_reason", | 396 unchecked_redirect_url_, "defer_reason", |
| 385 "resumed_redirect"); | 397 "resumed_redirect"); |
| 386 } | 398 } |
| 387 } | 399 } |
| 388 | 400 |
| 389 if (resume) { | 401 if (resume) { |
| 390 defer_state_ = DEFERRED_NONE; | 402 defer_state_ = DEFERRED_NONE; |
| 391 controller()->Resume(); | 403 controller()->Resume(); |
| 392 } | 404 } |
| 393 } | 405 } |
| OLD | NEW |