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

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

Issue 8638001: [Sync] Made some sync session member functions const (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix latent bug in StatusController Created 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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. It 'controls' the model data
7 // defined in session_state.h. The most important feature of StatusController 7 // defined in session_state.h. The most important feature of StatusController
8 // is the ScopedModelSafetyRestriction. When one of these is active, the 8 // is the ScopedModelSafetyRestriction. When one of these is active, the
9 // underlying data set exposed via accessors is swapped out to the appropriate 9 // underlying data set exposed via accessors is swapped out to the appropriate
10 // set for the restricted ModelSafeGroup behind the scenes. For example, if 10 // set for the restricted ModelSafeGroup behind the scenes. For example, if
(...skipping 18 matching lines...) Expand all
29 // so that various parts of the sync engine can avoid broadcasting 29 // so that various parts of the sync engine can avoid broadcasting
30 // notifications if no changes occurred. 30 // notifications if no changes occurred.
31 31
32 #ifndef CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ 32 #ifndef CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_
33 #define CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ 33 #define CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_
34 #pragma once 34 #pragma once
35 35
36 #include <vector> 36 #include <vector>
37 #include <map> 37 #include <map>
38 38
39 #include "base/logging.h"
39 #include "base/stl_util.h" 40 #include "base/stl_util.h"
40 #include "base/time.h" 41 #include "base/time.h"
41 #include "chrome/browser/sync/sessions/ordered_commit_set.h" 42 #include "chrome/browser/sync/sessions/ordered_commit_set.h"
42 #include "chrome/browser/sync/sessions/session_state.h" 43 #include "chrome/browser/sync/sessions/session_state.h"
43 44
44 namespace browser_sync { 45 namespace browser_sync {
45 namespace sessions { 46 namespace sessions {
46 47
47 class StatusController { 48 class StatusController {
48 public: 49 public:
49 explicit StatusController(const ModelSafeRoutingInfo& routes); 50 explicit StatusController(const ModelSafeRoutingInfo& routes);
50 ~StatusController(); 51 ~StatusController();
51 52
52 // Returns true if some portion of the session state has changed (is dirty) 53 // Returns true if some portion of the session state has changed (is dirty)
53 // since it was created or was last reset. 54 // since it was created or was last reset.
54 bool TestAndClearIsDirty(); 55 bool TestAndClearIsDirty();
55 56
56 // Progress counters. 57 // Progress counters. All const methods may return NULL if the
57 const ConflictProgress& conflict_progress() { 58 // progress structure doesn't exist, but all non-const methods
58 return GetOrCreateModelSafeGroupState(true, 59 // auto-create.
59 group_restriction_)->conflict_progress; 60 const ConflictProgress* conflict_progress() const;
60 } 61 ConflictProgress* mutable_conflict_progress();
61 ConflictProgress* mutable_conflict_progress() { 62 const UpdateProgress* update_progress() const;
62 return &GetOrCreateModelSafeGroupState(true, 63 UpdateProgress* mutable_update_progress();
63 group_restriction_)->conflict_progress; 64 const ConflictProgress* GetUnrestrictedConflictProgress(
64 } 65 ModelSafeGroup group) const;
65 const UpdateProgress& update_progress() { 66 const UpdateProgress* GetUnrestrictedUpdateProgress(
66 return GetOrCreateModelSafeGroupState(true, 67 ModelSafeGroup group) const;
67 group_restriction_)->update_progress;
68 }
69 UpdateProgress* mutable_update_progress() {
70 return &GetOrCreateModelSafeGroupState(true,
71 group_restriction_)->update_progress;
72 }
73 // Some unrestricted, non-ModelChangingSyncerCommand commands need to store
74 // meta information about updates.
75 UpdateProgress* GetUnrestrictedUpdateProgress(ModelSafeGroup group) {
76 return &GetOrCreateModelSafeGroupState(false, group)->update_progress;
77 }
78 68
79 // ClientToServer messages. 69 // ClientToServer messages.
80 const ClientToServerMessage& commit_message() { 70 const ClientToServerMessage& commit_message() {
81 return shared_.commit_message; 71 return shared_.commit_message;
82 } 72 }
83 ClientToServerMessage* mutable_commit_message() { 73 ClientToServerMessage* mutable_commit_message() {
84 return &shared_.commit_message; 74 return &shared_.commit_message;
85 } 75 }
86 const ClientToServerResponse& commit_response() const { 76 const ClientToServerResponse& commit_response() const {
87 return shared_.commit_response; 77 return shared_.commit_response;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 112 }
123 const OrderedCommitSet::Projection& commit_id_projection() { 113 const OrderedCommitSet::Projection& commit_id_projection() {
124 DCHECK(group_restriction_in_effect_) 114 DCHECK(group_restriction_in_effect_)
125 << "No group restriction for projection."; 115 << "No group restriction for projection.";
126 return shared_.commit_set.GetCommitIdProjection(group_restriction_); 116 return shared_.commit_set.GetCommitIdProjection(group_restriction_);
127 } 117 }
128 const syncable::Id& GetCommitIdAt(size_t index) { 118 const syncable::Id& GetCommitIdAt(size_t index) {
129 DCHECK(CurrentCommitIdProjectionHasIndex(index)); 119 DCHECK(CurrentCommitIdProjectionHasIndex(index));
130 return shared_.commit_set.GetCommitIdAt(index); 120 return shared_.commit_set.GetCommitIdAt(index);
131 } 121 }
132 syncable::ModelType GetCommitIdModelTypeAt(size_t index) { 122 syncable::ModelType GetCommitModelTypeAt(size_t index) {
133 DCHECK(CurrentCommitIdProjectionHasIndex(index)); 123 DCHECK(CurrentCommitIdProjectionHasIndex(index));
134 return shared_.commit_set.GetModelTypeAt(index); 124 return shared_.commit_set.GetModelTypeAt(index);
135 } 125 }
126 syncable::ModelType GetUnrestrictedCommitModelTypeAt(size_t index) const {
127 DCHECK(!group_restriction_in_effect_) << "Group restriction in effect!";
128 return shared_.commit_set.GetModelTypeAt(index);
129 }
136 const std::vector<int64>& unsynced_handles() const { 130 const std::vector<int64>& unsynced_handles() const {
137 DCHECK(!group_restriction_in_effect_) 131 DCHECK(!group_restriction_in_effect_)
138 << "unsynced_handles is unrestricted."; 132 << "unsynced_handles is unrestricted.";
139 return shared_.unsynced_handles.value(); 133 return shared_.unsynced_handles.value();
140 } 134 }
141 135
142 // Control parameters for sync cycles. 136 // Control parameters for sync cycles.
143 bool conflict_sets_built() const { 137 bool conflict_sets_built() const {
144 return shared_.control_params.conflict_sets_built; 138 return shared_.control_params.conflict_sets_built;
145 } 139 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void set_commit_set(const OrderedCommitSet& commit_set); 228 void set_commit_set(const OrderedCommitSet& commit_set);
235 void update_conflict_sets_built(bool built); 229 void update_conflict_sets_built(bool built);
236 void update_conflicts_resolved(bool resolved); 230 void update_conflicts_resolved(bool resolved);
237 void reset_conflicts_resolved(); 231 void reset_conflicts_resolved();
238 void set_items_committed(); 232 void set_items_committed();
239 233
240 void SetSyncInProgressAndUpdateStartTime(bool sync_in_progress); 234 void SetSyncInProgressAndUpdateStartTime(bool sync_in_progress);
241 235
242 void set_debug_info_sent(); 236 void set_debug_info_sent();
243 237
244 bool debug_info_sent(); 238 bool debug_info_sent() const;
245 239
246 private: 240 private:
247 friend class ScopedModelSafeGroupRestriction; 241 friend class ScopedModelSafeGroupRestriction;
248 242
249 // Returns true iff the commit id projection for |group_restriction_| 243 // Returns true iff the commit id projection for |group_restriction_|
250 // references position |index| into the full set of commit ids in play. 244 // references position |index| into the full set of commit ids in play.
251 bool CurrentCommitIdProjectionHasIndex(size_t index); 245 bool CurrentCommitIdProjectionHasIndex(size_t index);
252 246
247 // Returns the state, if it exists, or NULL otherwise.
248 const PerModelSafeGroupState* GetModelSafeGroupState(
249 bool restrict, ModelSafeGroup group) const;
250
253 // Helper to lazily create objects for per-ModelSafeGroup state. 251 // Helper to lazily create objects for per-ModelSafeGroup state.
254 PerModelSafeGroupState* GetOrCreateModelSafeGroupState(bool restrict, 252 PerModelSafeGroupState* GetOrCreateModelSafeGroupState(
255 ModelSafeGroup group); 253 bool restrict, ModelSafeGroup group);
256 254
257 AllModelTypeState shared_; 255 AllModelTypeState shared_;
258 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; 256 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_;
259 257
260 STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> > 258 STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> >
261 per_model_group_deleter_; 259 per_model_group_deleter_;
262 260
263 // Set to true if any DirtyOnWrite pieces of state we maintain are changed. 261 // Set to true if any DirtyOnWrite pieces of state we maintain are changed.
264 // Reset to false by TestAndClearIsDirty. 262 // Reset to false by TestAndClearIsDirty.
265 bool is_dirty_; 263 bool is_dirty_;
(...skipping 27 matching lines...) Expand all
293 } 291 }
294 private: 292 private:
295 StatusController* status_; 293 StatusController* status_;
296 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); 294 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction);
297 }; 295 };
298 296
299 } 297 }
300 } 298 }
301 299
302 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ 300 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/session_state.cc ('k') | chrome/browser/sync/sessions/status_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698