Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/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: Get rid of this copy. | |
|
shivanisha
2017/05/17 18:58:28
nit: TODO(username)
Julia Tuttle
2017/05/18 19:34:25
Done.
| |
| 43 reporting_service->QueueReport(url, group, type, body->CreateDeepCopy()); | |
| 44 } | |
| 45 | |
| 46 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy { | |
| 47 public: | |
| 48 ReportingServiceProxyImpl( | |
| 49 mojom::ReportingServiceProxyRequest request, | |
| 50 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | |
| 51 : binding_(this, std::move(request)), | |
| 52 request_context_getter_(request_context_getter) {} | |
| 53 | |
| 54 // mojom::ReportingServiceProxy: | |
| 55 void QueueReport(const GURL& url, | |
| 56 const std::string& group, | |
| 57 const std::string& type, | |
| 58 std::unique_ptr<base::Value> body) override { | |
| 59 // TODO: Get rid of this intermediate step. | |
| 60 const base::Value* raw_const_body = body.release(); | |
| 61 | |
| 62 request_context_getter_->GetNetworkTaskRunner()->PostTask( | |
| 63 FROM_HERE, | |
| 64 base::BindOnce(&QueueReportOnIOThread, request_context_getter_, url, | |
| 65 group, type, base::WrapUnique(raw_const_body))); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 mojo::Binding<mojom::ReportingServiceProxy> binding_; | |
| 70 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 71 }; | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 // static | |
| 76 void CreateReportingServiceProxy( | |
| 77 scoped_refptr<SiteInstance> site_instance, | |
| 78 const service_manager::BindSourceInfo& source_info, | |
| 79 mojom::ReportingServiceProxyRequest request) { | |
| 80 BrowserContext* browser_context = site_instance->GetBrowserContext(); | |
| 81 StoragePartition* storage_partition = | |
| 82 BrowserContext::GetStoragePartition(browser_context, site_instance.get()); | |
| 83 // 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.
| |
| 84 scoped_refptr<net::URLRequestContextGetter> request_context_getter( | |
| 85 storage_partition->GetURLRequestContext()); | |
| 86 new ReportingServiceProxyImpl(std::move(request), | |
| 87 std::move(request_context_getter)); | |
| 88 } | |
| 89 } | |
| OLD | NEW |