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/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 void SafeBrowsingResourceThrottle::OnCheckBrowseUrlResult( | 231 void SafeBrowsingResourceThrottle::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 = base::ContainsValue(timed_out_urls_, url); |
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; | 392 threat_type_ = safe_browsing::SB_THREAT_TYPE_SAFE; |
392 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. | 393 ui_manager_->LogPauseDelay(base::TimeDelta()); // No delay. |
393 return true; | 394 return true; |
394 } | 395 } |
395 | 396 |
396 state_ = STATE_CHECKING_URL; | 397 state_ = STATE_CHECKING_URL; |
397 url_being_checked_ = url; | 398 url_being_checked_ = url; |
398 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_CHECKING_URL, url, nullptr, | 399 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_CHECKING_URL, url, nullptr, |
399 nullptr); | 400 nullptr); |
400 | 401 |
402 // If the URL had timed out earlier but is being retried, remove it from the | |
403 // list of URLs that timed out. | |
404 auto iter = std::find(timed_out_urls_.begin(), timed_out_urls_.end(), url); | |
405 if (iter != timed_out_urls_.end()) { | |
Nathan Parker
2017/01/06 01:41:01
same comment I had before: I don't think a URL can
vakh (use Gerrit instead)
2017/01/06 02:15:08
There you go! I agree that caring for SB check tim
| |
406 timed_out_urls_.erase(iter); | |
407 } | |
401 // Start a timer to abort the check if it takes too long. | 408 // Start a timer to abort the check if it takes too long. |
402 // TODO(nparker): Set this only when we defer, based on remaining time, | 409 // TODO(nparker): Set this only when we defer, based on remaining time, |
403 // so we don't cancel earlier than necessary. | 410 // so we don't cancel earlier than necessary. |
404 timer_.Start(FROM_HERE, | 411 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), |
405 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), | |
406 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); | 412 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); |
407 | 413 |
408 return false; | 414 return false; |
409 } | 415 } |
410 | 416 |
411 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { | 417 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { |
412 CHECK_EQ(state_, STATE_CHECKING_URL); | 418 CHECK_EQ(state_, STATE_CHECKING_URL); |
413 | 419 |
414 database_manager_->CancelCheck(this); | 420 database_manager_->CancelCheck(this); |
415 | 421 |
416 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, | 422 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, |
417 safe_browsing::ThreatMetadata()); | 423 safe_browsing::ThreatMetadata()); |
424 timed_out_urls_.push_back(url_being_checked_); | |
418 } | 425 } |
419 | 426 |
420 void SafeBrowsingResourceThrottle::ResumeRequest() { | 427 void SafeBrowsingResourceThrottle::ResumeRequest() { |
421 CHECK_EQ(state_, STATE_NONE); | 428 CHECK_EQ(state_, STATE_NONE); |
422 CHECK_NE(defer_state_, DEFERRED_NONE); | 429 CHECK_NE(defer_state_, DEFERRED_NONE); |
423 | 430 |
424 bool resume = true; | 431 bool resume = true; |
425 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { | 432 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { |
426 // Save the redirect urls for possible malware detail reporting later. | 433 // Save the redirect urls for possible malware detail reporting later. |
427 redirect_urls_.push_back(unchecked_redirect_url_); | 434 redirect_urls_.push_back(unchecked_redirect_url_); |
428 if (!CheckUrl(unchecked_redirect_url_)) { | 435 if (!CheckUrl(unchecked_redirect_url_)) { |
429 // We're now waiting for the unchecked_redirect_url_. | 436 // We're now waiting for the unchecked_redirect_url_. |
430 defer_state_ = DEFERRED_REDIRECT; | 437 defer_state_ = DEFERRED_REDIRECT; |
431 resume = false; | 438 resume = false; |
432 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, | 439 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, |
433 unchecked_redirect_url_, "defer_reason", | 440 unchecked_redirect_url_, "defer_reason", |
434 "resumed_redirect"); | 441 "resumed_redirect"); |
435 } | 442 } |
436 } | 443 } |
437 | 444 |
438 if (resume) { | 445 if (resume) { |
439 defer_state_ = DEFERRED_NONE; | 446 defer_state_ = DEFERRED_NONE; |
440 Resume(); | 447 Resume(); |
441 } | 448 } |
442 } | 449 } |
OLD | NEW |