Remove define of defunct SK_DEBUG_PATH_REF from skia.gyp
[chromium-blink-merge.git] / sync / sessions / status_controller.cc
blobabd6f1ecbd6374c6938d31c71dd5d677d9f2dddb
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sync/sessions/status_controller.h"
7 #include <vector>
9 #include "base/basictypes.h"
10 #include "sync/internal_api/public/base/model_type.h"
11 #include "sync/protocol/sync_protocol_error.h"
13 namespace syncer {
14 namespace sessions {
16 StatusController::StatusController()
17 : group_restriction_in_effect_(false),
18 group_restriction_(GROUP_PASSIVE) {
21 StatusController::~StatusController() {}
23 void StatusController::increment_num_updates_downloaded_by(int value) {
24 model_neutral_.num_updates_downloaded_total += value;
27 void StatusController::set_types_needing_local_migration(ModelTypeSet types) {
28 model_neutral_.types_needing_local_migration = types;
31 void StatusController::increment_num_tombstone_updates_downloaded_by(
32 int value) {
33 model_neutral_.num_tombstone_updates_downloaded_total += value;
36 void StatusController::increment_num_reflected_updates_downloaded_by(
37 int value) {
38 model_neutral_.num_reflected_updates_downloaded_total += value;
41 void StatusController::set_num_server_changes_remaining(
42 int64 changes_remaining) {
43 model_neutral_.num_server_changes_remaining = changes_remaining;
46 void StatusController::UpdateStartTime() {
47 sync_start_time_ = base::Time::Now();
50 void StatusController::set_num_successful_bookmark_commits(int value) {
51 model_neutral_.num_successful_bookmark_commits = value;
54 void StatusController::increment_num_successful_bookmark_commits() {
55 model_neutral_.num_successful_bookmark_commits++;
58 void StatusController::increment_num_successful_commits() {
59 model_neutral_.num_successful_commits++;
62 void StatusController::increment_num_updates_applied_by(int value) {
63 model_neutral_.num_updates_applied += value;
66 void StatusController::increment_num_encryption_conflicts_by(int value) {
67 model_neutral_.num_encryption_conflicts += value;
70 void StatusController::increment_num_hierarchy_conflicts_by(int value) {
71 model_neutral_.num_hierarchy_conflicts += value;
74 void StatusController::increment_num_server_conflicts() {
75 model_neutral_.num_server_conflicts++;
78 void StatusController::increment_num_local_overwrites() {
79 model_neutral_.num_local_overwrites++;
82 void StatusController::increment_num_server_overwrites() {
83 model_neutral_.num_server_overwrites++;
86 void StatusController::set_sync_protocol_error(
87 const SyncProtocolError& error) {
88 model_neutral_.sync_protocol_error = error;
91 void StatusController::set_last_get_key_result(const SyncerError result) {
92 model_neutral_.last_get_key_result = result;
95 void StatusController::set_last_download_updates_result(
96 const SyncerError result) {
97 model_neutral_.last_download_updates_result = result;
100 void StatusController::set_commit_result(const SyncerError result) {
101 model_neutral_.commit_result = result;
104 SyncerError StatusController::last_get_key_result() const {
105 return model_neutral_.last_get_key_result;
108 // Returns the number of updates received from the sync server.
109 int64 StatusController::CountUpdates() const {
110 const sync_pb::ClientToServerResponse& updates =
111 model_neutral_.updates_response;
112 if (updates.has_get_updates()) {
113 return updates.get_updates().entries().size();
114 } else {
115 return 0;
119 int StatusController::num_updates_applied() const {
120 return model_neutral_.num_updates_applied;
123 int StatusController::num_server_overwrites() const {
124 return model_neutral_.num_server_overwrites;
127 int StatusController::num_encryption_conflicts() const {
128 return model_neutral_.num_encryption_conflicts;
131 int StatusController::num_hierarchy_conflicts() const {
132 DCHECK(!group_restriction_in_effect_)
133 << "num_hierarchy_conflicts applies to all ModelSafeGroups";
134 return model_neutral_.num_hierarchy_conflicts;
137 int StatusController::num_server_conflicts() const {
138 DCHECK(!group_restriction_in_effect_)
139 << "num_server_conflicts applies to all ModelSafeGroups";
140 return model_neutral_.num_server_conflicts;
143 int StatusController::TotalNumConflictingItems() const {
144 DCHECK(!group_restriction_in_effect_)
145 << "TotalNumConflictingItems applies to all ModelSafeGroups";
146 int sum = 0;
147 sum += num_encryption_conflicts();
148 sum += num_hierarchy_conflicts();
149 sum += num_server_conflicts();
150 return sum;
153 bool StatusController::ServerSaysNothingMoreToDownload() const {
154 if (!download_updates_succeeded())
155 return false;
157 if (!updates_response().get_updates().has_changes_remaining()) {
158 NOTREACHED(); // Server should always send changes remaining.
159 return false; // Avoid looping forever.
161 // Changes remaining is an estimate, but if it's estimated to be
162 // zero, that's firm and we don't have to ask again.
163 return updates_response().get_updates().changes_remaining() == 0;
166 void StatusController::set_debug_info_sent() {
167 model_neutral_.debug_info_sent = true;
170 bool StatusController::debug_info_sent() const {
171 return model_neutral_.debug_info_sent;
174 } // namespace sessions
175 } // namespace syncer