Chromium Code Reviews| 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::UNININITIALIZED; |
| 21 status_.initial_sync_ended = true; | |
| 22 status_.notifications_enabled = false; | 21 status_.notifications_enabled = false; |
| 23 status_.cryptographer_ready = false; | 22 status_.cryptographer_ready = false; |
| 24 status_.crypto_has_pending_keys = false; | 23 status_.crypto_has_pending_keys = false; |
| 25 } | 24 } |
| 26 | 25 |
| 27 AllStatus::~AllStatus() { | 26 AllStatus::~AllStatus() { |
| 28 } | 27 } |
| 29 | 28 |
| 30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { | 29 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { |
| 31 // Status is initialized with the previous status value. Variables | 30 // Status is initialized with the previous status value. Variables |
| 32 // whose values accumulate (e.g. lifetime counters like updates_received) | 31 // whose values accumulate (e.g. lifetime counters like updates_received) |
| 33 // are not to be cleared here. | 32 // are not to be cleared here. |
| 34 sync_api::SyncManager::Status status = status_; | 33 sync_api::SyncManager::Status status = status_; |
| 35 status.unsynced_count = 0; | 34 status.unsynced_count = 0; |
| 36 status.conflicting_count = 0; | 35 status.conflicting_count = 0; |
| 37 status.initial_sync_ended = false; | |
|
rlarocque
2012/02/02 22:44:13
How is this change related to the intentions descr
lipalani1
2012/02/03 01:55:39
I thought about it some more. I had few reasons fo
| |
| 38 status.max_consecutive_errors = 0; | 36 status.max_consecutive_errors = 0; |
| 39 status.updates_available = 0; | 37 status.updates_available = 0; |
| 40 return status; | 38 return status; |
| 41 } | 39 } |
| 42 | 40 |
| 43 sync_api::SyncManager::Status AllStatus::CalcSyncing( | 41 sync_api::SyncManager::Status AllStatus::CalcSyncing( |
| 44 const SyncEngineEvent &event) const { | 42 const SyncEngineEvent &event) const { |
| 45 sync_api::SyncManager::Status status = CreateBlankStatus(); | 43 sync_api::SyncManager::Status status = CreateBlankStatus(); |
| 46 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; | 44 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; |
| 47 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); | 45 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); |
| 48 status.conflicting_count += snapshot->errors.num_conflicting_commits; | 46 status.conflicting_count += snapshot->errors.num_conflicting_commits; |
| 49 // The syncer may not be done yet, which could cause conflicting updates. | 47 // The syncer may not be done yet, which could cause conflicting updates. |
| 50 // But this is only used for status, so it is better to have visibility. | 48 // But this is only used for status, so it is better to have visibility. |
| 51 status.conflicting_count += snapshot->num_conflicting_updates; | 49 status.conflicting_count += snapshot->num_conflicting_updates; |
| 52 | 50 |
| 53 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { | 51 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { |
| 54 status.syncing = true; | 52 status.syncing = true; |
| 55 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 53 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| 56 status.syncing = false; | 54 status.syncing = false; |
| 57 } | 55 } |
| 58 | 56 |
| 59 status.initial_sync_ended |= snapshot->is_share_usable; | |
| 60 | |
| 61 const sessions::ErrorCounters& errors(snapshot->errors); | 57 const sessions::ErrorCounters& errors(snapshot->errors); |
| 62 if (errors.consecutive_errors > status.max_consecutive_errors) | 58 if (errors.consecutive_errors > status.max_consecutive_errors) |
| 63 status.max_consecutive_errors = errors.consecutive_errors; | 59 status.max_consecutive_errors = errors.consecutive_errors; |
| 64 | 60 |
| 65 status.updates_available += snapshot->num_server_changes_remaining; | 61 status.updates_available += snapshot->num_server_changes_remaining; |
| 66 status.sync_protocol_error = snapshot->errors.sync_protocol_error; | 62 status.sync_protocol_error = snapshot->errors.sync_protocol_error; |
| 67 | 63 |
| 68 // Accumulate update count only once per session to avoid double-counting. | 64 // Accumulate update count only once per session to avoid double-counting. |
| 69 // TODO(ncarter): Make this realtime by having the syncer_status | 65 // TODO(ncarter): Make this realtime by having the syncer_status |
| 70 // counter preserve its value across sessions. http://crbug.com/26339 | 66 // counter preserve its value across sessions. http://crbug.com/26339 |
| 71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 67 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
| 68 ++status.sync_count; | |
| 72 status.updates_received += | 69 status.updates_received += |
| 73 snapshot->syncer_status.num_updates_downloaded_total; | 70 snapshot->syncer_status.num_updates_downloaded_total; |
| 74 status.tombstone_updates_received += | 71 status.tombstone_updates_received += |
| 75 snapshot->syncer_status.num_tombstone_updates_downloaded_total; | 72 snapshot->syncer_status.num_tombstone_updates_downloaded_total; |
| 76 status.num_local_overwrites_total += | 73 status.num_local_overwrites_total += |
| 77 snapshot->syncer_status.num_local_overwrites; | 74 snapshot->syncer_status.num_local_overwrites; |
| 78 status.num_server_overwrites_total += | 75 status.num_server_overwrites_total += |
| 79 snapshot->syncer_status.num_server_overwrites; | 76 snapshot->syncer_status.num_server_overwrites; |
| 80 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { | 77 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { |
| 81 ++status.empty_get_updates; | 78 ++status.empty_get_updates; |
| 82 } else { | 79 } else { |
| 83 ++status.nonempty_get_updates; | 80 ++status.nonempty_get_updates; |
| 84 } | 81 } |
| 85 if (snapshot->syncer_status.num_successful_commits == 0 && | 82 if (snapshot->syncer_status.num_successful_commits == 0 && |
| 86 snapshot->syncer_status.num_updates_downloaded_total == 0) { | 83 snapshot->syncer_status.num_updates_downloaded_total == 0) { |
| 87 ++status.useless_sync_cycles; | 84 ++status.useless_sync_cycles; |
| 88 } else { | 85 } else { |
| 89 ++status.useful_sync_cycles; | 86 ++status.useful_sync_cycles; |
| 90 } | 87 } |
| 91 } | 88 } |
| 92 return status; | 89 return status; |
| 93 } | 90 } |
| 94 | 91 |
| 95 void AllStatus::CalcStatusChanges() { | 92 void AllStatus::CalcStatusChanges() { |
| 96 const bool unsynced_changes = status_.unsynced_count > 0; | 93 const bool unsynced_changes = status_.unsynced_count > 0; |
| 97 const bool online = status_.authenticated && | 94 const bool online = status_.sync_count > 0 && status_.authenticated && |
| 98 status_.server_reachable && status_.server_up; | 95 status_.server_reachable && status_.server_up; |
| 99 if (online) { | 96 if (online) { |
| 100 if (status_.syncing) | 97 if (status_.syncing) |
| 101 status_.summary = sync_api::SyncManager::Status::SYNCING; | 98 status_.summary = sync_api::SyncManager::Status::SYNCING; |
| 102 else | 99 else |
| 103 status_.summary = sync_api::SyncManager::Status::READY; | 100 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) { | 101 } else if (unsynced_changes) { |
| 107 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; | 102 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; |
| 108 } else { | 103 } else if (status_.sync_count > 0) { |
| 109 status_.summary = sync_api::SyncManager::Status::OFFLINE; | 104 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; |
|
rlarocque
2012/02/02 22:44:13
Why? This would make the OFFLINE_UNSYNCED branch
lipalani1
2012/02/03 01:55:39
If you look at the comments for this enum OFFLINE
rlarocque
2012/02/03 18:55:03
OK, but this is still a big change to the definiti
| |
| 110 } | 105 } |
|
rlarocque
2012/02/02 22:44:13
For completeness, I'd like to see an else branch t
lipalani1
2012/02/03 01:55:39
Done.
| |
| 111 } | 106 } |
| 112 | 107 |
| 113 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { | 108 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { |
| 114 ScopedStatusLock lock(this); | 109 ScopedStatusLock lock(this); |
| 115 switch (event.what_happened) { | 110 switch (event.what_happened) { |
| 116 case SyncEngineEvent::SYNC_CYCLE_BEGIN: | 111 case SyncEngineEvent::SYNC_CYCLE_BEGIN: |
| 117 case SyncEngineEvent::STATUS_CHANGED: | 112 case SyncEngineEvent::STATUS_CHANGED: |
| 118 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 113 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
| 119 status_ = CalcSyncing(event); | 114 status_ = CalcSyncing(event); |
| 120 break; | 115 break; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 : allstatus_(allstatus) { | 185 : allstatus_(allstatus) { |
| 191 allstatus->mutex_.Acquire(); | 186 allstatus->mutex_.Acquire(); |
| 192 } | 187 } |
| 193 | 188 |
| 194 ScopedStatusLock::~ScopedStatusLock() { | 189 ScopedStatusLock::~ScopedStatusLock() { |
| 195 allstatus_->CalcStatusChanges(); | 190 allstatus_->CalcStatusChanges(); |
| 196 allstatus_->mutex_.Release(); | 191 allstatus_->mutex_.Release(); |
| 197 } | 192 } |
| 198 | 193 |
| 199 } // namespace browser_sync | 194 } // namespace browser_sync |
| OLD | NEW |