| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/engine/all_status.h" | 5 #include "chrome/browser/sync/engine/all_status.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/port.h" | 10 #include "base/port.h" |
| 11 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 11 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 12 #include "chrome/browser/sync/protocol/service_constants.h" | 12 #include "chrome/browser/sync/protocol/service_constants.h" |
| 13 #include "chrome/browser/sync/sessions/session_state.h" | 13 #include "chrome/browser/sync/sessions/session_state.h" |
| 14 #include "chrome/browser/sync/syncable/directory_manager.h" | 14 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 15 #include "chrome/browser/sync/syncable/model_type.h" | 15 #include "chrome/browser/sync/syncable/model_type.h" |
| 16 | 16 |
| 17 namespace browser_sync { | 17 namespace browser_sync { |
| 18 | 18 |
| 19 AllStatus::AllStatus() { | 19 AllStatus::AllStatus() { |
| 20 status_.summary = sync_api::SyncManager::Status::OFFLINE; | 20 status_.summary = sync_api::SyncManager::Status::UNINITIALIZED; |
| 21 status_.initial_sync_ended = true; | 21 status_.initial_sync_ended = true; |
| 22 status_.notifications_enabled = false; | 22 status_.notifications_enabled = false; |
| 23 status_.cryptographer_ready = false; | 23 status_.cryptographer_ready = false; |
| 24 status_.crypto_has_pending_keys = false; | 24 status_.crypto_has_pending_keys = false; |
| 25 } | 25 } |
| 26 | 26 |
| 27 AllStatus::~AllStatus() { | 27 AllStatus::~AllStatus() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { | 30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (errors.consecutive_errors > status.max_consecutive_errors) | 62 if (errors.consecutive_errors > status.max_consecutive_errors) |
| 63 status.max_consecutive_errors = errors.consecutive_errors; | 63 status.max_consecutive_errors = errors.consecutive_errors; |
| 64 | 64 |
| 65 status.updates_available += snapshot->num_server_changes_remaining; | 65 status.updates_available += snapshot->num_server_changes_remaining; |
| 66 status.sync_protocol_error = snapshot->errors.sync_protocol_error; | 66 status.sync_protocol_error = snapshot->errors.sync_protocol_error; |
| 67 | 67 |
| 68 // Accumulate update count only once per session to avoid double-counting. | 68 // Accumulate update count only once per session to avoid double-counting. |
| 69 // TODO(ncarter): Make this realtime by having the syncer_status | 69 // TODO(ncarter): Make this realtime by having the syncer_status |
| 70 // counter preserve its value across sessions. http://crbug.com/26339 | 70 // counter preserve its value across sessions. http://crbug.com/26339 |
| 71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| 72 ++status.sync_count; |
| 72 status.updates_received += | 73 status.updates_received += |
| 73 snapshot->syncer_status.num_updates_downloaded_total; | 74 snapshot->syncer_status.num_updates_downloaded_total; |
| 74 status.tombstone_updates_received += | 75 status.tombstone_updates_received += |
| 75 snapshot->syncer_status.num_tombstone_updates_downloaded_total; | 76 snapshot->syncer_status.num_tombstone_updates_downloaded_total; |
| 76 status.num_local_overwrites_total += | 77 status.num_local_overwrites_total += |
| 77 snapshot->syncer_status.num_local_overwrites; | 78 snapshot->syncer_status.num_local_overwrites; |
| 78 status.num_server_overwrites_total += | 79 status.num_server_overwrites_total += |
| 79 snapshot->syncer_status.num_server_overwrites; | 80 snapshot->syncer_status.num_server_overwrites; |
| 80 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { | 81 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { |
| 81 ++status.empty_get_updates; | 82 ++status.empty_get_updates; |
| 82 } else { | 83 } else { |
| 83 ++status.nonempty_get_updates; | 84 ++status.nonempty_get_updates; |
| 84 } | 85 } |
| 85 if (snapshot->syncer_status.num_successful_commits == 0 && | 86 if (snapshot->syncer_status.num_successful_commits == 0 && |
| 86 snapshot->syncer_status.num_updates_downloaded_total == 0) { | 87 snapshot->syncer_status.num_updates_downloaded_total == 0) { |
| 87 ++status.useless_sync_cycles; | 88 ++status.useless_sync_cycles; |
| 88 } else { | 89 } else { |
| 89 ++status.useful_sync_cycles; | 90 ++status.useful_sync_cycles; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 return status; | 93 return status; |
| 93 } | 94 } |
| 94 | 95 |
| 95 void AllStatus::CalcStatusChanges() { | 96 void AllStatus::CalcStatusChanges() { |
| 96 const bool unsynced_changes = status_.unsynced_count > 0; | 97 const bool unsynced_changes = status_.unsynced_count > 0; |
| 97 const bool online = status_.authenticated && | 98 const bool online = status_.sync_count > 0 && status_.authenticated && |
| 98 status_.server_reachable && status_.server_up; | 99 status_.server_reachable && status_.server_up; |
| 99 if (online) { | 100 if (online) { |
| 100 if (status_.syncing) | 101 if (status_.syncing) |
| 101 status_.summary = sync_api::SyncManager::Status::SYNCING; | 102 status_.summary = sync_api::SyncManager::Status::SYNCING; |
| 102 else | 103 else |
| 103 status_.summary = sync_api::SyncManager::Status::READY; | 104 status_.summary = sync_api::SyncManager::Status::READY; |
| 104 } else if (!status_.initial_sync_ended) { | |
| 105 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; | |
| 106 } else if (unsynced_changes) { | 105 } else if (unsynced_changes) { |
| 107 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; | 106 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; |
| 107 } else if (status_.sync_count > 0) { |
| 108 status_.summary = sync_api::SyncManager::Status::OFFLINE; |
| 108 } else { | 109 } else { |
| 109 status_.summary = sync_api::SyncManager::Status::OFFLINE; | 110 status_.summary = sync_api::SyncManager::Status::UNINITIALIZED; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { | 114 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { |
| 114 ScopedStatusLock lock(this); | 115 ScopedStatusLock lock(this); |
| 115 switch (event.what_happened) { | 116 switch (event.what_happened) { |
| 116 case SyncEngineEvent::SYNC_CYCLE_BEGIN: | 117 case SyncEngineEvent::SYNC_CYCLE_BEGIN: |
| 117 case SyncEngineEvent::STATUS_CHANGED: | 118 case SyncEngineEvent::STATUS_CHANGED: |
| 118 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 119 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
| 119 status_ = CalcSyncing(event); | 120 status_ = CalcSyncing(event); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 : allstatus_(allstatus) { | 191 : allstatus_(allstatus) { |
| 191 allstatus->mutex_.Acquire(); | 192 allstatus->mutex_.Acquire(); |
| 192 } | 193 } |
| 193 | 194 |
| 194 ScopedStatusLock::~ScopedStatusLock() { | 195 ScopedStatusLock::~ScopedStatusLock() { |
| 195 allstatus_->CalcStatusChanges(); | 196 allstatus_->CalcStatusChanges(); |
| 196 allstatus_->mutex_.Release(); | 197 allstatus_->mutex_.Release(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 } // namespace browser_sync | 200 } // namespace browser_sync |
| OLD | NEW |