| 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/safe_browsing/protocol_manager.h" | 5 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 21 #include "chrome/browser/safe_browsing/protocol_parser.h" | 21 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 22 #include "chrome/common/env_vars.h" | 22 #include "chrome/common/env_vars.h" |
| 23 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 23 #include "components/safe_browsing_db/util.h" | 24 #include "components/safe_browsing_db/util.h" |
| 24 #include "components/variations/variations_associated_data.h" | 25 #include "components/variations/variations_associated_data.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "google_apis/google_api_keys.h" | 27 #include "google_apis/google_api_keys.h" |
| 27 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
| 29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 30 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 31 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 32 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) { | 208 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) { |
| 208 RecordGetHashResult(is_download, GET_HASH_BACKOFF_ERROR); | 209 RecordGetHashResult(is_download, GET_HASH_BACKOFF_ERROR); |
| 209 std::vector<SBFullHashResult> full_hashes; | 210 std::vector<SBFullHashResult> full_hashes; |
| 210 callback.Run(full_hashes, base::TimeDelta()); | 211 callback.Run(full_hashes, base::TimeDelta()); |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 GURL gethash_url = GetHashUrl(is_extended_reporting); | 214 GURL gethash_url = GetHashUrl(is_extended_reporting); |
| 214 std::unique_ptr<net::URLFetcher> fetcher_ptr = net::URLFetcher::Create( | 215 std::unique_ptr<net::URLFetcher> fetcher_ptr = net::URLFetcher::Create( |
| 215 url_fetcher_id_++, gethash_url, net::URLFetcher::POST, this); | 216 url_fetcher_id_++, gethash_url, net::URLFetcher::POST, this); |
| 216 net::URLFetcher* fetcher = fetcher_ptr.get(); | 217 net::URLFetcher* fetcher = fetcher_ptr.get(); |
| 218 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 219 fetcher, data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 217 hash_requests_[fetcher] = {std::move(fetcher_ptr), | 220 hash_requests_[fetcher] = {std::move(fetcher_ptr), |
| 218 FullHashDetails(callback, is_download)}; | 221 FullHashDetails(callback, is_download)}; |
| 219 | 222 |
| 220 const std::string get_hash = FormatGetHash(prefixes); | 223 const std::string get_hash = FormatGetHash(prefixes); |
| 221 | 224 |
| 222 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 225 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 223 fetcher->SetRequestContext(request_context_getter_.get()); | 226 fetcher->SetRequestContext(request_context_getter_.get()); |
| 224 fetcher->SetUploadData("text/plain", get_hash); | 227 fetcher->SetUploadData("text/plain", get_hash); |
| 225 fetcher->Start(); | 228 fetcher->Start(); |
| 226 } | 229 } |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 DCHECK(backup_update_reason >= 0 && | 576 DCHECK(backup_update_reason >= 0 && |
| 574 backup_update_reason < BACKUP_UPDATE_REASON_MAX); | 577 backup_update_reason < BACKUP_UPDATE_REASON_MAX); |
| 575 if (backup_url_prefixes_[backup_update_reason].empty()) | 578 if (backup_url_prefixes_[backup_update_reason].empty()) |
| 576 return false; | 579 return false; |
| 577 request_type_ = BACKUP_UPDATE_REQUEST; | 580 request_type_ = BACKUP_UPDATE_REQUEST; |
| 578 backup_update_reason_ = backup_update_reason; | 581 backup_update_reason_ = backup_update_reason; |
| 579 | 582 |
| 580 GURL backup_update_url = BackupUpdateUrl(backup_update_reason); | 583 GURL backup_update_url = BackupUpdateUrl(backup_update_reason); |
| 581 request_ = net::URLFetcher::Create(url_fetcher_id_++, backup_update_url, | 584 request_ = net::URLFetcher::Create(url_fetcher_id_++, backup_update_url, |
| 582 net::URLFetcher::POST, this); | 585 net::URLFetcher::POST, this); |
| 586 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 587 request_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 583 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 588 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 584 request_->SetRequestContext(request_context_getter_.get()); | 589 request_->SetRequestContext(request_context_getter_.get()); |
| 585 request_->SetUploadData("text/plain", update_list_data_); | 590 request_->SetUploadData("text/plain", update_list_data_); |
| 586 request_->Start(); | 591 request_->Start(); |
| 587 | 592 |
| 588 // Begin the update request timeout. | 593 // Begin the update request timeout. |
| 589 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), | 594 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), |
| 590 this, | 595 this, |
| 591 &SafeBrowsingProtocolManager::UpdateResponseTimeout); | 596 &SafeBrowsingProtocolManager::UpdateResponseTimeout); |
| 592 | 597 |
| 593 return true; | 598 return true; |
| 594 } | 599 } |
| 595 | 600 |
| 596 void SafeBrowsingProtocolManager::IssueChunkRequest() { | 601 void SafeBrowsingProtocolManager::IssueChunkRequest() { |
| 597 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 602 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 598 // We are only allowed to have one request outstanding at any time. Also, | 603 // We are only allowed to have one request outstanding at any time. Also, |
| 599 // don't get the next url until the previous one has been written to disk so | 604 // don't get the next url until the previous one has been written to disk so |
| 600 // that we don't use too much memory. | 605 // that we don't use too much memory. |
| 601 if (request_.get() || chunk_request_urls_.empty() || chunk_pending_to_write_) | 606 if (request_.get() || chunk_request_urls_.empty() || chunk_pending_to_write_) |
| 602 return; | 607 return; |
| 603 | 608 |
| 604 ChunkUrl next_chunk = chunk_request_urls_.front(); | 609 ChunkUrl next_chunk = chunk_request_urls_.front(); |
| 605 DCHECK(!next_chunk.url.empty()); | 610 DCHECK(!next_chunk.url.empty()); |
| 606 GURL chunk_url = NextChunkUrl(next_chunk.url); | 611 GURL chunk_url = NextChunkUrl(next_chunk.url); |
| 607 request_type_ = CHUNK_REQUEST; | 612 request_type_ = CHUNK_REQUEST; |
| 608 request_ = net::URLFetcher::Create(url_fetcher_id_++, chunk_url, | 613 request_ = net::URLFetcher::Create(url_fetcher_id_++, chunk_url, |
| 609 net::URLFetcher::GET, this); | 614 net::URLFetcher::GET, this); |
| 615 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 616 request_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 610 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 617 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 611 request_->SetRequestContext(request_context_getter_.get()); | 618 request_->SetRequestContext(request_context_getter_.get()); |
| 612 chunk_request_start_ = base::Time::Now(); | 619 chunk_request_start_ = base::Time::Now(); |
| 613 request_->Start(); | 620 request_->Start(); |
| 614 } | 621 } |
| 615 | 622 |
| 616 void SafeBrowsingProtocolManager::OnGetChunksComplete( | 623 void SafeBrowsingProtocolManager::OnGetChunksComplete( |
| 617 const std::vector<SBListChunkRanges>& lists, | 624 const std::vector<SBListChunkRanges>& lists, |
| 618 bool database_error, | 625 bool database_error, |
| 619 bool is_extended_reporting) { | 626 bool is_extended_reporting) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 } | 658 } |
| 652 | 659 |
| 653 // Large requests are (probably) a sign of database corruption. | 660 // Large requests are (probably) a sign of database corruption. |
| 654 // Record stats to inform decisions about whether to automate | 661 // Record stats to inform decisions about whether to automate |
| 655 // deletion of such databases. http://crbug.com/120219 | 662 // deletion of such databases. http://crbug.com/120219 |
| 656 UMA_HISTOGRAM_COUNTS("SB2.UpdateRequestSize", update_list_data_.size()); | 663 UMA_HISTOGRAM_COUNTS("SB2.UpdateRequestSize", update_list_data_.size()); |
| 657 | 664 |
| 658 GURL update_url = UpdateUrl(is_extended_reporting); | 665 GURL update_url = UpdateUrl(is_extended_reporting); |
| 659 request_ = net::URLFetcher::Create(url_fetcher_id_++, update_url, | 666 request_ = net::URLFetcher::Create(url_fetcher_id_++, update_url, |
| 660 net::URLFetcher::POST, this); | 667 net::URLFetcher::POST, this); |
| 668 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 669 request_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 661 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 670 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 662 request_->SetRequestContext(request_context_getter_.get()); | 671 request_->SetRequestContext(request_context_getter_.get()); |
| 663 request_->SetUploadData("text/plain", update_list_data_); | 672 request_->SetUploadData("text/plain", update_list_data_); |
| 664 request_->Start(); | 673 request_->Start(); |
| 665 | 674 |
| 666 // Begin the update request timeout. | 675 // Begin the update request timeout. |
| 667 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), | 676 timeout_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kSbMaxUpdateWaitSec), |
| 668 this, | 677 this, |
| 669 &SafeBrowsingProtocolManager::UpdateResponseTimeout); | 678 &SafeBrowsingProtocolManager::UpdateResponseTimeout); |
| 670 } | 679 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 : callback(callback), is_download(is_download) {} | 797 : callback(callback), is_download(is_download) {} |
| 789 | 798 |
| 790 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( | 799 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( |
| 791 const FullHashDetails& other) = default; | 800 const FullHashDetails& other) = default; |
| 792 | 801 |
| 793 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} | 802 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} |
| 794 | 803 |
| 795 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} | 804 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} |
| 796 | 805 |
| 797 } // namespace safe_browsing | 806 } // namespace safe_browsing |
| OLD | NEW |