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

Side by Side Diff: content/browser/net/reporting_service_proxy.cc

Issue 2881593002: Reporting: Plumb into RenderFrame via Mojo (Closed)
Patch Set: Fix #includes and DEPS. Created 3 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/net/reporting_service_proxy.h"
6
7 #include <memory>
8 #include <string>
9 #include <utility>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/values.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "mojo/public/cpp/bindings/strong_binding.h"
17 #include "net/reporting/reporting_service.h"
18 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h"
20 #include "third_party/WebKit/public/platform/reporting.mojom.h"
21 #include "url/gurl.h"
22
23 namespace content {
24
25 namespace {
26
27 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy {
28 public:
29 ReportingServiceProxyImpl(
30 scoped_refptr<net::URLRequestContextGetter> request_context_getter)
31 : request_context_getter_(std::move(request_context_getter)) {}
32
33 // mojom::ReportingServiceProxy:
34 void QueueReport(const GURL& url,
35 const std::string& group,
36 const std::string& type,
37 std::unique_ptr<base::Value> body) override {
38 std::unique_ptr<const base::Value> const_body =
39 base::WrapUnique(body.release());
40
41 net::URLRequestContext* request_context =
42 request_context_getter_->GetURLRequestContext();
43 if (!request_context)
44 return;
45
46 net::ReportingService* reporting_service =
47 request_context->reporting_service();
48 if (!reporting_service)
49 return;
50
51 reporting_service->QueueReport(url, group, type, std::move(const_body));
52 }
53
54 private:
55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
56 };
57
58 void CreateReportingServiceProxyOnNetworkTaskRunner(
59 mojom::ReportingServiceProxyRequest request,
60 scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
61 mojo::MakeStrongBinding(base::MakeUnique<ReportingServiceProxyImpl>(
62 std::move(request_context_getter)),
63 std::move(request));
64 }
65
66 } // namespace
67
68 // static
69 void CreateReportingServiceProxy(
70 StoragePartition* storage_partition,
71 const service_manager::BindSourceInfo& source_info,
72 mojom::ReportingServiceProxyRequest request) {
73 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
74 storage_partition->GetURLRequestContext());
75 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner(
76 request_context_getter->GetNetworkTaskRunner());
77 network_task_runner->PostTask(
78 FROM_HERE,
79 base::BindOnce(&CreateReportingServiceProxyOnNetworkTaskRunner,
80 std::move(request), std::move(request_context_getter)));
81 }
82
83 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/net/reporting_service_proxy.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698