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_garbage_collector.h" | 5 #include "net/reporting/reporting_garbage_collector.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 ~ReportingGarbageCollectorImpl() override { | 33 ~ReportingGarbageCollectorImpl() override { |
34 context_->RemoveObserver(this); | 34 context_->RemoveObserver(this); |
35 } | 35 } |
36 | 36 |
37 void SetTimerForTesting(std::unique_ptr<base::Timer> timer) override { | 37 void SetTimerForTesting(std::unique_ptr<base::Timer> timer) override { |
38 timer_ = std::move(timer); | 38 timer_ = std::move(timer); |
39 } | 39 } |
40 | 40 |
41 // ReportingObserver implementation: | 41 // ReportingObserver implementation: |
42 void OnCacheUpdated() override { | 42 void OnCacheUpdated() override { |
43 if (!timer_->IsRunning()) | 43 if (timer_->IsRunning()) |
44 StartTimer(); | 44 return; |
45 } | |
46 | 45 |
47 private: | |
48 void StartTimer() { | |
49 timer_->Start(FROM_HERE, context_->policy().garbage_collection_interval, | 46 timer_->Start(FROM_HERE, context_->policy().garbage_collection_interval, |
50 base::Bind(&ReportingGarbageCollectorImpl::CollectGarbage, | 47 base::Bind(&ReportingGarbageCollectorImpl::CollectGarbage, |
51 base::Unretained(this))); | 48 base::Unretained(this))); |
52 } | 49 } |
53 | 50 |
| 51 private: |
54 void CollectGarbage() { | 52 void CollectGarbage() { |
55 base::TimeTicks now = context_->tick_clock()->NowTicks(); | 53 base::TimeTicks now = context_->tick_clock()->NowTicks(); |
56 const ReportingPolicy& policy = context_->policy(); | 54 const ReportingPolicy& policy = context_->policy(); |
57 | 55 |
58 std::vector<const ReportingReport*> all_reports; | 56 std::vector<const ReportingReport*> all_reports; |
59 context_->cache()->GetReports(&all_reports); | 57 context_->cache()->GetReports(&all_reports); |
60 | 58 |
61 std::vector<const ReportingReport*> reports_to_remove; | 59 std::vector<const ReportingReport*> reports_to_remove; |
62 for (const ReportingReport* report : all_reports) { | 60 for (const ReportingReport* report : all_reports) { |
63 if (now - report->queued >= policy.max_report_age || | 61 if (now - report->queued >= policy.max_report_age || |
(...skipping 16 matching lines...) Expand all Loading... |
80 | 78 |
81 // static | 79 // static |
82 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create( | 80 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create( |
83 ReportingContext* context) { | 81 ReportingContext* context) { |
84 return base::MakeUnique<ReportingGarbageCollectorImpl>(context); | 82 return base::MakeUnique<ReportingGarbageCollectorImpl>(context); |
85 } | 83 } |
86 | 84 |
87 ReportingGarbageCollector::~ReportingGarbageCollector() {} | 85 ReportingGarbageCollector::~ReportingGarbageCollector() {} |
88 | 86 |
89 } // namespace net | 87 } // namespace net |
OLD | NEW |