Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 19 matching lines...) Expand all Loading... | |
| 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/stl_util.h" | 39 #include "base/stl_util.h" |
| 40 #include "base/time.h" | |
| 40 #include "chrome/browser/sync/sessions/ordered_commit_set.h" | 41 #include "chrome/browser/sync/sessions/ordered_commit_set.h" |
| 41 #include "chrome/browser/sync/sessions/session_state.h" | 42 #include "chrome/browser/sync/sessions/session_state.h" |
| 42 | 43 |
| 43 namespace browser_sync { | 44 namespace browser_sync { |
| 44 namespace sessions { | 45 namespace sessions { |
| 45 | 46 |
| 46 class StatusController { | 47 class StatusController { |
| 47 public: | 48 public: |
| 48 explicit StatusController(const ModelSafeRoutingInfo& routes); | 49 explicit StatusController(const ModelSafeRoutingInfo& routes); |
| 49 ~StatusController(); | 50 ~StatusController(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 // the server said there WAS more to download, or it could mean that we | 186 // the server said there WAS more to download, or it could mean that we |
| 186 // were unable to reach the server. If we didn't request every enabled | 187 // were unable to reach the server. If we didn't request every enabled |
| 187 // datatype, then we can't say for sure that there's nothing left to | 188 // datatype, then we can't say for sure that there's nothing left to |
| 188 // download: in that case, this also returns false. | 189 // download: in that case, this also returns false. |
| 189 bool ServerSaysNothingMoreToDownload() const; | 190 bool ServerSaysNothingMoreToDownload() const; |
| 190 | 191 |
| 191 ModelSafeGroup group_restriction() const { | 192 ModelSafeGroup group_restriction() const { |
| 192 return group_restriction_; | 193 return group_restriction_; |
| 193 } | 194 } |
| 194 | 195 |
| 196 base::Time sync_start_time() const { | |
|
tim (not reviewing)
2011/08/08 23:11:35
Comment what "start" actually means.
lipalani1
2011/08/09 01:39:02
Done.
| |
| 197 return sync_start_time_; | |
| 198 } | |
| 199 | |
| 195 // Check whether a particular model is included by the active group | 200 // Check whether a particular model is included by the active group |
| 196 // restriction. | 201 // restriction. |
| 197 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { | 202 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { |
| 198 if (!group_restriction_in_effect_) | 203 if (!group_restriction_in_effect_) |
| 199 return true; | 204 return true; |
| 200 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | 205 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
| 201 if (it == routing_info_.end()) | 206 if (it == routing_info_.end()) |
| 202 return false; | 207 return false; |
| 203 return group_restriction() == it->second; | 208 return group_restriction() == it->second; |
| 204 } | 209 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 // Reset to false by TestAndClearIsDirty. | 257 // Reset to false by TestAndClearIsDirty. |
| 253 bool is_dirty_; | 258 bool is_dirty_; |
| 254 | 259 |
| 255 // Used to fail read/write operations on state that don't obey the current | 260 // Used to fail read/write operations on state that don't obey the current |
| 256 // active ModelSafeWorker contract. | 261 // active ModelSafeWorker contract. |
| 257 bool group_restriction_in_effect_; | 262 bool group_restriction_in_effect_; |
| 258 ModelSafeGroup group_restriction_; | 263 ModelSafeGroup group_restriction_; |
| 259 | 264 |
| 260 const ModelSafeRoutingInfo routing_info_; | 265 const ModelSafeRoutingInfo routing_info_; |
| 261 | 266 |
| 267 base::Time sync_start_time_; | |
| 268 | |
| 262 DISALLOW_COPY_AND_ASSIGN(StatusController); | 269 DISALLOW_COPY_AND_ASSIGN(StatusController); |
| 263 }; | 270 }; |
| 264 | 271 |
| 265 // A utility to restrict access to only those parts of the given | 272 // A utility to restrict access to only those parts of the given |
| 266 // StatusController that pertain to the specified ModelSafeGroup. | 273 // StatusController that pertain to the specified ModelSafeGroup. |
| 267 class ScopedModelSafeGroupRestriction { | 274 class ScopedModelSafeGroupRestriction { |
| 268 public: | 275 public: |
| 269 ScopedModelSafeGroupRestriction(StatusController* to_restrict, | 276 ScopedModelSafeGroupRestriction(StatusController* to_restrict, |
| 270 ModelSafeGroup restriction) | 277 ModelSafeGroup restriction) |
| 271 : status_(to_restrict) { | 278 : status_(to_restrict) { |
| 272 DCHECK(!status_->group_restriction_in_effect_); | 279 DCHECK(!status_->group_restriction_in_effect_); |
| 273 status_->group_restriction_ = restriction; | 280 status_->group_restriction_ = restriction; |
| 274 status_->group_restriction_in_effect_ = true; | 281 status_->group_restriction_in_effect_ = true; |
| 275 } | 282 } |
| 276 ~ScopedModelSafeGroupRestriction() { | 283 ~ScopedModelSafeGroupRestriction() { |
| 277 DCHECK(status_->group_restriction_in_effect_); | 284 DCHECK(status_->group_restriction_in_effect_); |
| 278 status_->group_restriction_in_effect_ = false; | 285 status_->group_restriction_in_effect_ = false; |
| 279 } | 286 } |
| 280 private: | 287 private: |
| 281 StatusController* status_; | 288 StatusController* status_; |
| 282 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 289 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 283 }; | 290 }; |
| 284 | 291 |
| 285 } | 292 } |
| 286 } | 293 } |
| 287 | 294 |
| 288 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 295 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |