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