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

Side by Side Diff: sync/sessions/sync_session_context.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/sessions/sync_session_context.h ('k') | sync/sessions/sync_session_context_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/sessions/sync_session_context.h" 5 #include "sync/sessions/sync_session_context.h"
6 6
7 #include "sync/engine/throttled_data_type_tracker.h"
7 #include "sync/sessions/debug_info_getter.h" 8 #include "sync/sessions/debug_info_getter.h"
8 #include "sync/util/extensions_activity_monitor.h" 9 #include "sync/util/extensions_activity_monitor.h"
9 10
10 namespace browser_sync { 11 namespace browser_sync {
11 namespace sessions { 12 namespace sessions {
12 13
13 const unsigned int kMaxMessagesToRecord = 10; 14 const unsigned int kMaxMessagesToRecord = 10;
14 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; 15 const unsigned int kMaxMessageSizeToRecord = 5 * 1024;
15 16
16 SyncSessionContext::SyncSessionContext( 17 SyncSessionContext::SyncSessionContext(
17 ServerConnectionManager* connection_manager, 18 ServerConnectionManager* connection_manager,
18 syncable::Directory* directory, 19 syncable::Directory* directory,
19 const ModelSafeRoutingInfo& model_safe_routing_info, 20 const ModelSafeRoutingInfo& model_safe_routing_info,
20 const std::vector<ModelSafeWorker*>& workers, 21 const std::vector<ModelSafeWorker*>& workers,
21 ExtensionsActivityMonitor* extensions_activity_monitor, 22 ExtensionsActivityMonitor* extensions_activity_monitor,
23 ThrottledDataTypeTracker* throttled_data_type_tracker,
22 const std::vector<SyncEngineEventListener*>& listeners, 24 const std::vector<SyncEngineEventListener*>& listeners,
23 DebugInfoGetter* debug_info_getter, 25 DebugInfoGetter* debug_info_getter,
24 browser_sync::TrafficRecorder* traffic_recorder) 26 browser_sync::TrafficRecorder* traffic_recorder)
25 : resolver_(NULL), 27 : resolver_(NULL),
26 connection_manager_(connection_manager), 28 connection_manager_(connection_manager),
27 directory_(directory), 29 directory_(directory),
28 routing_info_(model_safe_routing_info), 30 routing_info_(model_safe_routing_info),
29 workers_(workers), 31 workers_(workers),
30 extensions_activity_monitor_(extensions_activity_monitor), 32 extensions_activity_monitor_(extensions_activity_monitor),
31 notifications_enabled_(false), 33 notifications_enabled_(false),
32 max_commit_batch_size_(kDefaultMaxCommitBatchSize), 34 max_commit_batch_size_(kDefaultMaxCommitBatchSize),
35 throttled_data_type_tracker_(throttled_data_type_tracker),
33 debug_info_getter_(debug_info_getter), 36 debug_info_getter_(debug_info_getter),
34 traffic_recorder_(traffic_recorder) { 37 traffic_recorder_(traffic_recorder) {
35 std::vector<SyncEngineEventListener*>::const_iterator it; 38 std::vector<SyncEngineEventListener*>::const_iterator it;
36 for (it = listeners.begin(); it != listeners.end(); ++it) 39 for (it = listeners.begin(); it != listeners.end(); ++it)
37 listeners_.AddObserver(*it); 40 listeners_.AddObserver(*it);
38 } 41 }
39 42
40 SyncSessionContext::SyncSessionContext()
41 : connection_manager_(NULL),
42 directory_(NULL),
43 extensions_activity_monitor_(NULL),
44 debug_info_getter_(NULL),
45 traffic_recorder_(NULL) {
46 }
47
48 SyncSessionContext::~SyncSessionContext() { 43 SyncSessionContext::~SyncSessionContext() {
49 } 44 }
50 45
51 void SyncSessionContext::SetUnthrottleTime(syncable::ModelTypeSet types,
52 const base::TimeTicks& time) {
53 for (syncable::ModelTypeSet::Iterator it = types.First();
54 it.Good(); it.Inc()) {
55 unthrottle_times_[it.Get()] = time;
56 }
57 }
58
59 void SyncSessionContext::PruneUnthrottledTypes(const base::TimeTicks& time) {
60 UnthrottleTimes::iterator it = unthrottle_times_.begin();
61 while (it != unthrottle_times_.end()) {
62 if (it->second <= time) {
63 // Delete and increment the iterator.
64 UnthrottleTimes::iterator iterator_to_delete = it;
65 ++it;
66 unthrottle_times_.erase(iterator_to_delete);
67 } else {
68 // Just increment the iterator.
69 ++it;
70 }
71 }
72 }
73
74 // TODO(lipalani): Call this function and fill the return values in snapshot
75 // so it could be shown in the about:sync page.
76 syncable::ModelTypeSet SyncSessionContext::GetThrottledTypes() const {
77 syncable::ModelTypeSet types;
78 for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
79 it != unthrottle_times_.end();
80 ++it) {
81 types.Put(it->first);
82 }
83 return types;
84 }
85
86 } // namespace sessions 46 } // namespace sessions
87 } // namespace browser_sync 47 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/sessions/sync_session_context.h ('k') | sync/sessions/sync_session_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698