OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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. | 6 // state tracking on behalf of a SyncSession. |
7 // | 7 // |
8 // The most important feature of StatusController is the | 8 // This object may be accessed from many different threads. It will be accessed |
9 // ScopedModelSafeGroupRestriction. Some of its functions expose per-thread | 9 // most often from the syncer thread. However, when update application is in |
10 // state, and can be called only when the restriction is in effect. For | 10 // progress it may also be accessed from the worker threads. This is safe |
11 // example, if GROUP_UI is set then the value returned from | 11 // because only one of them will run at a time, and the syncer thread will be |
12 // commit_id_projection() will be useful for iterating over the commit IDs of | 12 // blocked until update application completes. |
Nicolas Zea
2013/11/19 22:45:26
Does the status controller only hold model neutral
rlarocque
2013/11/21 18:28:47
It hasn't tracked any data type specific state for
| |
13 // items that live on the UI thread. | |
14 // | |
15 // Other parts of its state are global, and do not require the restriction. | |
16 // | |
17 // NOTE: There is no concurrent access protection provided by this class. It | |
18 // assumes one single thread is accessing this class for each unique | |
19 // ModelSafeGroup, and also only one single thread (in practice, the | |
20 // SyncerThread) responsible for all "shared" access when no restriction is in | |
21 // place. Thus, every bit of data is to be accessed mutually exclusively with | |
22 // respect to threads. | |
23 // | |
24 // StatusController can also track if changes occur to certain parts of state | |
25 // so that various parts of the sync engine can avoid broadcasting | |
26 // notifications if no changes occurred. | |
27 | 13 |
28 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 14 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
29 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 15 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
30 | 16 |
31 #include <map> | 17 #include <map> |
32 #include <vector> | 18 #include <vector> |
33 | 19 |
34 #include "base/logging.h" | 20 #include "base/logging.h" |
35 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
36 #include "base/time/time.h" | 22 #include "base/time/time.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 } | 75 } |
90 | 76 |
91 // Returns true if the last updates response indicated that we were fully | 77 // Returns true if the last updates response indicated that we were fully |
92 // up to date. This is subtle: if it's false, it could either mean that | 78 // up to date. This is subtle: if it's false, it could either mean that |
93 // the server said there WAS more to download, or it could mean that we | 79 // the server said there WAS more to download, or it could mean that we |
94 // were unable to reach the server. If we didn't request every enabled | 80 // were unable to reach the server. If we didn't request every enabled |
95 // datatype, then we can't say for sure that there's nothing left to | 81 // datatype, then we can't say for sure that there's nothing left to |
96 // download: in that case, this also returns false. | 82 // download: in that case, this also returns false. |
97 bool ServerSaysNothingMoreToDownload() const; | 83 bool ServerSaysNothingMoreToDownload() const; |
98 | 84 |
99 ModelSafeGroup group_restriction() const { | |
100 return group_restriction_; | |
101 } | |
102 | |
103 base::Time sync_start_time() const { | 85 base::Time sync_start_time() const { |
104 // The time at which we sent the first GetUpdates command for this sync. | 86 // The time at which we sent the first GetUpdates command for this sync. |
105 return sync_start_time_; | 87 return sync_start_time_; |
106 } | 88 } |
107 | 89 |
108 const ModelNeutralState& model_neutral_state() const { | 90 const ModelNeutralState& model_neutral_state() const { |
109 return model_neutral_; | 91 return model_neutral_; |
110 } | 92 } |
111 | 93 |
112 SyncerError last_get_key_result() const; | 94 SyncerError last_get_key_result() const; |
(...skipping 26 matching lines...) Expand all Loading... | |
139 // A very important flag used to inform frontend of need to migrate. | 121 // A very important flag used to inform frontend of need to migrate. |
140 void set_types_needing_local_migration(ModelTypeSet types); | 122 void set_types_needing_local_migration(ModelTypeSet types); |
141 | 123 |
142 void UpdateStartTime(); | 124 void UpdateStartTime(); |
143 | 125 |
144 void set_debug_info_sent(); | 126 void set_debug_info_sent(); |
145 | 127 |
146 bool debug_info_sent() const; | 128 bool debug_info_sent() const; |
147 | 129 |
148 private: | 130 private: |
149 friend class ScopedModelSafeGroupRestriction; | |
150 | |
151 ModelNeutralState model_neutral_; | 131 ModelNeutralState model_neutral_; |
152 | 132 |
153 // Used to fail read/write operations on state that don't obey the current | |
154 // active ModelSafeWorker contract. | |
155 bool group_restriction_in_effect_; | |
156 ModelSafeGroup group_restriction_; | |
157 | |
158 base::Time sync_start_time_; | 133 base::Time sync_start_time_; |
159 | 134 |
160 DISALLOW_COPY_AND_ASSIGN(StatusController); | 135 DISALLOW_COPY_AND_ASSIGN(StatusController); |
161 }; | 136 }; |
162 | 137 |
163 // A utility to restrict access to only those parts of the given | |
164 // StatusController that pertain to the specified ModelSafeGroup. | |
165 class ScopedModelSafeGroupRestriction { | |
166 public: | |
167 ScopedModelSafeGroupRestriction(StatusController* to_restrict, | |
168 ModelSafeGroup restriction) | |
169 : status_(to_restrict) { | |
170 DCHECK(!status_->group_restriction_in_effect_); | |
171 status_->group_restriction_ = restriction; | |
172 status_->group_restriction_in_effect_ = true; | |
173 } | |
174 ~ScopedModelSafeGroupRestriction() { | |
175 DCHECK(status_->group_restriction_in_effect_); | |
176 status_->group_restriction_in_effect_ = false; | |
177 } | |
178 private: | |
179 StatusController* status_; | |
180 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | |
181 }; | |
182 | |
183 } // namespace sessions | 138 } // namespace sessions |
184 } // namespace syncer | 139 } // namespace syncer |
185 | 140 |
186 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 141 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
OLD | NEW |