| 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/loader/safe_browsing_resource_throttle.h" | 5 #include "chrome/browser/loader/safe_browsing_resource_throttle.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const net::URLRequest* request, | 87 const net::URLRequest* request, |
| 88 content::ResourceType resource_type, | 88 content::ResourceType resource_type, |
| 89 safe_browsing::SafeBrowsingService* sb_service) | 89 safe_browsing::SafeBrowsingService* sb_service) |
| 90 : state_(STATE_NONE), | 90 : state_(STATE_NONE), |
| 91 defer_state_(DEFERRED_NONE), | 91 defer_state_(DEFERRED_NONE), |
| 92 threat_type_(safe_browsing::SB_THREAT_TYPE_SAFE), | 92 threat_type_(safe_browsing::SB_THREAT_TYPE_SAFE), |
| 93 database_manager_(sb_service->database_manager()), | 93 database_manager_(sb_service->database_manager()), |
| 94 ui_manager_(sb_service->ui_manager()), | 94 ui_manager_(sb_service->ui_manager()), |
| 95 request_(request), | 95 request_(request), |
| 96 resource_type_(resource_type), | 96 resource_type_(resource_type), |
| 97 bound_net_log_(net::BoundNetLog::Make(request->net_log().net_log(), | 97 net_log_with_source_( |
| 98 NetLogSourceType::SAFE_BROWSING)) {} | 98 net::NetLogWithSource::Make(request->net_log().net_log(), |
| 99 NetLogSourceType::SAFE_BROWSING)) {} |
| 99 | 100 |
| 100 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { | 101 SafeBrowsingResourceThrottle::~SafeBrowsingResourceThrottle() { |
| 101 if (defer_state_ != DEFERRED_NONE) { | 102 if (defer_state_ != DEFERRED_NONE) { |
| 102 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, nullptr, nullptr); | 103 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, nullptr, nullptr); |
| 103 } | 104 } |
| 104 | 105 |
| 105 if (state_ == STATE_CHECKING_URL) { | 106 if (state_ == STATE_CHECKING_URL) { |
| 106 database_manager_->CancelCheck(this); | 107 database_manager_->CancelCheck(this); |
| 107 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_CHECKING_URL, "result", | 108 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_CHECKING_URL, "result", |
| 108 "request_canceled"); | 109 "request_canceled"); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 // Note on net_log calls: SAFE_BROWSING_DEFERRED events must be wholly | 113 // Note on net_log calls: SAFE_BROWSING_DEFERRED events must be wholly |
| 113 // nested within SAFE_BROWSING_CHECKING_URL events. Synchronous checks | 114 // nested within SAFE_BROWSING_CHECKING_URL events. Synchronous checks |
| 114 // are not logged at all. | 115 // are not logged at all. |
| 115 void SafeBrowsingResourceThrottle::BeginNetLogEvent(NetLogEventType type, | 116 void SafeBrowsingResourceThrottle::BeginNetLogEvent(NetLogEventType type, |
| 116 const GURL& url, | 117 const GURL& url, |
| 117 const char* name, | 118 const char* name, |
| 118 const char* value) { | 119 const char* value) { |
| 119 bound_net_log_.BeginEvent( | 120 net_log_with_source_.BeginEvent( |
| 120 type, base::Bind(&NetLogUrlCallback, request_, url, name, value)); | 121 type, base::Bind(&NetLogUrlCallback, request_, url, name, value)); |
| 121 request_->net_log().AddEvent( | 122 request_->net_log().AddEvent( |
| 122 type, bound_net_log_.source().ToEventParametersCallback()); | 123 type, net_log_with_source_.source().ToEventParametersCallback()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void SafeBrowsingResourceThrottle::EndNetLogEvent(NetLogEventType type, | 126 void SafeBrowsingResourceThrottle::EndNetLogEvent(NetLogEventType type, |
| 126 const char* name, | 127 const char* name, |
| 127 const char* value) { | 128 const char* value) { |
| 128 bound_net_log_.EndEvent( | 129 net_log_with_source_.EndEvent( |
| 129 type, base::Bind(&NetLogStringCallback, name, value)); | 130 type, base::Bind(&NetLogStringCallback, name, value)); |
| 130 request_->net_log().AddEvent( | 131 request_->net_log().AddEvent( |
| 131 type, bound_net_log_.source().ToEventParametersCallback()); | 132 type, net_log_with_source_.source().ToEventParametersCallback()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { | 135 void SafeBrowsingResourceThrottle::WillStartRequest(bool* defer) { |
| 135 // We need to check the new URL before starting the request. | 136 // We need to check the new URL before starting the request. |
| 136 if (CheckUrl(request_->url())) | 137 if (CheckUrl(request_->url())) |
| 137 return; | 138 return; |
| 138 | 139 |
| 139 // We let the check run in parallel with resource load only if this | 140 // We let the check run in parallel with resource load only if this |
| 140 // db_manager only supports asynchronous checks, like on mobile. | 141 // db_manager only supports asynchronous checks, like on mobile. |
| 141 // Otherwise, we defer now. | 142 // Otherwise, we defer now. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 unchecked_redirect_url_, "defer_reason", | 418 unchecked_redirect_url_, "defer_reason", |
| 418 "resumed_redirect"); | 419 "resumed_redirect"); |
| 419 } | 420 } |
| 420 } | 421 } |
| 421 | 422 |
| 422 if (resume) { | 423 if (resume) { |
| 423 defer_state_ = DEFERRED_NONE; | 424 defer_state_ = DEFERRED_NONE; |
| 424 controller()->Resume(); | 425 controller()->Resume(); |
| 425 } | 426 } |
| 426 } | 427 } |
| OLD | NEW |