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 #include "chrome/browser/sync/sessions/status_controller.h" | 5 #include "chrome/browser/sync/sessions/status_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "chrome/browser/sync/protocol/sync_protocol_error.h" | 10 #include "chrome/browser/sync/protocol/sync_protocol_error.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 StatusController::~StatusController() {} | 28 StatusController::~StatusController() {} |
29 | 29 |
30 bool StatusController::TestAndClearIsDirty() { | 30 bool StatusController::TestAndClearIsDirty() { |
31 bool is_dirty = is_dirty_; | 31 bool is_dirty = is_dirty_; |
32 is_dirty_ = false; | 32 is_dirty_ = false; |
33 return is_dirty; | 33 return is_dirty; |
34 } | 34 } |
35 | 35 |
| 36 const UpdateProgress* StatusController::update_progress() const { |
| 37 const PerModelSafeGroupState* state = |
| 38 GetModelSafeGroupState(true, group_restriction_); |
| 39 return state ? &state->update_progress : NULL; |
| 40 } |
| 41 |
| 42 UpdateProgress* StatusController::mutable_update_progress() { |
| 43 return &GetOrCreateModelSafeGroupState( |
| 44 true, group_restriction_)->update_progress; |
| 45 } |
| 46 |
| 47 const ConflictProgress* StatusController::conflict_progress() const { |
| 48 const PerModelSafeGroupState* state = |
| 49 GetModelSafeGroupState(true, group_restriction_); |
| 50 return state ? &state->conflict_progress : NULL; |
| 51 } |
| 52 |
| 53 ConflictProgress* StatusController::mutable_conflict_progress() { |
| 54 return &GetOrCreateModelSafeGroupState( |
| 55 true, group_restriction_)->conflict_progress; |
| 56 } |
| 57 |
| 58 const ConflictProgress* StatusController::GetUnrestrictedConflictProgress( |
| 59 ModelSafeGroup group) const { |
| 60 const PerModelSafeGroupState* state = |
| 61 GetModelSafeGroupState(false, group); |
| 62 return state ? &state->conflict_progress : NULL; |
| 63 } |
| 64 |
| 65 const UpdateProgress* StatusController::GetUnrestrictedUpdateProgress( |
| 66 ModelSafeGroup group) const { |
| 67 const PerModelSafeGroupState* state = |
| 68 GetModelSafeGroupState(false, group); |
| 69 return state ? &state->update_progress : NULL; |
| 70 } |
| 71 |
| 72 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState( |
| 73 bool restrict, ModelSafeGroup group) const { |
| 74 DCHECK_EQ(restrict, group_restriction_in_effect_); |
| 75 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = |
| 76 per_model_group_.find(group); |
| 77 return (it == per_model_group_.end()) ? NULL : it->second; |
| 78 } |
| 79 |
36 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( | 80 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( |
37 bool restrict, ModelSafeGroup group) { | 81 bool restrict, ModelSafeGroup group) { |
38 DCHECK(restrict == group_restriction_in_effect_) << "Group violation!"; | 82 DCHECK_EQ(restrict, group_restriction_in_effect_); |
39 if (per_model_group_.find(group) == per_model_group_.end()) { | 83 std::map<ModelSafeGroup, PerModelSafeGroupState*>::iterator it = |
| 84 per_model_group_.find(group); |
| 85 if (it == per_model_group_.end()) { |
40 PerModelSafeGroupState* state = new PerModelSafeGroupState(&is_dirty_); | 86 PerModelSafeGroupState* state = new PerModelSafeGroupState(&is_dirty_); |
41 per_model_group_[group] = state; | 87 it = per_model_group_.insert(std::make_pair(group, state)).first; |
42 return state; | |
43 } | 88 } |
44 return per_model_group_[group]; | 89 return it->second; |
45 } | 90 } |
46 | 91 |
47 void StatusController::increment_num_conflicting_commits_by(int value) { | 92 void StatusController::increment_num_conflicting_commits_by(int value) { |
48 if (value == 0) | 93 if (value == 0) |
49 return; | 94 return; |
50 shared_.error.mutate()->num_conflicting_commits += value; | 95 shared_.error.mutate()->num_conflicting_commits += value; |
51 } | 96 } |
52 | 97 |
53 void StatusController::increment_num_updates_downloaded_by(int value) { | 98 void StatusController::increment_num_updates_downloaded_by(int value) { |
54 shared_.syncer_status.mutate()->num_updates_downloaded_total += value; | 99 shared_.syncer_status.mutate()->num_updates_downloaded_total += value; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 284 } |
240 // Changes remaining is an estimate, but if it's estimated to be | 285 // Changes remaining is an estimate, but if it's estimated to be |
241 // zero, that's firm and we don't have to ask again. | 286 // zero, that's firm and we don't have to ask again. |
242 return updates_response().get_updates().changes_remaining() == 0; | 287 return updates_response().get_updates().changes_remaining() == 0; |
243 } | 288 } |
244 | 289 |
245 void StatusController::set_debug_info_sent() { | 290 void StatusController::set_debug_info_sent() { |
246 shared_.control_params.debug_info_sent = true; | 291 shared_.control_params.debug_info_sent = true; |
247 } | 292 } |
248 | 293 |
249 bool StatusController::debug_info_sent() { | 294 bool StatusController::debug_info_sent() const { |
250 return shared_.control_params.debug_info_sent; | 295 return shared_.control_params.debug_info_sent; |
251 } | 296 } |
252 | 297 |
253 } // namespace sessions | 298 } // namespace sessions |
254 } // namespace browser_sync | 299 } // namespace browser_sync |
OLD | NEW |