blob: 42d1246f37f0c46430177327447ad4c6c92e2526 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/engine/all_status.h"
#include "sync/internal_api/public/base/model_type.h"
namespace syncer {
ThrottledDataTypeTracker::ThrottledDataTypeTracker(AllStatus *allstatus)
: allstatus_(allstatus) {
if (allstatus_) {
allstatus_->SetThrottledTypes(syncer::ModelTypeSet());
}
}
ThrottledDataTypeTracker::~ThrottledDataTypeTracker() { }
void ThrottledDataTypeTracker::SetUnthrottleTime(syncer::ModelTypeSet types,
const base::TimeTicks& time) {
for (syncer::ModelTypeSet::Iterator it = types.First();
it.Good(); it.Inc()) {
unthrottle_times_[it.Get()] = time;
}
DVLOG(2)
<< "Throttling types: " << ModelTypeSetToString(types)
<< ", throttled list is now: "
<< ModelTypeSetToString(GetThrottledTypes());
if (allstatus_) {
allstatus_->SetThrottledTypes(GetThrottledTypes());
}
}
void ThrottledDataTypeTracker::PruneUnthrottledTypes(
const base::TimeTicks& time) {
bool modified = false;
UnthrottleTimes::iterator it = unthrottle_times_.begin();
while (it != unthrottle_times_.end()) {
if (it->second <= time) {
// Delete and increment the iterator.
UnthrottleTimes::iterator iterator_to_delete = it;
++it;
unthrottle_times_.erase(iterator_to_delete);
modified = true;
} else {
// Just increment the iterator.
++it;
}
}
DVLOG_IF(2, modified)
<< "Remaining throttled types: "
<< ModelTypeSetToString(GetThrottledTypes());
if (modified && allstatus_) {
allstatus_->SetThrottledTypes(GetThrottledTypes());
}
}
syncer::ModelTypeSet ThrottledDataTypeTracker::GetThrottledTypes() const {
syncer::ModelTypeSet types;
for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
it != unthrottle_times_.end(); ++it) {
types.Put(it->first);
}
return types;
}
} // namespace syncer
|