| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "components/safe_browsing/base_safe_browsing_resource_throttle.h" | 5 #include "components/safe_browsing/base_safe_browsing_resource_throttle.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 void BaseSafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( | 231 void BaseSafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( |
| 232 const GURL& url, | 232 const GURL& url, |
| 233 safe_browsing::SBThreatType threat_type, | 233 safe_browsing::SBThreatType threat_type, |
| 234 const safe_browsing::ThreatMetadata& metadata) { | 234 const safe_browsing::ThreatMetadata& metadata) { |
| 235 CHECK_EQ(state_, STATE_CHECKING_URL); | 235 CHECK_EQ(state_, STATE_CHECKING_URL); |
| 236 // TODO(vakh): The following base::debug::Alias() and CHECK calls should be | 236 // TODO(vakh): The following base::debug::Alias() and CHECK calls should be |
| 237 // removed after http://crbug.com/660293 is fixed. | 237 // removed after http://crbug.com/660293 is fixed. |
| 238 CHECK(url.is_valid()); | 238 CHECK(url.is_valid()); |
| 239 CHECK(url_being_checked_.is_valid()); | 239 CHECK(url_being_checked_.is_valid()); |
| 240 if (url != url_being_checked_) { | 240 if (url != url_being_checked_) { |
| 241 char buf[2000]; | 241 bool url_had_timed_out = timed_out_urls_.count(url) > 0; |
| 242 snprintf(buf, sizeof(buf), "sbtr::ocbur:%s -- %s\n", url.spec().c_str(), | 242 char buf[1000]; |
| 243 url_being_checked_.spec().c_str()); | 243 snprintf(buf, sizeof(buf), "sbtr::ocbur:%d:%s -- %s\n", url_had_timed_out, |
| 244 url.spec().c_str(), url_being_checked_.spec().c_str()); |
| 244 base::debug::Alias(buf); | 245 base::debug::Alias(buf); |
| 245 CHECK(false) << "buf: " << buf; | 246 CHECK(false) << "buf: " << buf; |
| 246 } | 247 } |
| 247 | 248 |
| 248 timer_.Stop(); // Cancel the timeout timer. | 249 timer_.Stop(); // Cancel the timeout timer. |
| 249 threat_type_ = threat_type; | 250 threat_type_ = threat_type; |
| 250 state_ = STATE_NONE; | 251 state_ = STATE_NONE; |
| 251 | 252 |
| 252 if (defer_state_ != DEFERRED_NONE) { | 253 if (defer_state_ != DEFERRED_NONE) { |
| 253 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, nullptr, nullptr); | 254 EndNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, nullptr, nullptr); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 return false; | 407 return false; |
| 407 } | 408 } |
| 408 | 409 |
| 409 void BaseSafeBrowsingResourceThrottle::OnCheckUrlTimeout() { | 410 void BaseSafeBrowsingResourceThrottle::OnCheckUrlTimeout() { |
| 410 CHECK_EQ(state_, STATE_CHECKING_URL); | 411 CHECK_EQ(state_, STATE_CHECKING_URL); |
| 411 | 412 |
| 412 database_manager_->CancelCheck(this); | 413 database_manager_->CancelCheck(this); |
| 413 | 414 |
| 414 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, | 415 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, |
| 415 safe_browsing::ThreatMetadata()); | 416 safe_browsing::ThreatMetadata()); |
| 417 |
| 418 timed_out_urls_.insert(url_being_checked_); |
| 416 } | 419 } |
| 417 | 420 |
| 418 void BaseSafeBrowsingResourceThrottle::ResumeRequest() { | 421 void BaseSafeBrowsingResourceThrottle::ResumeRequest() { |
| 419 CHECK_EQ(state_, STATE_NONE); | 422 CHECK_EQ(state_, STATE_NONE); |
| 420 CHECK_NE(defer_state_, DEFERRED_NONE); | 423 CHECK_NE(defer_state_, DEFERRED_NONE); |
| 421 | 424 |
| 422 bool resume = true; | 425 bool resume = true; |
| 423 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { | 426 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { |
| 424 // Save the redirect urls for possible malware detail reporting later. | 427 // Save the redirect urls for possible malware detail reporting later. |
| 425 redirect_urls_.push_back(unchecked_redirect_url_); | 428 redirect_urls_.push_back(unchecked_redirect_url_); |
| 426 if (!CheckUrl(unchecked_redirect_url_)) { | 429 if (!CheckUrl(unchecked_redirect_url_)) { |
| 427 // We're now waiting for the unchecked_redirect_url_. | 430 // We're now waiting for the unchecked_redirect_url_. |
| 428 defer_state_ = DEFERRED_REDIRECT; | 431 defer_state_ = DEFERRED_REDIRECT; |
| 429 resume = false; | 432 resume = false; |
| 430 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, | 433 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, |
| 431 unchecked_redirect_url_, "defer_reason", | 434 unchecked_redirect_url_, "defer_reason", |
| 432 "resumed_redirect"); | 435 "resumed_redirect"); |
| 433 } | 436 } |
| 434 } | 437 } |
| 435 | 438 |
| 436 if (resume) { | 439 if (resume) { |
| 437 defer_state_ = DEFERRED_NONE; | 440 defer_state_ = DEFERRED_NONE; |
| 438 Resume(); | 441 Resume(); |
| 439 } | 442 } |
| 440 } | 443 } |
| OLD | NEW |