| 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/ping_manager.h" | 5 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/safe_browsing/permission_reporter.h" | 13 #include "chrome/browser/safe_browsing/permission_reporter.h" |
| 14 #include "components/certificate_reporting/error_reporter.h" | 14 #include "components/certificate_reporting/error_reporter.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
| 17 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 19 #include "net/ssl/ssl_info.h" | 20 #include "net/ssl/ssl_info.h" |
| 20 #include "net/url_request/report_sender.h" | 21 #include "net/url_request/report_sender.h" |
| 21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 92 |
| 92 // Sends a SafeBrowsing "hit" report. | 93 // Sends a SafeBrowsing "hit" report. |
| 93 void SafeBrowsingPingManager::ReportSafeBrowsingHit( | 94 void SafeBrowsingPingManager::ReportSafeBrowsingHit( |
| 94 const safe_browsing::HitReport& hit_report) { | 95 const safe_browsing::HitReport& hit_report) { |
| 95 GURL report_url = SafeBrowsingHitUrl(hit_report); | 96 GURL report_url = SafeBrowsingHitUrl(hit_report); |
| 96 std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create( | 97 std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create( |
| 97 report_url, hit_report.post_data.empty() ? net::URLFetcher::GET | 98 report_url, hit_report.post_data.empty() ? net::URLFetcher::GET |
| 98 : net::URLFetcher::POST, | 99 : net::URLFetcher::POST, |
| 99 this); | 100 this); |
| 100 net::URLFetcher* report = report_ptr.get(); | 101 net::URLFetcher* report = report_ptr.get(); |
| 102 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 103 report, data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 101 report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 104 report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 102 report_ptr->SetRequestContext(request_context_getter_.get()); | 105 report_ptr->SetRequestContext(request_context_getter_.get()); |
| 103 if (!hit_report.post_data.empty()) | 106 if (!hit_report.post_data.empty()) |
| 104 report_ptr->SetUploadData("text/plain", hit_report.post_data); | 107 report_ptr->SetUploadData("text/plain", hit_report.post_data); |
| 105 safebrowsing_reports_.insert(std::move(report_ptr)); | 108 safebrowsing_reports_.insert(std::move(report_ptr)); |
| 106 report->Start(); | 109 report->Start(); |
| 107 } | 110 } |
| 108 | 111 |
| 109 // Sends threat details for users who opt-in. | 112 // Sends threat details for users who opt-in. |
| 110 void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { | 113 void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { |
| 111 GURL report_url = ThreatDetailsUrl(); | 114 GURL report_url = ThreatDetailsUrl(); |
| 112 std::unique_ptr<net::URLFetcher> fetcher = | 115 std::unique_ptr<net::URLFetcher> fetcher = |
| 113 net::URLFetcher::Create(report_url, net::URLFetcher::POST, this); | 116 net::URLFetcher::Create(report_url, net::URLFetcher::POST, this); |
| 117 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 118 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 114 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 119 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 115 fetcher->SetRequestContext(request_context_getter_.get()); | 120 fetcher->SetRequestContext(request_context_getter_.get()); |
| 116 fetcher->SetUploadData("application/octet-stream", report); | 121 fetcher->SetUploadData("application/octet-stream", report); |
| 117 // Don't try too hard to send reports on failures. | 122 // Don't try too hard to send reports on failures. |
| 118 fetcher->SetAutomaticallyRetryOn5xx(false); | 123 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 119 fetcher->Start(); | 124 fetcher->Start(); |
| 120 safebrowsing_reports_.insert(std::move(fetcher)); | 125 safebrowsing_reports_.insert(std::move(fetcher)); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void SafeBrowsingPingManager::ReportInvalidCertificateChain( | 128 void SafeBrowsingPingManager::ReportInvalidCertificateChain( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 version_.c_str()); | 232 version_.c_str()); |
| 228 std::string api_key = google_apis::GetAPIKey(); | 233 std::string api_key = google_apis::GetAPIKey(); |
| 229 if (!api_key.empty()) { | 234 if (!api_key.empty()) { |
| 230 base::StringAppendF(&url, "&key=%s", | 235 base::StringAppendF(&url, "&key=%s", |
| 231 net::EscapeQueryParamValue(api_key, true).c_str()); | 236 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 232 } | 237 } |
| 233 return GURL(url); | 238 return GURL(url); |
| 234 } | 239 } |
| 235 | 240 |
| 236 } // namespace safe_browsing | 241 } // namespace safe_browsing |
| OLD | NEW |