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

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

Issue 2616653002: Have a list of pending checks instead of pending clients (Closed)
Patch Set: Rebase and use the new fake GHPM in unit test Created 3 years, 11 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/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
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
401 // Start a timer to abort the check if it takes too long. 402 // 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, 403 // TODO(nparker): Set this only when we defer, based on remaining time,
403 // so we don't cancel earlier than necessary. 404 // so we don't cancel earlier than necessary.
404 timer_.Start(FROM_HERE, 405 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs),
405 base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs),
406 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout); 406 this, &SafeBrowsingResourceThrottle::OnCheckUrlTimeout);
407 407
408 return false; 408 return false;
409 } 409 }
410 410
411 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() { 411 void SafeBrowsingResourceThrottle::OnCheckUrlTimeout() {
412 CHECK_EQ(state_, STATE_CHECKING_URL); 412 CHECK_EQ(state_, STATE_CHECKING_URL);
413 413
414 database_manager_->CancelCheck(this); 414 database_manager_->CancelCheck(this);
415 415
416 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE, 416 OnCheckBrowseUrlResult(url_being_checked_, safe_browsing::SB_THREAT_TYPE_SAFE,
417 safe_browsing::ThreatMetadata()); 417 safe_browsing::ThreatMetadata());
418 timed_out_urls_.push_back(url_being_checked_);
418 } 419 }
419 420
420 void SafeBrowsingResourceThrottle::ResumeRequest() { 421 void SafeBrowsingResourceThrottle::ResumeRequest() {
421 CHECK_EQ(state_, STATE_NONE); 422 CHECK_EQ(state_, STATE_NONE);
422 CHECK_NE(defer_state_, DEFERRED_NONE); 423 CHECK_NE(defer_state_, DEFERRED_NONE);
423 424
424 bool resume = true; 425 bool resume = true;
425 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) { 426 if (defer_state_ == DEFERRED_UNCHECKED_REDIRECT) {
426 // Save the redirect urls for possible malware detail reporting later. 427 // Save the redirect urls for possible malware detail reporting later.
427 redirect_urls_.push_back(unchecked_redirect_url_); 428 redirect_urls_.push_back(unchecked_redirect_url_);
428 if (!CheckUrl(unchecked_redirect_url_)) { 429 if (!CheckUrl(unchecked_redirect_url_)) {
429 // We're now waiting for the unchecked_redirect_url_. 430 // We're now waiting for the unchecked_redirect_url_.
430 defer_state_ = DEFERRED_REDIRECT; 431 defer_state_ = DEFERRED_REDIRECT;
431 resume = false; 432 resume = false;
432 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED, 433 BeginNetLogEvent(NetLogEventType::SAFE_BROWSING_DEFERRED,
433 unchecked_redirect_url_, "defer_reason", 434 unchecked_redirect_url_, "defer_reason",
434 "resumed_redirect"); 435 "resumed_redirect");
435 } 436 }
436 } 437 }
437 438
438 if (resume) { 439 if (resume) {
439 defer_state_ = DEFERRED_NONE; 440 defer_state_ = DEFERRED_NONE;
440 Resume(); 441 Resume();
441 } 442 }
442 } 443 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698