| OLD | NEW |
| (Empty) |
| 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/internal_api/all_status.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/port.h" | |
| 11 #include "sync/engine/net/server_connection_manager.h" | |
| 12 #include "sync/internal_api/public/syncable/model_type.h" | |
| 13 #include "sync/sessions/session_state.h" | |
| 14 | |
| 15 namespace browser_sync { | |
| 16 | |
| 17 AllStatus::AllStatus() { | |
| 18 status_.initial_sync_ended = true; | |
| 19 status_.notifications_enabled = false; | |
| 20 status_.cryptographer_ready = false; | |
| 21 status_.crypto_has_pending_keys = false; | |
| 22 } | |
| 23 | |
| 24 AllStatus::~AllStatus() { | |
| 25 } | |
| 26 | |
| 27 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { | |
| 28 // Status is initialized with the previous status value. Variables | |
| 29 // whose values accumulate (e.g. lifetime counters like updates_received) | |
| 30 // are not to be cleared here. | |
| 31 sync_api::SyncManager::Status status = status_; | |
| 32 status.encryption_conflicts = 0; | |
| 33 status.hierarchy_conflicts = 0; | |
| 34 status.simple_conflicts = 0; | |
| 35 status.server_conflicts = 0; | |
| 36 status.committed_count = 0; | |
| 37 status.initial_sync_ended = false; | |
| 38 status.updates_available = 0; | |
| 39 return status; | |
| 40 } | |
| 41 | |
| 42 sync_api::SyncManager::Status AllStatus::CalcSyncing( | |
| 43 const SyncEngineEvent &event) const { | |
| 44 sync_api::SyncManager::Status status = CreateBlankStatus(); | |
| 45 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; | |
| 46 status.encryption_conflicts = snapshot.num_encryption_conflicts(); | |
| 47 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); | |
| 48 status.simple_conflicts = snapshot.num_simple_conflicts(); | |
| 49 status.server_conflicts = snapshot.num_server_conflicts(); | |
| 50 status.committed_count = snapshot.syncer_status().num_successful_commits; | |
| 51 | |
| 52 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { | |
| 53 status.syncing = true; | |
| 54 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | |
| 55 status.syncing = false; | |
| 56 } | |
| 57 | |
| 58 status.initial_sync_ended |= snapshot.is_share_usable(); | |
| 59 | |
| 60 status.updates_available += snapshot.num_server_changes_remaining(); | |
| 61 status.sync_protocol_error = snapshot.errors().sync_protocol_error; | |
| 62 | |
| 63 // Accumulate update count only once per session to avoid double-counting. | |
| 64 // TODO(ncarter): Make this realtime by having the syncer_status | |
| 65 // counter preserve its value across sessions. http://crbug.com/26339 | |
| 66 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | |
| 67 status.updates_received += | |
| 68 snapshot.syncer_status().num_updates_downloaded_total; | |
| 69 status.tombstone_updates_received += | |
| 70 snapshot.syncer_status().num_tombstone_updates_downloaded_total; | |
| 71 status.reflected_updates_received += | |
| 72 snapshot.syncer_status().num_reflected_updates_downloaded_total; | |
| 73 status.num_commits_total += | |
| 74 snapshot.syncer_status().num_successful_commits; | |
| 75 status.num_local_overwrites_total += | |
| 76 snapshot.syncer_status().num_local_overwrites; | |
| 77 status.num_server_overwrites_total += | |
| 78 snapshot.syncer_status().num_server_overwrites; | |
| 79 if (snapshot.syncer_status().num_updates_downloaded_total == 0) { | |
| 80 ++status.empty_get_updates; | |
| 81 } else { | |
| 82 ++status.nonempty_get_updates; | |
| 83 } | |
| 84 if (snapshot.syncer_status().num_successful_commits == 0) { | |
| 85 ++status.sync_cycles_without_commits; | |
| 86 } else { | |
| 87 ++status.sync_cycles_with_commits; | |
| 88 } | |
| 89 if (snapshot.syncer_status().num_successful_commits == 0 && | |
| 90 snapshot.syncer_status().num_updates_downloaded_total == 0) { | |
| 91 ++status.useless_sync_cycles; | |
| 92 } else { | |
| 93 ++status.useful_sync_cycles; | |
| 94 } | |
| 95 } | |
| 96 return status; | |
| 97 } | |
| 98 | |
| 99 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { | |
| 100 ScopedStatusLock lock(this); | |
| 101 switch (event.what_happened) { | |
| 102 case SyncEngineEvent::SYNC_CYCLE_BEGIN: | |
| 103 case SyncEngineEvent::STATUS_CHANGED: | |
| 104 case SyncEngineEvent::SYNC_CYCLE_ENDED: | |
| 105 status_ = CalcSyncing(event); | |
| 106 break; | |
| 107 case SyncEngineEvent::STOP_SYNCING_PERMANENTLY: | |
| 108 case SyncEngineEvent::UPDATED_TOKEN: | |
| 109 case SyncEngineEvent::CLEAR_SERVER_DATA_FAILED: | |
| 110 case SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED: | |
| 111 break; | |
| 112 case SyncEngineEvent::ACTIONABLE_ERROR: | |
| 113 status_ = CreateBlankStatus(); | |
| 114 status_.sync_protocol_error = event.snapshot.errors().sync_protocol_error; | |
| 115 break; | |
| 116 default: | |
| 117 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; | |
| 118 break; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 sync_api::SyncManager::Status AllStatus::status() const { | |
| 123 base::AutoLock lock(mutex_); | |
| 124 return status_; | |
| 125 } | |
| 126 | |
| 127 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | |
| 128 ScopedStatusLock lock(this); | |
| 129 status_.notifications_enabled = notifications_enabled; | |
| 130 } | |
| 131 | |
| 132 void AllStatus::IncrementNotificationsReceived() { | |
| 133 ScopedStatusLock lock(this); | |
| 134 ++status_.notifications_received; | |
| 135 } | |
| 136 | |
| 137 void AllStatus::SetEncryptedTypes(syncable::ModelTypeSet types) { | |
| 138 ScopedStatusLock lock(this); | |
| 139 status_.encrypted_types = types; | |
| 140 } | |
| 141 | |
| 142 void AllStatus::SetCryptographerReady(bool ready) { | |
| 143 ScopedStatusLock lock(this); | |
| 144 status_.cryptographer_ready = ready; | |
| 145 } | |
| 146 | |
| 147 void AllStatus::SetCryptoHasPendingKeys(bool has_pending_keys) { | |
| 148 ScopedStatusLock lock(this); | |
| 149 status_.crypto_has_pending_keys = has_pending_keys; | |
| 150 } | |
| 151 | |
| 152 void AllStatus::SetUniqueId(const std::string& guid) { | |
| 153 ScopedStatusLock lock(this); | |
| 154 status_.unique_id = guid; | |
| 155 } | |
| 156 | |
| 157 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) | |
| 158 : allstatus_(allstatus) { | |
| 159 allstatus->mutex_.Acquire(); | |
| 160 } | |
| 161 | |
| 162 ScopedStatusLock::~ScopedStatusLock() { | |
| 163 allstatus_->mutex_.Release(); | |
| 164 } | |
| 165 | |
| 166 } // namespace browser_sync | |
| OLD | NEW |