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

Unified Diff: sync/engine/throttled_data_type_tracker.cc

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/throttled_data_type_tracker.h ('k') | sync/engine/throttled_data_type_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/throttled_data_type_tracker.cc
diff --git a/sync/engine/throttled_data_type_tracker.cc b/sync/engine/throttled_data_type_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..01317a81df3a02dd2bfcd634a336b03f96d3b0dc
--- /dev/null
+++ b/sync/engine/throttled_data_type_tracker.cc
@@ -0,0 +1,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/syncable/model_type.h"
+
+namespace browser_sync {
+
+ThrottledDataTypeTracker::ThrottledDataTypeTracker(AllStatus *allstatus)
+ : allstatus_(allstatus) {
+ if (allstatus_) {
+ allstatus_->SetThrottledTypes(syncable::ModelTypeSet());
+ }
+}
+
+ThrottledDataTypeTracker::~ThrottledDataTypeTracker() { }
+
+void ThrottledDataTypeTracker::SetUnthrottleTime(syncable::ModelTypeSet types,
+ const base::TimeTicks& time) {
+ for (syncable::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());
+ }
+}
+
+syncable::ModelTypeSet ThrottledDataTypeTracker::GetThrottledTypes() const {
+ syncable::ModelTypeSet types;
+ for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
+ it != unthrottle_times_.end(); ++it) {
+ types.Put(it->first);
+ }
+ return types;
+}
+
+} // namespace browser_sync
« no previous file with comments | « sync/engine/throttled_data_type_tracker.h ('k') | sync/engine/throttled_data_type_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698