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

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: Rebase + fix typo Created 7 years 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/internal_api/sync_manager_impl_unittest.cc ('k') | sync/sessions/status_controller.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 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 22 matching lines...) Expand all
135 void set_last_get_key_result(const SyncerError result); 120 void set_last_get_key_result(const SyncerError result);
136 void set_last_download_updates_result(const SyncerError result); 121 void set_last_download_updates_result(const SyncerError result);
137 void set_commit_result(const SyncerError result); 122 void set_commit_result(const SyncerError result);
138 123
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 private: 129 private:
145 friend class ScopedModelSafeGroupRestriction;
146
147 ModelNeutralState model_neutral_; 130 ModelNeutralState model_neutral_;
148 131
149 // Used to fail read/write operations on state that don't obey the current
150 // active ModelSafeWorker contract.
151 bool group_restriction_in_effect_;
152 ModelSafeGroup group_restriction_;
153
154 base::Time sync_start_time_; 132 base::Time sync_start_time_;
155 133
156 DISALLOW_COPY_AND_ASSIGN(StatusController); 134 DISALLOW_COPY_AND_ASSIGN(StatusController);
157 }; 135 };
158 136
159 // A utility to restrict access to only those parts of the given
160 // StatusController that pertain to the specified ModelSafeGroup.
161 class ScopedModelSafeGroupRestriction {
162 public:
163 ScopedModelSafeGroupRestriction(StatusController* to_restrict,
164 ModelSafeGroup restriction)
165 : status_(to_restrict) {
166 DCHECK(!status_->group_restriction_in_effect_);
167 status_->group_restriction_ = restriction;
168 status_->group_restriction_in_effect_ = true;
169 }
170 ~ScopedModelSafeGroupRestriction() {
171 DCHECK(status_->group_restriction_in_effect_);
172 status_->group_restriction_in_effect_ = false;
173 }
174 private:
175 StatusController* status_;
176 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction);
177 };
178
179 } // namespace sessions 137 } // namespace sessions
180 } // namespace syncer 138 } // namespace syncer
181 139
182 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ 140 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/sessions/status_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698