Chromium Code Reviews| 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/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/safe_browsing/permission_reporter.h" | 14 #include "chrome/browser/safe_browsing/permission_reporter.h" |
| 15 #include "components/certificate_reporting/error_reporter.h" | 15 #include "components/certificate_reporting/error_reporter.h" |
| 16 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "google_apis/google_api_keys.h" | 18 #include "google_apis/google_api_keys.h" |
| 18 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
| 19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 20 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
| 21 #include "net/url_request/report_sender.h" | 22 #include "net/url_request/report_sender.h" |
| 22 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // Sends a SafeBrowsing "hit" report. | 94 // Sends a SafeBrowsing "hit" report. |
| 94 void SafeBrowsingPingManager::ReportSafeBrowsingHit( | 95 void SafeBrowsingPingManager::ReportSafeBrowsingHit( |
| 95 const safe_browsing::HitReport& hit_report) { | 96 const safe_browsing::HitReport& hit_report) { |
| 96 GURL report_url = SafeBrowsingHitUrl(hit_report); | 97 GURL report_url = SafeBrowsingHitUrl(hit_report); |
| 97 net::URLFetcher* report = | 98 net::URLFetcher* report = |
| 98 net::URLFetcher::Create(report_url, hit_report.post_data.empty() | 99 net::URLFetcher::Create(report_url, hit_report.post_data.empty() |
| 99 ? net::URLFetcher::GET | 100 ? net::URLFetcher::GET |
| 100 : net::URLFetcher::POST, | 101 : net::URLFetcher::POST, |
| 101 this) | 102 this) |
| 102 .release(); | 103 .release(); |
| 104 data_use_measurement::DataUseUserData::AttachToFetcher( | |
| 105 report, data_use_measurement::DataUseUserData::SAFE_BROWSING); | |
| 103 report->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 106 report->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 104 report->SetRequestContext(request_context_getter_.get()); | 107 report->SetRequestContext(request_context_getter_.get()); |
| 105 if (!hit_report.post_data.empty()) | 108 if (!hit_report.post_data.empty()) |
| 106 report->SetUploadData("text/plain", hit_report.post_data); | 109 report->SetUploadData("text/plain", hit_report.post_data); |
| 107 safebrowsing_reports_.insert(report); | 110 safebrowsing_reports_.insert(report); |
| 108 report->Start(); | 111 report->Start(); |
| 109 } | 112 } |
| 110 | 113 |
| 111 // Sends threat details for users who opt-in. | 114 // Sends threat details for users who opt-in. |
| 112 void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { | 115 void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { |
| 113 GURL report_url = ThreatDetailsUrl(); | 116 GURL report_url = ThreatDetailsUrl(); |
| 114 net::URLFetcher* fetcher = | 117 net::URLFetcher* fetcher = |
| 115 net::URLFetcher::Create(report_url, net::URLFetcher::POST, this) | 118 net::URLFetcher::Create(report_url, net::URLFetcher::POST, this) |
| 116 .release(); | 119 .release(); |
| 120 data_use_measurement::DataUseUserData::AttachToFetcher( | |
| 121 fetcher, data_use_measurement::DataUseUserData::SAFE_BROWSING); | |
|
Jialiu Lin
2016/08/24 19:10:45
In addition to these two pings, download pings are
Raj
2016/08/24 20:00:01
Thanks. Added to that file as well.
| |
| 117 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 122 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 118 fetcher->SetRequestContext(request_context_getter_.get()); | 123 fetcher->SetRequestContext(request_context_getter_.get()); |
| 119 fetcher->SetUploadData("application/octet-stream", report); | 124 fetcher->SetUploadData("application/octet-stream", report); |
| 120 // Don't try too hard to send reports on failures. | 125 // Don't try too hard to send reports on failures. |
| 121 fetcher->SetAutomaticallyRetryOn5xx(false); | 126 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 122 fetcher->Start(); | 127 fetcher->Start(); |
| 123 safebrowsing_reports_.insert(fetcher); | 128 safebrowsing_reports_.insert(fetcher); |
| 124 } | 129 } |
| 125 | 130 |
| 126 void SafeBrowsingPingManager::ReportInvalidCertificateChain( | 131 void SafeBrowsingPingManager::ReportInvalidCertificateChain( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 version_.c_str()); | 240 version_.c_str()); |
| 236 std::string api_key = google_apis::GetAPIKey(); | 241 std::string api_key = google_apis::GetAPIKey(); |
| 237 if (!api_key.empty()) { | 242 if (!api_key.empty()) { |
| 238 base::StringAppendF(&url, "&key=%s", | 243 base::StringAppendF(&url, "&key=%s", |
| 239 net::EscapeQueryParamValue(api_key, true).c_str()); | 244 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 240 } | 245 } |
| 241 return GURL(url); | 246 return GURL(url); |
| 242 } | 247 } |
| 243 | 248 |
| 244 } // namespace safe_browsing | 249 } // namespace safe_browsing |
| OLD | NEW |