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

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 165008: Fix for an "update in progress" DCHECK (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/safe_browsing/protocol_manager.h" 5 #include "chrome/browser/safe_browsing/protocol_manager.h"
6 6
7 #include "base/file_version_info.h" 7 #include "base/file_version_info.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/base/base64.h" 21 #include "net/base/base64.h"
22 #include "net/base/escape.h" 22 #include "net/base/escape.h"
23 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
24 24
25 using base::Time; 25 using base::Time;
26 using base::TimeDelta; 26 using base::TimeDelta;
27 27
28 // Maximum time, in seconds, from start up before we must issue an update query. 28 // Maximum time, in seconds, from start up before we must issue an update query.
29 static const int kSbTimerStartIntervalSec = 5 * 60; 29 static const int kSbTimerStartIntervalSec = 5 * 60;
30 30
31 // The maximum time, in seconds, to wait for a response to an update request.
32 static const int kSbMaxUpdateWaitSec = 10;
33
31 // Update URL for querying about the latest set of chunk updates. 34 // Update URL for querying about the latest set of chunk updates.
32 static const char* const kSbUpdateUrl = 35 static const char* const kSbUpdateUrl =
33 "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=%s" 36 "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=%s"
34 "&appver=%s&pver=2.2"; 37 "&appver=%s&pver=2.2";
35 38
36 // GetHash request URL for retrieving full hashes. 39 // GetHash request URL for retrieving full hashes.
37 static const char* const kSbGetHashUrl = 40 static const char* const kSbGetHashUrl =
38 "http://safebrowsing.clients.google.com/safebrowsing/gethash?client=%s" 41 "http://safebrowsing.clients.google.com/safebrowsing/gethash?client=%s"
39 "&appver=%s&pver=2.2"; 42 "&appver=%s&pver=2.2";
40 43
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 231 }
229 232
230 // Call back the SafeBrowsingService with full_hashes, even if there was a 233 // Call back the SafeBrowsingService with full_hashes, even if there was a
231 // parse error or an error response code (in which case full_hashes will be 234 // parse error or an error response code (in which case full_hashes will be
232 // empty). We can't block the user regardless of the error status. 235 // empty). We can't block the user regardless of the error status.
233 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); 236 sb_service_->HandleGetHashResults(check, full_hashes, can_cache);
234 237
235 hash_requests_.erase(it); 238 hash_requests_.erase(it);
236 } else { 239 } else {
237 // Update, chunk or key response. 240 // Update, chunk or key response.
238 DCHECK(source == request_.get());
239 fetcher.reset(request_.release()); 241 fetcher.reset(request_.release());
240 242
243 if (request_type_ == UPDATE_REQUEST) {
244 if (!fetcher.get()) {
245 // We've timed out waiting for an update response, so we've cancelled
246 // the update request and scheduled a new one. Ignore this response.
247 return;
248 }
249
250 // Cancel the update response timeout now that we have the response.
251 update_timer_.Stop();
252 }
253
241 if (response_code == 200) { 254 if (response_code == 200) {
242 // We have data from the SafeBrowsing service. 255 // We have data from the SafeBrowsing service.
243 parsed_ok = HandleServiceResponse(source->url(), 256 parsed_ok = HandleServiceResponse(source->url(),
244 data.data(), 257 data.data(),
245 static_cast<int>(data.length())); 258 static_cast<int>(data.length()));
246 if (!parsed_ok) { 259 if (!parsed_ok) {
247 SB_DLOG(INFO) << "SafeBrowsing request for: " << source->url() 260 SB_DLOG(INFO) << "SafeBrowsing request for: " << source->url()
248 << "failed parse."; 261 << "failed parse.";
249 must_back_off = true; 262 must_back_off = true;
250 chunk_request_urls_.clear(); 263 chunk_request_urls_.clear();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 request_->set_request_context(Profile::GetDefaultRequestContext()); 530 request_->set_request_context(Profile::GetDefaultRequestContext());
518 request_->Start(); 531 request_->Start();
519 } 532 }
520 533
521 void SafeBrowsingProtocolManager::OnGetChunksComplete( 534 void SafeBrowsingProtocolManager::OnGetChunksComplete(
522 const std::vector<SBListChunkRanges>& lists, bool database_error) { 535 const std::vector<SBListChunkRanges>& lists, bool database_error) {
523 DCHECK(request_type_ == UPDATE_REQUEST); 536 DCHECK(request_type_ == UPDATE_REQUEST);
524 537
525 if (database_error) { 538 if (database_error) {
526 ScheduleNextUpdate(false); 539 ScheduleNextUpdate(false);
540 UpdateFinished(false);
527 return; 541 return;
528 } 542 }
529 543
530 const bool use_mac = !client_key_.empty(); 544 const bool use_mac = !client_key_.empty();
531 545
532 // Format our stored chunks: 546 // Format our stored chunks:
533 std::string list_data; 547 std::string list_data;
534 bool found_malware = false; 548 bool found_malware = false;
535 bool found_phishing = false; 549 bool found_phishing = false;
536 for (size_t i = 0; i < lists.size(); ++i) { 550 for (size_t i = 0; i < lists.size(); ++i) {
(...skipping 22 matching lines...) Expand all
559 url.append("&wrkey="); 573 url.append("&wrkey=");
560 url.append(wrapped_key_); 574 url.append(wrapped_key_);
561 } 575 }
562 576
563 GURL update_url(url); 577 GURL update_url(url);
564 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this)); 578 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this));
565 request_->set_load_flags(net::LOAD_DISABLE_CACHE); 579 request_->set_load_flags(net::LOAD_DISABLE_CACHE);
566 request_->set_request_context(Profile::GetDefaultRequestContext()); 580 request_->set_request_context(Profile::GetDefaultRequestContext());
567 request_->set_upload_data("text/plain", list_data); 581 request_->set_upload_data("text/plain", list_data);
568 request_->Start(); 582 request_->Start();
583
584 // Begin the update request timeout.
585 update_timer_.Start(TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), this,
586 &SafeBrowsingProtocolManager::UpdateResponseTimeout);
587 }
588
589 // If we haven't heard back from the server with an update response, this method
590 // will run. Close the current update session and schedule another update.
591 void SafeBrowsingProtocolManager::UpdateResponseTimeout() {
592 DCHECK(request_type_ == UPDATE_REQUEST);
593 request_.reset();
594 ScheduleNextUpdate(false);
595 UpdateFinished(false);
569 } 596 }
570 597
571 void SafeBrowsingProtocolManager::OnChunkInserted() { 598 void SafeBrowsingProtocolManager::OnChunkInserted() {
572 chunk_pending_to_write_ = false; 599 chunk_pending_to_write_ = false;
573 600
574 if (chunk_request_urls_.empty()) { 601 if (chunk_request_urls_.empty()) {
575 UMA_HISTOGRAM_LONG_TIMES("SB2.Update", Time::Now() - last_update_); 602 UMA_HISTOGRAM_LONG_TIMES("SB2.Update", Time::Now() - last_update_);
576 UpdateFinished(true); 603 UpdateFinished(true);
577 } else { 604 } else {
578 IssueChunkRequest(); 605 IssueChunkRequest();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) { 656 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) {
630 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_); 657 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_);
631 next_gethash_time_ = now + TimeDelta::FromSeconds(next); 658 next_gethash_time_ = now + TimeDelta::FromSeconds(next);
632 } 659 }
633 660
634 void SafeBrowsingProtocolManager::UpdateFinished(bool success) { 661 void SafeBrowsingProtocolManager::UpdateFinished(bool success) {
635 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_); 662 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_);
636 update_size_ = 0; 663 update_size_ = 0;
637 sb_service_->UpdateFinished(success); 664 sb_service_->UpdateFinished(success);
638 } 665 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698