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

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

Issue 2881593002: Reporting: Plumb into RenderFrame via Mojo (Closed)
Patch Set: rebase, make requested changes, format 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 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
10 #include "base/memory/ref_counted.h"
11 #include "base/values.h"
12 #include "content/common/net/reporting.mojom.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 "url/gurl.h"
21
22 namespace content {
23
24 namespace {
25
26 void QueueReportOnIOThread(
27 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
28 const GURL& url,
29 const std::string& group,
30 const std::string& type,
31 std::unique_ptr<const base::Value> body) {
32 net::URLRequestContext* request_context =
33 request_context_getter->GetURLRequestContext();
34 if (!request_context)
35 return;
36
37 net::ReportingService* reporting_service =
38 request_context->reporting_service();
39 if (!reporting_service)
40 return;
41
42 // TODO(juliatuttle): Get rid of this copy.
43 reporting_service->QueueReport(url, group, type, body->CreateDeepCopy());
44 }
45
46 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy {
47 public:
48 ReportingServiceProxyImpl(
49 scoped_refptr<net::URLRequestContextGetter> request_context_getter)
50 : request_context_getter_(std::move(request_context_getter)) {}
51
52 // mojom::ReportingServiceProxy:
53 void QueueReport(const GURL& url,
54 const std::string& group,
55 const std::string& type,
56 std::unique_ptr<base::Value> body) override {
57 // TODO(juliatuttle): Get rid of this intermediate step.
58 const base::Value* raw_const_body = body.release();
59
60 request_context_getter_->GetNetworkTaskRunner()->PostTask(
61 FROM_HERE,
62 base::BindOnce(&QueueReportOnIOThread, request_context_getter_, url,
63 group, type, base::WrapUnique(raw_const_body)));
64 }
65
66 private:
67 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
68 };
69
70 } // namespace
71
72 // static
73 void CreateReportingServiceProxy(
74 SiteInstance* site_instance,
75 const service_manager::BindSourceInfo& source_info,
76 mojom::ReportingServiceProxyRequest request) {
77 BrowserContext* browser_context = site_instance->GetBrowserContext();
78 StoragePartition* storage_partition =
79 BrowserContext::GetStoragePartition(browser_context, site_instance);
80 // TODO(juliatuttle): Make sure making our own scoped_refptr is okay.
81 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
82 storage_partition->GetURLRequestContext());
83 mojo::MakeStrongBinding(
84 base::MakeUnique<ReportingServiceProxyImpl>(request_context_getter),
85 std::move(request));
86 }
87
88 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698