OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/reporting/reporting_service.h" | 5 #include "net/reporting/reporting_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/time/tick_clock.h" | 12 #include "base/time/tick_clock.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "net/reporting/reporting_cache.h" | 15 #include "net/reporting/reporting_cache.h" |
16 #include "net/reporting/reporting_context.h" | 16 #include "net/reporting/reporting_context.h" |
17 #include "net/reporting/reporting_delegate.h" | |
18 #include "net/reporting/reporting_header_parser.h" | 17 #include "net/reporting/reporting_header_parser.h" |
19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
20 | 19 |
21 namespace net { | 20 namespace net { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 class ReportingServiceImpl : public ReportingService { | 24 class ReportingServiceImpl : public ReportingService { |
26 public: | 25 public: |
27 ReportingServiceImpl(std::unique_ptr<ReportingContext> context) | 26 ReportingServiceImpl(std::unique_ptr<ReportingContext> context) |
28 : context_(std::move(context)) { | 27 : context_(std::move(context)) {} |
29 // TODO(juliatuttle): This can be slow, so it might be better to expose it | |
30 // as a separate method and call it separately from constructing everything. | |
31 context_->Initialize(); | |
32 } | |
33 | 28 |
34 ~ReportingServiceImpl() override {} | 29 ~ReportingServiceImpl() override {} |
35 | 30 |
36 void QueueReport(const GURL& url, | 31 void QueueReport(const GURL& url, |
37 const std::string& group, | 32 const std::string& group, |
38 const std::string& type, | 33 const std::string& type, |
39 std::unique_ptr<const base::Value> body) override { | 34 std::unique_ptr<const base::Value> body) override { |
40 DCHECK(context_->initialized()); | |
41 context_->cache()->AddReport(url, group, type, std::move(body), | 35 context_->cache()->AddReport(url, group, type, std::move(body), |
42 context_->tick_clock()->NowTicks(), 0); | 36 context_->tick_clock()->NowTicks(), 0); |
43 } | 37 } |
44 | 38 |
45 void ProcessHeader(const GURL& url, | 39 void ProcessHeader(const GURL& url, |
46 const std::string& header_value) override { | 40 const std::string& header_value) override { |
47 DCHECK(context_->initialized()); | |
48 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value); | 41 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value); |
49 } | 42 } |
50 | 43 |
51 private: | 44 private: |
52 std::unique_ptr<ReportingContext> context_; | 45 std::unique_ptr<ReportingContext> context_; |
53 | 46 |
54 DISALLOW_COPY_AND_ASSIGN(ReportingServiceImpl); | 47 DISALLOW_COPY_AND_ASSIGN(ReportingServiceImpl); |
55 }; | 48 }; |
56 | 49 |
57 } // namespace | 50 } // namespace |
58 | 51 |
59 ReportingService::~ReportingService() {} | 52 ReportingService::~ReportingService() {} |
60 | 53 |
61 // static | 54 // static |
62 std::unique_ptr<ReportingService> ReportingService::Create( | 55 std::unique_ptr<ReportingService> ReportingService::Create( |
63 const ReportingPolicy& policy, | 56 const ReportingPolicy& policy, |
64 URLRequestContext* request_context, | 57 URLRequestContext* request_context) { |
65 std::unique_ptr<ReportingDelegate> delegate) { | |
66 return base::MakeUnique<ReportingServiceImpl>( | 58 return base::MakeUnique<ReportingServiceImpl>( |
67 ReportingContext::Create(policy, std::move(delegate), request_context)); | 59 ReportingContext::Create(policy, request_context)); |
68 } | 60 } |
69 | 61 |
70 // static | 62 // static |
71 std::unique_ptr<ReportingService> ReportingService::CreateForTesting( | 63 std::unique_ptr<ReportingService> ReportingService::CreateForTesting( |
72 std::unique_ptr<ReportingContext> reporting_context) { | 64 std::unique_ptr<ReportingContext> reporting_context) { |
73 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context)); | 65 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context)); |
74 } | 66 } |
75 | 67 |
76 } // namespace net | 68 } // namespace net |
OLD | NEW |