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 // StatusController handles all counter and status related number crunching and | 5 // StatusController handles all counter and status related number crunching and |
6 // state tracking on behalf of a SyncSession. It 'controls' the model data | 6 // state tracking on behalf of a SyncSession. |
7 // defined in session_state.h. The most important feature of StatusController | 7 // |
8 // is the ScopedModelSafetyRestriction. When one of these is active, the | 8 // The most important feature of StatusController is the |
9 // underlying data set exposed via accessors is swapped out to the appropriate | 9 // ScopedModelSafeGroupRestriction. Some of its functions expose per-thread |
10 // set for the restricted ModelSafeGroup behind the scenes. For example, if | 10 // state, and can be called only when the SafetyRestriction is in effect. Other |
Nicolas Zea
2012/10/26 21:14:30
I think the more indepth description that was here
rlarocque
2012/10/26 21:41:46
The only remaining use of the ModelSafeGroupRestri
Nicolas Zea
2012/10/26 22:03:27
"per-thread" is kind of implicit, the more explici
| |
11 // GROUP_UI is set, then accessors such as conflict_progress() and commit_ids() | 11 // parts of its state are global, and do not require the restriction. |
12 // are implicitly restricted to returning only data pertaining to GROUP_UI. | |
13 // You can see which parts of status fall into this "restricted" category, or | |
14 // the global "shared" category for all model types, by looking at the struct | |
15 // declarations in session_state.h. If these accessors are invoked without a | |
16 // restriction in place, this is a violation and will cause debug assertions | |
17 // to surface improper use of the API in development. Likewise for | |
18 // invocation of "shared" accessors when a restriction is in place; for | |
19 // safety's sake, an assertion will fire. | |
20 // | 12 // |
21 // NOTE: There is no concurrent access protection provided by this class. It | 13 // NOTE: There is no concurrent access protection provided by this class. It |
22 // assumes one single thread is accessing this class for each unique | 14 // assumes one single thread is accessing this class for each unique |
23 // ModelSafeGroup, and also only one single thread (in practice, the | 15 // ModelSafeGroup, and also only one single thread (in practice, the |
24 // SyncerThread) responsible for all "shared" access when no restriction is in | 16 // SyncerThread) responsible for all "shared" access when no restriction is in |
25 // place. Thus, every bit of data is to be accessed mutually exclusively with | 17 // place. Thus, every bit of data is to be accessed mutually exclusively with |
26 // respect to threads. | 18 // respect to threads. |
27 // | 19 // |
28 // StatusController can also track if changes occur to certain parts of state | 20 // StatusController can also track if changes occur to certain parts of state |
29 // so that various parts of the sync engine can avoid broadcasting | 21 // so that various parts of the sync engine can avoid broadcasting |
30 // notifications if no changes occurred. | 22 // notifications if no changes occurred. |
31 | 23 |
32 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 24 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
33 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 25 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
34 | 26 |
35 #include <map> | 27 #include <map> |
36 #include <vector> | 28 #include <vector> |
37 | 29 |
38 #include "base/logging.h" | 30 #include "base/logging.h" |
39 #include "base/stl_util.h" | 31 #include "base/stl_util.h" |
40 #include "base/time.h" | 32 #include "base/time.h" |
41 #include "sync/internal_api/public/sessions/model_neutral_state.h" | 33 #include "sync/internal_api/public/sessions/model_neutral_state.h" |
42 #include "sync/sessions/ordered_commit_set.h" | 34 #include "sync/sessions/ordered_commit_set.h" |
43 #include "sync/sessions/session_state.h" | |
44 | 35 |
45 namespace syncer { | 36 namespace syncer { |
46 namespace sessions { | 37 namespace sessions { |
47 | 38 |
48 class StatusController { | 39 class StatusController { |
49 public: | 40 public: |
50 explicit StatusController(const ModelSafeRoutingInfo& routes); | 41 explicit StatusController(const ModelSafeRoutingInfo& routes); |
51 ~StatusController(); | 42 ~StatusController(); |
52 | 43 |
53 // Progress counters. All const methods may return NULL if the | |
54 // progress structure doesn't exist, but all non-const methods | |
55 // auto-create. | |
56 const std::set<syncable::Id>* simple_conflict_ids() const; | |
57 std::set<syncable::Id>* mutable_simple_conflict_ids(); | |
58 const std::set<syncable::Id>* GetUnrestrictedSimpleConflictIds( | |
59 ModelSafeGroup group) const; | |
60 | |
61 // ClientToServer messages. | 44 // ClientToServer messages. |
62 const ModelTypeSet updates_request_types() const { | 45 const ModelTypeSet updates_request_types() const { |
63 return model_neutral_.updates_request_types; | 46 return model_neutral_.updates_request_types; |
64 } | 47 } |
65 void set_updates_request_types(ModelTypeSet value) { | 48 void set_updates_request_types(ModelTypeSet value) { |
66 model_neutral_.updates_request_types = value; | 49 model_neutral_.updates_request_types = value; |
67 } | 50 } |
68 const sync_pb::ClientToServerResponse& updates_response() const { | 51 const sync_pb::ClientToServerResponse& updates_response() const { |
69 return model_neutral_.updates_response; | 52 return model_neutral_.updates_response; |
70 } | 53 } |
71 sync_pb::ClientToServerResponse* mutable_updates_response() { | 54 sync_pb::ClientToServerResponse* mutable_updates_response() { |
72 return &model_neutral_.updates_response; | 55 return &model_neutral_.updates_response; |
73 } | 56 } |
74 | 57 |
75 // Changelog related state. | 58 // Changelog related state. |
76 int64 num_server_changes_remaining() const { | 59 int64 num_server_changes_remaining() const { |
77 return model_neutral_.num_server_changes_remaining; | 60 return model_neutral_.num_server_changes_remaining; |
78 } | 61 } |
79 | 62 |
80 const OrderedCommitSet::Projection& commit_id_projection( | 63 const OrderedCommitSet::Projection& commit_id_projection( |
81 const sessions::OrderedCommitSet &commit_set) { | 64 const sessions::OrderedCommitSet &commit_set) { |
82 DCHECK(group_restriction_in_effect_) | 65 DCHECK(group_restriction_in_effect_) |
83 << "No group restriction for projection."; | 66 << "No group restriction for projection."; |
84 return commit_set.GetCommitIdProjection(group_restriction_); | 67 return commit_set.GetCommitIdProjection(group_restriction_); |
85 } | 68 } |
86 | 69 |
87 // Control parameters for sync cycles. | |
88 bool conflicts_resolved() const { | |
89 return model_neutral_.conflicts_resolved; | |
90 } | |
91 | |
92 // If a GetUpdates for any data type resulted in downloading an update that | |
93 // is in conflict, this method returns true. | |
94 // Note: this includes unresolvable conflicts. | |
95 bool HasConflictingUpdates() const; | |
96 | |
97 // Various conflict counters. | 70 // Various conflict counters. |
98 int num_encryption_conflicts() const; | 71 int num_encryption_conflicts() const; |
99 int num_hierarchy_conflicts() const; | 72 int num_hierarchy_conflicts() const; |
100 int num_server_conflicts() const; | 73 int num_server_conflicts() const; |
101 | 74 |
102 int num_simple_conflicts() const; | |
103 | |
104 // Aggregate sum of all conflicting items over all conflict types. | 75 // Aggregate sum of all conflicting items over all conflict types. |
105 int TotalNumConflictingItems() const; | 76 int TotalNumConflictingItems() const; |
106 | 77 |
107 // Number of successfully applied updates. | 78 // Number of successfully applied updates. |
108 int num_updates_applied() const; | 79 int num_updates_applied() const; |
109 | 80 |
110 int num_server_overwrites() const; | 81 int num_server_overwrites() const; |
111 | 82 |
112 // Returns the number of updates received from the sync server. | 83 // Returns the number of updates received from the sync server. |
113 int64 CountUpdates() const; | 84 int64 CountUpdates() const; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 void increment_num_reflected_updates_downloaded_by(int value); | 124 void increment_num_reflected_updates_downloaded_by(int value); |
154 | 125 |
155 // Update application and conflict resolution counters. | 126 // Update application and conflict resolution counters. |
156 void increment_num_updates_applied_by(int value); | 127 void increment_num_updates_applied_by(int value); |
157 void increment_num_encryption_conflicts_by(int value); | 128 void increment_num_encryption_conflicts_by(int value); |
158 void increment_num_hierarchy_conflicts_by(int value); | 129 void increment_num_hierarchy_conflicts_by(int value); |
159 void increment_num_server_conflicts(); | 130 void increment_num_server_conflicts(); |
160 void increment_num_local_overwrites(); | 131 void increment_num_local_overwrites(); |
161 void increment_num_server_overwrites(); | 132 void increment_num_server_overwrites(); |
162 | 133 |
163 // TODO(rlarocque): Remove these after conflict resolution refactor. | |
164 void update_conflicts_resolved(bool resolved); | |
165 void reset_conflicts_resolved(); | |
166 | |
167 // Commit counters. | 134 // Commit counters. |
168 void increment_num_successful_commits(); | 135 void increment_num_successful_commits(); |
169 void increment_num_successful_bookmark_commits(); | 136 void increment_num_successful_bookmark_commits(); |
170 void set_num_successful_bookmark_commits(int value); | 137 void set_num_successful_bookmark_commits(int value); |
171 | 138 |
172 // Server communication status tracking. | 139 // Server communication status tracking. |
173 void set_sync_protocol_error(const SyncProtocolError& error); | 140 void set_sync_protocol_error(const SyncProtocolError& error); |
174 void set_last_get_key_result(const SyncerError result); | 141 void set_last_get_key_result(const SyncerError result); |
175 void set_last_download_updates_result(const SyncerError result); | 142 void set_last_download_updates_result(const SyncerError result); |
176 void set_commit_result(const SyncerError result); | 143 void set_commit_result(const SyncerError result); |
(...skipping 14 matching lines...) Expand all Loading... | |
191 // restriction. | 158 // restriction. |
192 bool ActiveGroupRestrictionIncludesModel(ModelType model) const { | 159 bool ActiveGroupRestrictionIncludesModel(ModelType model) const { |
193 if (!group_restriction_in_effect_) | 160 if (!group_restriction_in_effect_) |
194 return true; | 161 return true; |
195 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | 162 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
196 if (it == routing_info_.end()) | 163 if (it == routing_info_.end()) |
197 return false; | 164 return false; |
198 return group_restriction() == it->second; | 165 return group_restriction() == it->second; |
199 } | 166 } |
200 | 167 |
201 // Returns the state, if it exists, or NULL otherwise. | |
202 const PerModelSafeGroupState* GetModelSafeGroupState( | |
203 bool restrict, ModelSafeGroup group) const; | |
204 | |
205 // Helper to lazily create objects for per-ModelSafeGroup state. | |
206 PerModelSafeGroupState* GetOrCreateModelSafeGroupState( | |
207 bool restrict, ModelSafeGroup group); | |
208 | |
209 ModelNeutralState model_neutral_; | 168 ModelNeutralState model_neutral_; |
210 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; | |
211 | |
212 STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> > | |
213 per_model_group_deleter_; | |
214 | 169 |
215 // Used to fail read/write operations on state that don't obey the current | 170 // Used to fail read/write operations on state that don't obey the current |
216 // active ModelSafeWorker contract. | 171 // active ModelSafeWorker contract. |
217 bool group_restriction_in_effect_; | 172 bool group_restriction_in_effect_; |
218 ModelSafeGroup group_restriction_; | 173 ModelSafeGroup group_restriction_; |
219 | 174 |
220 const ModelSafeRoutingInfo routing_info_; | 175 const ModelSafeRoutingInfo routing_info_; |
221 | 176 |
222 base::Time sync_start_time_; | 177 base::Time sync_start_time_; |
223 | 178 |
(...skipping 17 matching lines...) Expand all Loading... | |
241 } | 196 } |
242 private: | 197 private: |
243 StatusController* status_; | 198 StatusController* status_; |
244 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 199 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
245 }; | 200 }; |
246 | 201 |
247 } // namespace sessions | 202 } // namespace sessions |
248 } // namespace syncer | 203 } // namespace syncer |
249 | 204 |
250 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 205 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
OLD | NEW |