OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "components/reporting/core/browser/reporting_service.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/reporting/core/browser/reporting_manager.h" |
| 9 #include "components/reporting/core/browser/reporting_uploader.h" |
| 10 #include "mojo/public/cpp/bindings/binding_set.h" |
| 11 |
| 12 namespace reporting { |
| 13 |
| 14 namespace { |
| 15 |
| 16 class ReportingServiceImpl : public ReportingService { |
| 17 public: |
| 18 ReportingServiceImpl( |
| 19 scoped_refptr<net::URLRequestContextGetter> context, |
| 20 const base::Callback<bool(const GURL&)>& is_origin_secure) |
| 21 : ReportingService(), |
| 22 manager_(base::MakeUnique<ReportingManager>( |
| 23 ReportingUploader::Create(context), |
| 24 is_origin_secure)) {} |
| 25 |
| 26 ~ReportingServiceImpl() override {} |
| 27 |
| 28 void QueueReport(std::unique_ptr<base::Value> body, |
| 29 const GURL& url, |
| 30 const GURL& origin, |
| 31 const std::string& group, |
| 32 const std::string& type) override { |
| 33 auto report = base::MakeUnique<ReportingReport>(); |
| 34 report->body = std::move(body); |
| 35 report->url = url.GetAsReferrer(); |
| 36 report->origin = origin; |
| 37 report->group = group; |
| 38 report->type = type; |
| 39 |
| 40 if (manager_) |
| 41 manager_->QueueReport(std::move(report)); |
| 42 } |
| 43 |
| 44 void ProcessHeader(const GURL& origin, |
| 45 const std::string& header_value) override { |
| 46 if (manager_) |
| 47 manager_->ProcessHeader(origin, header_value); |
| 48 } |
| 49 |
| 50 void AddBinding(mojom::ReportingServiceRequest request) override { |
| 51 bindings_.AddBinding(this, std::move(request)); |
| 52 } |
| 53 |
| 54 private: |
| 55 std::unique_ptr<ReportingManager> manager_; |
| 56 mojo::BindingSet<mojom::ReportingService> bindings_; |
| 57 }; |
| 58 |
| 59 } // namespace |
| 60 |
| 61 ReportingService::~ReportingService() {} |
| 62 |
| 63 std::unique_ptr<ReportingService> ReportingService::Create( |
| 64 scoped_refptr<net::URLRequestContextGetter> context, |
| 65 const base::Callback<bool(const GURL&)>& is_origin_secure) { |
| 66 return base::MakeUnique<ReportingServiceImpl>(context, is_origin_secure); |
| 67 } |
| 68 |
| 69 ReportingService::ReportingService() {} |
| 70 |
| 71 } // namespace reporting |
OLD | NEW |