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

Unified Diff: content/browser/net/reporting_service_proxy.cc

Issue 2881593002: Reporting: Plumb into RenderFrame via Mojo (Closed)
Patch Set: rebase Created 3 years, 7 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 | « content/browser/net/reporting_service_proxy.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/net/reporting_service_proxy.cc
diff --git a/content/browser/net/reporting_service_proxy.cc b/content/browser/net/reporting_service_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..20c9b3c3a6aef70872d8b0add013cda642dab30f
--- /dev/null
+++ b/content/browser/net/reporting_service_proxy.cc
@@ -0,0 +1,89 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/net/reporting_service_proxy.h"
+
+#include <memory>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/values.h"
+#include "content/common/net/reporting.mojom.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/storage_partition.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "net/reporting/reporting_service.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
+
+namespace content {
+
+namespace {
+
+void QueueReportOnIOThread(
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter,
+ const GURL& url,
+ const std::string& group,
+ const std::string& type,
+ std::unique_ptr<const base::Value> body) {
+ net::URLRequestContext* request_context =
+ request_context_getter->GetURLRequestContext();
+ if (!request_context)
+ return;
+
+ net::ReportingService* reporting_service =
+ request_context->reporting_service();
+ if (!reporting_service)
+ return;
+
+ // TODO: Get rid of this copy.
shivanisha 2017/05/17 18:58:28 nit: TODO(username)
Julia Tuttle 2017/05/18 19:34:25 Done.
+ reporting_service->QueueReport(url, group, type, body->CreateDeepCopy());
+}
+
+class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy {
+ public:
+ ReportingServiceProxyImpl(
+ mojom::ReportingServiceProxyRequest request,
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter)
+ : binding_(this, std::move(request)),
+ request_context_getter_(request_context_getter) {}
+
+ // mojom::ReportingServiceProxy:
+ void QueueReport(const GURL& url,
+ const std::string& group,
+ const std::string& type,
+ std::unique_ptr<base::Value> body) override {
+ // TODO: Get rid of this intermediate step.
+ const base::Value* raw_const_body = body.release();
+
+ request_context_getter_->GetNetworkTaskRunner()->PostTask(
+ FROM_HERE,
+ base::BindOnce(&QueueReportOnIOThread, request_context_getter_, url,
+ group, type, base::WrapUnique(raw_const_body)));
+ }
+
+ private:
+ mojo::Binding<mojom::ReportingServiceProxy> binding_;
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
+};
+
+} // namespace
+
+// static
+void CreateReportingServiceProxy(
+ scoped_refptr<SiteInstance> site_instance,
+ const service_manager::BindSourceInfo& source_info,
+ mojom::ReportingServiceProxyRequest request) {
+ BrowserContext* browser_context = site_instance->GetBrowserContext();
+ StoragePartition* storage_partition =
+ BrowserContext::GetStoragePartition(browser_context, site_instance.get());
+ // TODO: Make sure making our own scoped_refptr is okay.
shivanisha 2017/05/17 18:58:28 nit: TODO(username)
Julia Tuttle 2017/05/18 19:34:25 Done.
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter(
+ storage_partition->GetURLRequestContext());
+ new ReportingServiceProxyImpl(std::move(request),
+ std::move(request_context_getter));
+}
+}
« no previous file with comments | « content/browser/net/reporting_service_proxy.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698