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 #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( | |
| 85 base::MakeUnique<ReportingServiceProxyImpl>(request_context_getter), | |
|
dcheng
2017/05/24 22:29:25
Nit: std::move() here as well.
Julia Tuttle
2017/05/25 17:36:42
Done.
| |
| 86 std::move(request)); | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |