OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NDEBUG | 7 #ifndef NDEBUG |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #endif | 9 #endif |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // Reschedule with the new update. | 495 // Reschedule with the new update. |
496 const int next_update = GetNextUpdateTime(back_off); | 496 const int next_update = GetNextUpdateTime(back_off); |
497 ForceScheduleNextUpdate(next_update); | 497 ForceScheduleNextUpdate(next_update); |
498 } | 498 } |
499 | 499 |
500 void SafeBrowsingProtocolManager::ForceScheduleNextUpdate( | 500 void SafeBrowsingProtocolManager::ForceScheduleNextUpdate( |
501 const int next_update_msec) { | 501 const int next_update_msec) { |
502 DCHECK_GE(next_update_msec, 0); | 502 DCHECK_GE(next_update_msec, 0); |
503 // Unschedule any current timer. | 503 // Unschedule any current timer. |
504 update_timer_.Stop(); | 504 update_timer_.Stop(); |
505 update_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(next_update_msec), | 505 update_timer_.Start(TimeDelta::FromMilliseconds(next_update_msec), this, |
506 this, &SafeBrowsingProtocolManager::GetNextUpdate); | 506 &SafeBrowsingProtocolManager::GetNextUpdate); |
507 } | 507 } |
508 | 508 |
509 // According to section 5 of the SafeBrowsing protocol specification, we must | 509 // According to section 5 of the SafeBrowsing protocol specification, we must |
510 // back off after a certain number of errors. We only change 'next_update_sec_' | 510 // back off after a certain number of errors. We only change 'next_update_sec_' |
511 // when we receive a response from the SafeBrowsing service. | 511 // when we receive a response from the SafeBrowsing service. |
512 int SafeBrowsingProtocolManager::GetNextUpdateTime(bool back_off) { | 512 int SafeBrowsingProtocolManager::GetNextUpdateTime(bool back_off) { |
513 int next = next_update_sec_; | 513 int next = next_update_sec_; |
514 if (back_off) { | 514 if (back_off) { |
515 next = GetNextBackOffTime(&update_error_count_, &update_back_off_mult_); | 515 next = GetNextBackOffTime(&update_error_count_, &update_back_off_mult_); |
516 } else { | 516 } else { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 SBListChunkRanges(safe_browsing_util::kMalwareList), use_mac)); | 613 SBListChunkRanges(safe_browsing_util::kMalwareList), use_mac)); |
614 | 614 |
615 GURL update_url = UpdateUrl(use_mac); | 615 GURL update_url = UpdateUrl(use_mac); |
616 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this)); | 616 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this)); |
617 request_->set_load_flags(net::LOAD_DISABLE_CACHE); | 617 request_->set_load_flags(net::LOAD_DISABLE_CACHE); |
618 request_->set_request_context(request_context_getter_); | 618 request_->set_request_context(request_context_getter_); |
619 request_->set_upload_data("text/plain", list_data); | 619 request_->set_upload_data("text/plain", list_data); |
620 request_->Start(); | 620 request_->Start(); |
621 | 621 |
622 // Begin the update request timeout. | 622 // Begin the update request timeout. |
623 update_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), | 623 update_timer_.Start(TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), this, |
624 this, | |
625 &SafeBrowsingProtocolManager::UpdateResponseTimeout); | 624 &SafeBrowsingProtocolManager::UpdateResponseTimeout); |
626 } | 625 } |
627 | 626 |
628 // If we haven't heard back from the server with an update response, this method | 627 // If we haven't heard back from the server with an update response, this method |
629 // will run. Close the current update session and schedule another update. | 628 // will run. Close the current update session and schedule another update. |
630 void SafeBrowsingProtocolManager::UpdateResponseTimeout() { | 629 void SafeBrowsingProtocolManager::UpdateResponseTimeout() { |
631 DCHECK_EQ(request_type_, UPDATE_REQUEST); | 630 DCHECK_EQ(request_type_, UPDATE_REQUEST); |
632 request_.reset(); | 631 request_.reset(); |
633 UpdateFinished(false); | 632 UpdateFinished(false); |
634 ScheduleNextUpdate(false); | 633 ScheduleNextUpdate(false); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 if (!additional_query_.empty()) { | 824 if (!additional_query_.empty()) { |
826 if (next_url.find("?") != std::string::npos) { | 825 if (next_url.find("?") != std::string::npos) { |
827 next_url.append("&"); | 826 next_url.append("&"); |
828 } else { | 827 } else { |
829 next_url.append("?"); | 828 next_url.append("?"); |
830 } | 829 } |
831 next_url.append(additional_query_); | 830 next_url.append(additional_query_); |
832 } | 831 } |
833 return GURL(next_url); | 832 return GURL(next_url); |
834 } | 833 } |
OLD | NEW |