OLD | NEW |
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 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 20 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
20 ExtensionsActivityMonitor* extensions_activity_monitor, | 21 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 22 ThrottledDataTypeTracker* throttled_data_type_tracker, |
21 const std::vector<SyncEngineEventListener*>& listeners, | 23 const std::vector<SyncEngineEventListener*>& listeners, |
22 DebugInfoGetter* debug_info_getter, | 24 DebugInfoGetter* debug_info_getter, |
23 browser_sync::TrafficRecorder* traffic_recorder) | 25 browser_sync::TrafficRecorder* traffic_recorder) |
24 : resolver_(NULL), | 26 : resolver_(NULL), |
25 connection_manager_(connection_manager), | 27 connection_manager_(connection_manager), |
26 directory_(directory), | 28 directory_(directory), |
27 registrar_(model_safe_worker_registrar), | 29 registrar_(model_safe_worker_registrar), |
28 extensions_activity_monitor_(extensions_activity_monitor), | 30 extensions_activity_monitor_(extensions_activity_monitor), |
29 notifications_enabled_(false), | 31 notifications_enabled_(false), |
30 max_commit_batch_size_(kDefaultMaxCommitBatchSize), | 32 max_commit_batch_size_(kDefaultMaxCommitBatchSize), |
| 33 throttled_data_type_tracker_(throttled_data_type_tracker), |
31 debug_info_getter_(debug_info_getter), | 34 debug_info_getter_(debug_info_getter), |
32 traffic_recorder_(traffic_recorder) { | 35 traffic_recorder_(traffic_recorder) { |
33 std::vector<SyncEngineEventListener*>::const_iterator it; | 36 std::vector<SyncEngineEventListener*>::const_iterator it; |
34 for (it = listeners.begin(); it != listeners.end(); ++it) | 37 for (it = listeners.begin(); it != listeners.end(); ++it) |
35 listeners_.AddObserver(*it); | 38 listeners_.AddObserver(*it); |
36 } | 39 } |
37 | 40 |
38 SyncSessionContext::SyncSessionContext() | |
39 : connection_manager_(NULL), | |
40 directory_(NULL), | |
41 registrar_(NULL), | |
42 extensions_activity_monitor_(NULL), | |
43 debug_info_getter_(NULL), | |
44 traffic_recorder_(NULL) { | |
45 } | |
46 | |
47 SyncSessionContext::~SyncSessionContext() { | 41 SyncSessionContext::~SyncSessionContext() { |
48 } | 42 } |
49 | 43 |
50 void SyncSessionContext::SetUnthrottleTime(syncable::ModelTypeSet types, | |
51 const base::TimeTicks& time) { | |
52 for (syncable::ModelTypeSet::Iterator it = types.First(); | |
53 it.Good(); it.Inc()) { | |
54 unthrottle_times_[it.Get()] = time; | |
55 } | |
56 } | |
57 | |
58 void SyncSessionContext::PruneUnthrottledTypes(const base::TimeTicks& time) { | |
59 UnthrottleTimes::iterator it = unthrottle_times_.begin(); | |
60 while (it != unthrottle_times_.end()) { | |
61 if (it->second <= time) { | |
62 // Delete and increment the iterator. | |
63 UnthrottleTimes::iterator iterator_to_delete = it; | |
64 ++it; | |
65 unthrottle_times_.erase(iterator_to_delete); | |
66 } else { | |
67 // Just increment the iterator. | |
68 ++it; | |
69 } | |
70 } | |
71 } | |
72 | |
73 // TODO(lipalani): Call this function and fill the return values in snapshot | |
74 // so it could be shown in the about:sync page. | |
75 syncable::ModelTypeSet SyncSessionContext::GetThrottledTypes() const { | |
76 syncable::ModelTypeSet types; | |
77 for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin(); | |
78 it != unthrottle_times_.end(); | |
79 ++it) { | |
80 types.Put(it->first); | |
81 } | |
82 return types; | |
83 } | |
84 | |
85 } // namespace sessions | 44 } // namespace sessions |
86 } // namespace browser_sync | 45 } // namespace browser_sync |
OLD | NEW |