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

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

Issue 2881593002: Reporting: Plumb into RenderFrame via Mojo (Closed)
Patch Set: rebase Created 3 years, 6 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/common/net/reporting.mojom.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/site_instance.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "mojo/public/cpp/bindings/strong_binding.h"
18 #include "net/reporting/reporting_service.h"
19 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_context_getter.h"
21 #include "url/gurl.h"
22
23 namespace content {
24
25 namespace {
26
27 void QueueReportOnIOThread(
28 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
29 const GURL& url,
30 const std::string& group,
31 const std::string& type,
32 std::unique_ptr<const base::Value> body) {
33 net::URLRequestContext* request_context =
34 request_context_getter->GetURLRequestContext();
35 if (!request_context)
36 return;
37
38 net::ReportingService* reporting_service =
39 request_context->reporting_service();
40 if (!reporting_service)
41 return;
42
43 // TODO(juliatuttle): Get rid of this copy.
44 reporting_service->QueueReport(url, group, type, body->CreateDeepCopy());
45 }
46
47 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy {
48 public:
49 ReportingServiceProxyImpl(
50 scoped_refptr<net::URLRequestContextGetter> request_context_getter)
51 : request_context_getter_(std::move(request_context_getter)) {}
52
53 // mojom::ReportingServiceProxy:
54 void QueueReport(const GURL& url,
55 const std::string& group,
56 const std::string& type,
57 std::unique_ptr<base::Value> body) override {
58 // TODO(juliatuttle): Get rid of this intermediate step.
59 const base::Value* raw_const_body = body.release();
60
61 request_context_getter_->GetNetworkTaskRunner()->PostTask(
62 FROM_HERE,
63 base::BindOnce(&QueueReportOnIOThread, request_context_getter_, url,
64 group, type, base::WrapUnique(raw_const_body)));
65 }
66
67 private:
68 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
69 };
70
71 } // namespace
72
73 // static
74 void CreateReportingServiceProxy(
75 SiteInstance* site_instance,
76 const service_manager::BindSourceInfo& source_info,
77 mojom::ReportingServiceProxyRequest request) {
78 BrowserContext* browser_context = site_instance->GetBrowserContext();
79 StoragePartition* storage_partition =
80 BrowserContext::GetStoragePartition(browser_context, site_instance);
81 // TODO(juliatuttle): Make sure making our own scoped_refptr is okay.
82 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
83 storage_partition->GetURLRequestContext());
84 mojo::MakeStrongBinding(base::MakeUnique<ReportingServiceProxyImpl>(
jam 2017/06/05 21:03:44 it'd be more efficient to pass the interface ptr (
Julia Tuttle 2017/06/15 20:33:32 I did this, but I didn't need to use PassInterface
jam 2017/06/23 16:39:41 sg
jam 2017/06/30 01:43:40 Yep.
85 std::move(request_context_getter)),
86 std::move(request));
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698