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. 4 5 #include "sync/sessions/status_controller.h" 6 7 #include <vector> 8 9 #include "base/basictypes.h" 10 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/protocol/sync_protocol_error.h" 12 13 namespace syncer { 14 namespace sessions { 15 16 StatusController::StatusController() 17 : group_restriction_in_effect_(false), 18 group_restriction_(GROUP_PASSIVE) { 19 } 20 21 StatusController::~StatusController() {} 22 23 void StatusController::increment_num_updates_downloaded_by(int value) { 24 model_neutral_.num_updates_downloaded_total += value; 25 } 26 27 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { 28 model_neutral_.types_needing_local_migration = types; 29 } 30 31 void StatusController::increment_num_tombstone_updates_downloaded_by( 32 int value) { 33 model_neutral_.num_tombstone_updates_downloaded_total += value; 34 } 35 36 void StatusController::increment_num_reflected_updates_downloaded_by( 37 int value) { 38 model_neutral_.num_reflected_updates_downloaded_total += value; 39 } 40 41 void StatusController::set_num_server_changes_remaining( 42 int64 changes_remaining) { 43 model_neutral_.num_server_changes_remaining = changes_remaining; 44 } 45 46 void StatusController::UpdateStartTime() { 47 sync_start_time_ = base::Time::Now(); 48 } 49 50 void StatusController::set_num_successful_bookmark_commits(int value) { 51 model_neutral_.num_successful_bookmark_commits = value; 52 } 53 54 void StatusController::increment_num_successful_bookmark_commits() { 55 model_neutral_.num_successful_bookmark_commits++; 56 } 57 58 void StatusController::increment_num_successful_commits() { 59 model_neutral_.num_successful_commits++; 60 } 61 62 void StatusController::increment_num_updates_applied_by(int value) { 63 model_neutral_.num_updates_applied += value; 64 } 65 66 void StatusController::increment_num_encryption_conflicts_by(int value) { 67 model_neutral_.num_encryption_conflicts += value; 68 } 69 70 void StatusController::increment_num_hierarchy_conflicts_by(int value) { 71 model_neutral_.num_hierarchy_conflicts += value; 72 } 73 74 void StatusController::increment_num_server_conflicts() { 75 model_neutral_.num_server_conflicts++; 76 } 77 78 void StatusController::increment_num_local_overwrites() { 79 model_neutral_.num_local_overwrites++; 80 } 81 82 void StatusController::increment_num_server_overwrites() { 83 model_neutral_.num_server_overwrites++; 84 } 85 86 void StatusController::set_sync_protocol_error( 87 const SyncProtocolError& error) { 88 model_neutral_.sync_protocol_error = error; 89 } 90 91 void StatusController::set_last_get_key_result(const SyncerError result) { 92 model_neutral_.last_get_key_result = result; 93 } 94 95 void StatusController::set_last_download_updates_result( 96 const SyncerError result) { 97 model_neutral_.last_download_updates_result = result; 98 } 99 100 void StatusController::set_commit_result(const SyncerError result) { 101 model_neutral_.commit_result = result; 102 } 103 104 SyncerError StatusController::last_get_key_result() const { 105 return model_neutral_.last_get_key_result; 106 } 107 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; 116 } 117 } 118 119 int StatusController::num_updates_applied() const { 120 return model_neutral_.num_updates_applied; 121 } 122 123 int StatusController::num_server_overwrites() const { 124 return model_neutral_.num_server_overwrites; 125 } 126 127 int StatusController::num_encryption_conflicts() const { 128 return model_neutral_.num_encryption_conflicts; 129 } 130 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; 135 } 136 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; 141 } 142 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; 151 } 152 153 bool StatusController::ServerSaysNothingMoreToDownload() const { 154 if (!download_updates_succeeded()) 155 return false; 156 157 if (!updates_response().get_updates().has_changes_remaining()) { 158 NOTREACHED(); // Server should always send changes remaining. 159 return false; // Avoid looping forever. 160 } 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; 164 } 165 166 void StatusController::set_debug_info_sent() { 167 model_neutral_.debug_info_sent = true; 168 } 169 170 bool StatusController::debug_info_sent() const { 171 return model_neutral_.debug_info_sent; 172 } 173 174 } // namespace sessions 175 } // namespace syncer 176