Chromium Code Reviews| Index: chrome/browser/safe_browsing/ping_manager.cc |
| diff --git a/chrome/browser/safe_browsing/ping_manager.cc b/chrome/browser/safe_browsing/ping_manager.cc |
| index 623a988f7388b29ea5575d275b480e804be75804..6c12f22151178fca3c6efc5f62edb3dee8d2389a 100644 |
| --- a/chrome/browser/safe_browsing/ping_manager.cc |
| +++ b/chrome/browser/safe_browsing/ping_manager.cc |
| @@ -10,15 +10,18 @@ |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/values.h" |
| #include "chrome/browser/safe_browsing/permission_reporter.h" |
| #include "components/certificate_reporting/error_reporter.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "google_apis/google_api_keys.h" |
| #include "net/base/escape.h" |
| #include "net/base/load_flags.h" |
| +#include "net/log/net_log_source_type.h" |
| #include "net/ssl/ssl_info.h" |
| #include "net/url_request/report_sender.h" |
| #include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "net/url_request/url_request_status.h" |
| #include "url/gurl.h" |
| @@ -32,6 +35,38 @@ namespace { |
| const char kExtendedReportingUploadUrlInsecure[] = |
| "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| "chrome-certs"; |
| + |
| +// Returns a dictionary with "url"=|url-spec| and "data"=|payload| for |
| +// netlogging the start phase of a ping. |
| +std::unique_ptr<base::Value> NetLogPingStartCallback( |
| + const net::NetLogWithSource& net_log, |
| + const GURL& url, |
| + const std::string& payload, |
| + net::NetLogCaptureMode) { |
| + std::unique_ptr<base::DictionaryValue> event_params( |
| + new base::DictionaryValue()); |
| + event_params->SetString("url", url.spec()); |
| + event_params->SetString("payload", payload); |
| + net_log.source().AddToEventParameters(event_params.get()); |
| + return std::move(event_params); |
| +} |
| + |
| +// Returns a dictionary with "url"=|url-spec|, "status"=|status| and |
| +// "error"=|error| for netlogging the end phase of a ping. |
| +std::unique_ptr<base::Value> NetLogPingEndCallback( |
| + const net::NetLogWithSource& net_log, |
| + const GURL& url, |
| + const net::URLRequestStatus& status, |
| + net::NetLogCaptureMode) { |
| + std::unique_ptr<base::DictionaryValue> event_params( |
| + new base::DictionaryValue()); |
| + event_params->SetString("url", url.spec()); |
| + event_params->SetInteger("status", status.status()); |
| + event_params->SetInteger("error", status.error()); |
| + net_log.source().AddToEventParameters(event_params.get()); |
| + return std::move(event_params); |
| +} |
| + |
| } // namespace |
| namespace safe_browsing { |
| @@ -67,6 +102,10 @@ SafeBrowsingPingManager::SafeBrowsingPingManager( |
| permission_reporter_.reset( |
| new PermissionReporter(request_context_getter->GetURLRequestContext())); |
| + |
| + net_log_ = net::NetLogWithSource::Make( |
| + request_context_getter->GetURLRequestContext()->net_log(), |
| + net::NetLogSourceType::SAFE_BROWSING); |
| } |
| version_ = SafeBrowsingProtocolManagerHelper::Version(); |
| @@ -80,6 +119,10 @@ SafeBrowsingPingManager::~SafeBrowsingPingManager() { |
| // All SafeBrowsing request responses are handled here. |
| void SafeBrowsingPingManager::OnURLFetchComplete( |
| const net::URLFetcher* source) { |
| + net_log_.EndEvent( |
| + net::NetLogEventType::SAFE_BROWSING_PING, |
| + base::Bind(&NetLogPingEndCallback, net_log_, source->GetOriginalURL(), |
| + source->GetStatus())); |
| auto it = |
| std::find_if(safebrowsing_reports_.begin(), safebrowsing_reports_.end(), |
| [source](const std::unique_ptr<net::URLFetcher>& ptr) { |
| @@ -102,8 +145,14 @@ void SafeBrowsingPingManager::ReportSafeBrowsingHit( |
| report_ptr->SetRequestContext(request_context_getter_.get()); |
| if (!hit_report.post_data.empty()) |
| report_ptr->SetUploadData("text/plain", hit_report.post_data); |
| - safebrowsing_reports_.insert(std::move(report_ptr)); |
| + |
| + net_log_.BeginEvent( |
| + net::NetLogEventType::SAFE_BROWSING_PING, |
| + base::Bind(&NetLogPingStartCallback, net_log_, |
| + report_ptr->GetOriginalURL(), hit_report.post_data)); |
|
Nathan Parker
2016/09/23 18:43:09
Is the post data already base64 encoded?
It'd be
lpz
2016/09/26 19:55:39
Good call, encoded both payloads.
|
| + |
| report->Start(); |
| + safebrowsing_reports_.insert(std::move(report_ptr)); |
| } |
| // Sends threat details for users who opt-in. |
| @@ -116,6 +165,12 @@ void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { |
| fetcher->SetUploadData("application/octet-stream", report); |
| // Don't try too hard to send reports on failures. |
| fetcher->SetAutomaticallyRetryOn5xx(false); |
| + |
| + net_log_.BeginEvent( |
| + net::NetLogEventType::SAFE_BROWSING_PING, |
| + base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(), |
| + report)); |
| + |
| fetcher->Start(); |
| safebrowsing_reports_.insert(std::move(fetcher)); |
| } |