Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Unified Diff: chrome/browser/safe_browsing/ping_manager.cc

Issue 2361963002: Adding NetLog support to SafeBrowsingPingManager. (Closed)
Patch Set: Base64 encoding the payloads. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ea91f571bf0e65f1f2c00df29dc715c53c9f30ee 100644
--- a/chrome/browser/safe_browsing/ping_manager.cc
+++ b/chrome/browser/safe_browsing/ping_manager.cc
@@ -6,19 +6,23 @@
#include <utility>
+#include "base/base64.h"
#include "base/logging.h"
#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 +36,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 +103,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 +120,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) {
@@ -100,10 +144,19 @@ void SafeBrowsingPingManager::ReportSafeBrowsingHit(
net::URLFetcher* report = report_ptr.get();
report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE);
report_ptr->SetRequestContext(request_context_getter_.get());
- if (!hit_report.post_data.empty())
+ std::string post_data_base64 = "";
vakh (use Gerrit instead) 2016/09/30 16:05:59 you may be able to leave out the explicit initiali
lpz 2016/10/04 18:48:32 Done.
+ if (!hit_report.post_data.empty()) {
report_ptr->SetUploadData("text/plain", hit_report.post_data);
- safebrowsing_reports_.insert(std::move(report_ptr));
+ base::Base64Encode(hit_report.post_data, &post_data_base64);
+ }
+
+ net_log_.BeginEvent(
+ net::NetLogEventType::SAFE_BROWSING_PING,
+ base::Bind(&NetLogPingStartCallback, net_log_,
+ report_ptr->GetOriginalURL(), post_data_base64));
+
report->Start();
+ safebrowsing_reports_.insert(std::move(report_ptr));
}
// Sends threat details for users who opt-in.
@@ -116,6 +169,14 @@ 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);
+
+ std::string report_base64 = "";
vakh (use Gerrit instead) 2016/09/30 16:05:59 same here
lpz 2016/10/04 18:48:32 Done.
+ base::Base64Encode(report, &report_base64);
+ net_log_.BeginEvent(
+ net::NetLogEventType::SAFE_BROWSING_PING,
+ base::Bind(&NetLogPingStartCallback, net_log_, fetcher->GetOriginalURL(),
+ report_base64));
+
fetcher->Start();
safebrowsing_reports_.insert(std::move(fetcher));
}

Powered by Google App Engine
This is Rietveld 408576698