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