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 "net/reporting/reporting_service.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/callback.h" |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/time/tick_clock.h" |
| 13 #include "base/time/time.h" |
| 14 #include "base/values.h" |
| 15 #include "net/reporting/reporting_browsing_data_remover.h" |
| 16 #include "net/reporting/reporting_cache.h" |
| 17 #include "net/reporting/reporting_context.h" |
| 18 #include "net/reporting/reporting_delegate.h" |
| 19 #include "net/reporting/reporting_header_parser.h" |
| 20 #include "url/gurl.h" |
| 21 |
| 22 namespace net { |
| 23 |
| 24 namespace { |
| 25 |
| 26 class ReportingServiceImpl : public ReportingService { |
| 27 public: |
| 28 ReportingServiceImpl(std::unique_ptr<ReportingContext> context) |
| 29 : context_(std::move(context)) {} |
| 30 |
| 31 ~ReportingServiceImpl() override {} |
| 32 |
| 33 void QueueReport(const GURL& url, |
| 34 const std::string& group, |
| 35 const std::string& type, |
| 36 std::unique_ptr<const base::Value> body) override { |
| 37 context_->cache()->AddReport(url, group, type, std::move(body), |
| 38 context_->tick_clock()->NowTicks(), 0); |
| 39 } |
| 40 |
| 41 void ProcessHeader(const GURL& url, |
| 42 const std::string& header_value) override { |
| 43 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value); |
| 44 } |
| 45 |
| 46 void RemoveBrowsingData( |
| 47 bool remove_reports, |
| 48 bool remove_clients, |
| 49 base::Callback<bool(const GURL&)> origin_filter) override { |
| 50 ReportingBrowsingDataRemover::RemoveBrowsingData( |
| 51 context_.get(), remove_reports, remove_clients, origin_filter); |
| 52 } |
| 53 |
| 54 private: |
| 55 std::unique_ptr<ReportingContext> context_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(ReportingServiceImpl); |
| 58 }; |
| 59 |
| 60 } // namespace |
| 61 |
| 62 ReportingService::~ReportingService() {} |
| 63 |
| 64 // static |
| 65 std::unique_ptr<ReportingService> ReportingService::Create( |
| 66 const ReportingPolicy& policy, |
| 67 URLRequestContext* request_context, |
| 68 std::unique_ptr<ReportingDelegate> delegate) { |
| 69 return base::MakeUnique<ReportingServiceImpl>( |
| 70 ReportingContext::Create(policy, std::move(delegate), request_context)); |
| 71 } |
| 72 |
| 73 // static |
| 74 std::unique_ptr<ReportingService> ReportingService::CreateForTesting( |
| 75 std::unique_ptr<ReportingContext> reporting_context) { |
| 76 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context)); |
| 77 } |
| 78 |
| 79 } // namespace net |
OLD | NEW |