Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: net/reporting/reporting_garbage_collector.cc

Issue 2751883003: Reporting: Implement serializer. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/reporting/reporting_garbage_collector.h ('k') | net/reporting/reporting_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "net/reporting/reporting_cache.h" 13 #include "net/reporting/reporting_cache.h"
14 #include "net/reporting/reporting_context.h" 14 #include "net/reporting/reporting_context.h"
15 #include "net/reporting/reporting_observer.h" 15 #include "net/reporting/reporting_observer.h"
16 #include "net/reporting/reporting_policy.h" 16 #include "net/reporting/reporting_policy.h"
17 #include "net/reporting/reporting_report.h" 17 #include "net/reporting/reporting_report.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 namespace { 21 namespace {
22 22
23 class ReportingGarbageCollectorImpl : public ReportingGarbageCollector, 23 class ReportingGarbageCollectorImpl : public ReportingGarbageCollector,
24 public ReportingObserver { 24 public ReportingObserver {
25 public: 25 public:
26 ReportingGarbageCollectorImpl(ReportingContext* context) 26 ReportingGarbageCollectorImpl(ReportingContext* context)
27 : context_(context), timer_(base::MakeUnique<base::OneShotTimer>()) { 27 : context_(context), timer_(base::MakeUnique<base::OneShotTimer>()) {}
28 context_->AddObserver(this); 28
29 // ReportingGarbageCollector implementation:
30
31 ~ReportingGarbageCollectorImpl() override {
32 DCHECK(context_->initialized());
33 context_->RemoveObserver(this);
29 } 34 }
30 35
31 // ReportingGarbageCollector implementation: 36 void Initialize() override {
32 // 37 context_->AddObserver(this);
33 ~ReportingGarbageCollectorImpl() override { context_->RemoveObserver(this); } 38 CollectGarbage();
39 }
34 40
35 void SetTimerForTesting(std::unique_ptr<base::Timer> timer) override { 41 void SetTimerForTesting(std::unique_ptr<base::Timer> timer) override {
36 DCHECK(!timer_->IsRunning()); 42 DCHECK(!context_->initialized());
37 timer_ = std::move(timer); 43 timer_ = std::move(timer);
38 } 44 }
39 45
40 // ReportingObserver implementation: 46 // ReportingObserver implementation:
41 void OnCacheUpdated() override { 47 void OnCacheUpdated() override {
48 DCHECK(context_->initialized());
42 if (!timer_->IsRunning()) 49 if (!timer_->IsRunning())
43 StartTimer(); 50 StartTimer();
44 } 51 }
45 52
46 private: 53 private:
47 void StartTimer() { 54 void StartTimer() {
48 timer_->Start(FROM_HERE, context_->policy().garbage_collection_interval, 55 timer_->Start(FROM_HERE, context_->policy().garbage_collection_interval,
49 base::Bind(&ReportingGarbageCollectorImpl::CollectGarbage, 56 base::Bind(&ReportingGarbageCollectorImpl::CollectGarbage,
50 base::Unretained(this))); 57 base::Unretained(this)));
51 } 58 }
(...skipping 27 matching lines...) Expand all
79 86
80 // static 87 // static
81 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create( 88 std::unique_ptr<ReportingGarbageCollector> ReportingGarbageCollector::Create(
82 ReportingContext* context) { 89 ReportingContext* context) {
83 return base::MakeUnique<ReportingGarbageCollectorImpl>(context); 90 return base::MakeUnique<ReportingGarbageCollectorImpl>(context);
84 } 91 }
85 92
86 ReportingGarbageCollector::~ReportingGarbageCollector() {} 93 ReportingGarbageCollector::~ReportingGarbageCollector() {}
87 94
88 } // namespace net 95 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_garbage_collector.h ('k') | net/reporting/reporting_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698