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

Side by Side Diff: sync/sessions/status_controller.h

Issue 72403003: sync: Per-type update application (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 7 years, 1 month 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
OLDNEW
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.
13 // items that live on the UI thread.
14 // 13 //
15 // Other parts of its state are global, and do not require the restriction. 14 // This object contains only global state. None of its members are per model
16 // 15 // type counters.
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 16
28 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_ 17 #ifndef SYNC_SESSIONS_STATUS_CONTROLLER_H_
29 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ 18 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_
30 19
31 #include <map> 20 #include <map>
32 #include <vector> 21 #include <vector>
33 22
34 #include "base/logging.h" 23 #include "base/logging.h"
35 #include "base/stl_util.h" 24 #include "base/stl_util.h"
36 #include "base/time/time.h" 25 #include "base/time/time.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 78 }
90 79
91 // Returns true if the last updates response indicated that we were fully 80 // 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 81 // 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 82 // 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 83 // 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 84 // datatype, then we can't say for sure that there's nothing left to
96 // download: in that case, this also returns false. 85 // download: in that case, this also returns false.
97 bool ServerSaysNothingMoreToDownload() const; 86 bool ServerSaysNothingMoreToDownload() const;
98 87
99 ModelSafeGroup group_restriction() const {
100 return group_restriction_;
101 }
102
103 base::Time sync_start_time() const { 88 base::Time sync_start_time() const {
104 // The time at which we sent the first GetUpdates command for this sync. 89 // The time at which we sent the first GetUpdates command for this sync.
105 return sync_start_time_; 90 return sync_start_time_;
106 } 91 }
107 92
108 const ModelNeutralState& model_neutral_state() const { 93 const ModelNeutralState& model_neutral_state() const {
109 return model_neutral_; 94 return model_neutral_;
110 } 95 }
111 96
112 SyncerError last_get_key_result() const; 97 SyncerError last_get_key_result() const;
(...skipping 26 matching lines...) Expand all
139 // A very important flag used to inform frontend of need to migrate. 124 // A very important flag used to inform frontend of need to migrate.
140 void set_types_needing_local_migration(ModelTypeSet types); 125 void set_types_needing_local_migration(ModelTypeSet types);
141 126
142 void UpdateStartTime(); 127 void UpdateStartTime();
143 128
144 void set_debug_info_sent(); 129 void set_debug_info_sent();
145 130
146 bool debug_info_sent() const; 131 bool debug_info_sent() const;
147 132
148 private: 133 private:
149 friend class ScopedModelSafeGroupRestriction;
150
151 ModelNeutralState model_neutral_; 134 ModelNeutralState model_neutral_;
152 135
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_; 136 base::Time sync_start_time_;
159 137
160 DISALLOW_COPY_AND_ASSIGN(StatusController); 138 DISALLOW_COPY_AND_ASSIGN(StatusController);
161 }; 139 };
162 140
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 141 } // namespace sessions
184 } // namespace syncer 142 } // namespace syncer
185 143
186 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ 144 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698