| 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..31f9245ad88138aa96135e112ceef5fa5095e369
|
| --- /dev/null
|
| +++ b/content/browser/net/reporting_service_proxy.cc
|
| @@ -0,0 +1,88 @@
|
| +// 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/strong_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(juliatuttle): Get rid of this copy.
|
| + reporting_service->QueueReport(url, group, type, body->CreateDeepCopy());
|
| +}
|
| +
|
| +class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy {
|
| + public:
|
| + ReportingServiceProxyImpl(
|
| + scoped_refptr<net::URLRequestContextGetter> request_context_getter)
|
| + : request_context_getter_(std::move(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(juliatuttle): 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:
|
| + scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +void CreateReportingServiceProxy(
|
| + 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);
|
| + // TODO(juliatuttle): Make sure making our own scoped_refptr is okay.
|
| + scoped_refptr<net::URLRequestContextGetter> request_context_getter(
|
| + storage_partition->GetURLRequestContext());
|
| + mojo::MakeStrongBinding(
|
| + base::MakeUnique<ReportingServiceProxyImpl>(request_context_getter),
|
| + std::move(request));
|
| +}
|
| +
|
| +} // namespace content
|
|
|