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 #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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "chrome/browser/safe_browsing/protocol_parser.h" | 18 #include "chrome/browser/safe_browsing/protocol_parser.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
21 #include "chrome/common/env_vars.h" | 21 #include "chrome/common/env_vars.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "google_apis/google_api_keys.h" | |
24 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
25 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
26 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
27 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
28 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
29 | 28 |
30 using base::Time; | 29 using base::Time; |
31 using base::TimeDelta; | 30 using base::TimeDelta; |
32 using content::BrowserThread; | 31 using content::BrowserThread; |
33 | 32 |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 644 |
646 std::string SafeBrowsingProtocolManager::ComposeUrl( | 645 std::string SafeBrowsingProtocolManager::ComposeUrl( |
647 const std::string& prefix, const std::string& method, | 646 const std::string& prefix, const std::string& method, |
648 const std::string& client_name, const std::string& version, | 647 const std::string& client_name, const std::string& version, |
649 const std::string& additional_query) { | 648 const std::string& additional_query) { |
650 DCHECK(!prefix.empty() && !method.empty() && | 649 DCHECK(!prefix.empty() && !method.empty() && |
651 !client_name.empty() && !version.empty()); | 650 !client_name.empty() && !version.empty()); |
652 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=2.2", | 651 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=2.2", |
653 prefix.c_str(), method.c_str(), | 652 prefix.c_str(), method.c_str(), |
654 client_name.c_str(), version.c_str()); | 653 client_name.c_str(), version.c_str()); |
655 std::string api_key = google_apis::GetAPIKey(); | |
656 if (!api_key.empty()) { | |
657 base::StringAppendF(&url, "&key=%s", | |
658 net::EscapeQueryParamValue(api_key, true).c_str()); | |
659 } | |
660 if (!additional_query.empty()) { | 654 if (!additional_query.empty()) { |
661 DCHECK(url.find("?") != std::string::npos); | 655 DCHECK(url.find("?") != std::string::npos); |
662 url.append("&"); | 656 url.append("&"); |
663 url.append(additional_query); | 657 url.append(additional_query); |
664 } | 658 } |
665 return url; | 659 return url; |
666 } | 660 } |
667 | 661 |
668 GURL SafeBrowsingProtocolManager::UpdateUrl() const { | 662 GURL SafeBrowsingProtocolManager::UpdateUrl() const { |
669 return GURL(ComposeUrl(url_prefix_, "downloads", client_name_, version_, | 663 return GURL(ComposeUrl(url_prefix_, "downloads", client_name_, version_, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 net::EscapeQueryParamValue(referrer_url.spec(), true).c_str(), | 707 net::EscapeQueryParamValue(referrer_url.spec(), true).c_str(), |
714 is_subresource)); | 708 is_subresource)); |
715 } | 709 } |
716 | 710 |
717 GURL SafeBrowsingProtocolManager::MalwareDetailsUrl() const { | 711 GURL SafeBrowsingProtocolManager::MalwareDetailsUrl() const { |
718 std::string url = base::StringPrintf( | 712 std::string url = base::StringPrintf( |
719 "%s/clientreport/malware?client=%s&appver=%s&pver=1.0", | 713 "%s/clientreport/malware?client=%s&appver=%s&pver=1.0", |
720 url_prefix_.c_str(), | 714 url_prefix_.c_str(), |
721 client_name_.c_str(), | 715 client_name_.c_str(), |
722 version_.c_str()); | 716 version_.c_str()); |
723 std::string api_key = google_apis::GetAPIKey(); | |
724 if (!api_key.empty()) { | |
725 base::StringAppendF(&url, "&key=%s", | |
726 net::EscapeQueryParamValue(api_key, true).c_str()); | |
727 } | |
728 return GURL(url); | 717 return GURL(url); |
729 } | 718 } |
730 | 719 |
731 GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const { | 720 GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const { |
732 std::string next_url; | 721 std::string next_url; |
733 if (!StartsWithASCII(url, "http://", false) && | 722 if (!StartsWithASCII(url, "http://", false) && |
734 !StartsWithASCII(url, "https://", false)) { | 723 !StartsWithASCII(url, "https://", false)) { |
735 // Use https if we updated via https, otherwise http (useful for testing). | 724 // Use https if we updated via https, otherwise http (useful for testing). |
736 if (StartsWithASCII(url_prefix_, "https://", false)) | 725 if (StartsWithASCII(url_prefix_, "https://", false)) |
737 next_url.append("https://"); | 726 next_url.append("https://"); |
738 else | 727 else |
739 next_url.append("http://"); | 728 next_url.append("http://"); |
740 next_url.append(url); | 729 next_url.append(url); |
741 } else { | 730 } else { |
742 next_url = url; | 731 next_url = url; |
743 } | 732 } |
744 if (!additional_query_.empty()) { | 733 if (!additional_query_.empty()) { |
745 if (next_url.find("?") != std::string::npos) { | 734 if (next_url.find("?") != std::string::npos) { |
746 next_url.append("&"); | 735 next_url.append("&"); |
747 } else { | 736 } else { |
748 next_url.append("?"); | 737 next_url.append("?"); |
749 } | 738 } |
750 next_url.append(additional_query_); | 739 next_url.append(additional_query_); |
751 } | 740 } |
752 return GURL(next_url); | 741 return GURL(next_url); |
753 } | 742 } |
OLD | NEW |