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

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

Issue 2361963002: Adding NetLog support to SafeBrowsingPingManager. (Closed)
Patch Set: Segfault fix: call netlog before std::moving the fetcher 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
« no previous file with comments | « chrome/browser/safe_browsing/ping_manager.h ('k') | net/log/net_log_event_type_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..00972aa78bde2d0b59e9b55f2fbb53a5180b6a73 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";
+
+// Return a dictionary with "url"=|url-spec| and "data"=|payload| for
sadrul 2016/09/23 16:38:21 *Returns
lpz 2016/09/23 18:11:58 Done.
+// 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);
+}
+
+// Return a dictionary with "url"=|url-spec|, "status"=|status| and
sadrul 2016/09/23 16:38:21 ditto
lpz 2016/09/23 18:11:58 Done.
+// "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();
@@ -87,6 +126,11 @@ void SafeBrowsingPingManager::OnURLFetchComplete(
});
DCHECK(it != safebrowsing_reports_.end());
safebrowsing_reports_.erase(it);
+
+ net_log_.EndEvent(
+ net::NetLogEventType::SAFE_BROWSING_PING,
+ base::Bind(&NetLogPingEndCallback, net_log_, source->GetURL(),
+ source->GetStatus()));
}
// Sends a SafeBrowsing "hit" report.
@@ -102,8 +146,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->GetURL(),
+ hit_report.post_data));
+
report->Start();
+ safebrowsing_reports_.insert(std::move(report_ptr));
}
// Sends threat details for users who opt-in.
@@ -116,8 +166,15 @@ 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->GetURL(),
+ report));
sadrul 2016/09/23 16:38:21 Are these callbacks always expected to run synchro
lpz 2016/09/23 18:11:58 Yes the docs suggest that this is guaranteed - the
+
fetcher->Start();
safebrowsing_reports_.insert(std::move(fetcher));
+
}
void SafeBrowsingPingManager::ReportInvalidCertificateChain(
« no previous file with comments | « chrome/browser/safe_browsing/ping_manager.h ('k') | net/log/net_log_event_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698