| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "chrome/browser/sync/engine/auth_watcher.h" | 12 #include "chrome/browser/sync/engine/auth_watcher.h" |
| 13 #include "chrome/browser/sync/engine/net/gaia_authenticator.h" | 13 #include "chrome/browser/sync/engine/net/gaia_authenticator.h" |
| 14 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 14 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 15 #include "chrome/browser/sync/engine/syncer.h" | 15 #include "chrome/browser/sync/engine/syncer.h" |
| 16 #include "chrome/browser/sync/engine/syncer_thread.h" | 16 #include "chrome/browser/sync/engine/syncer_thread.h" |
| 17 #include "chrome/browser/sync/engine/syncproto.h" | 17 #include "chrome/browser/sync/engine/syncproto.h" |
| 18 #include "chrome/browser/sync/notifier/listener/talk_mediator.h" | 18 #include "chrome/browser/sync/notifier/listener/talk_mediator.h" |
| 19 #include "chrome/browser/sync/protocol/service_constants.h" | 19 #include "chrome/browser/sync/protocol/service_constants.h" |
| 20 #include "chrome/browser/sync/sessions/session_state.h" |
| 20 #include "chrome/browser/sync/syncable/directory_manager.h" | 21 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 21 #include "chrome/browser/sync/util/event_sys-inl.h" | 22 #include "chrome/browser/sync/util/event_sys-inl.h" |
| 22 | 23 |
| 23 namespace browser_sync { | 24 namespace browser_sync { |
| 24 | 25 |
| 25 static const time_t kMinSyncObserveInterval = 10; // seconds | 26 static const time_t kMinSyncObserveInterval = 10; // seconds |
| 26 | 27 |
| 27 // Backoff interval randomization factor. | 28 // Backoff interval randomization factor. |
| 28 static const int kBackoffRandomizationFactor = 2; | 29 static const int kBackoffRandomizationFactor = 2; |
| 29 | 30 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 66 } |
| 66 | 67 |
| 67 void AllStatus::WatchAuthWatcher(AuthWatcher* auth_watcher) { | 68 void AllStatus::WatchAuthWatcher(AuthWatcher* auth_watcher) { |
| 68 authwatcher_hookup_.reset( | 69 authwatcher_hookup_.reset( |
| 69 NewEventListenerHookup(auth_watcher->channel(), this, | 70 NewEventListenerHookup(auth_watcher->channel(), this, |
| 70 &AllStatus::HandleAuthWatcherEvent)); | 71 &AllStatus::HandleAuthWatcherEvent)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) { | 74 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) { |
| 74 syncer_thread_hookup_.reset( | 75 syncer_thread_hookup_.reset( |
| 75 NewEventListenerHookup(syncer_thread->channel(), this, | 76 NewEventListenerHookup(syncer_thread->relay_channel(), this, |
| 76 &AllStatus::HandleSyncerEvent)); | 77 &AllStatus::HandleSyncerEvent)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 AllStatus::Status AllStatus::CreateBlankStatus() const { | 80 AllStatus::Status AllStatus::CreateBlankStatus() const { |
| 80 Status status = status_; | 81 Status status = status_; |
| 81 status.syncing = true; | 82 status.syncing = true; |
| 82 status.unsynced_count = 0; | 83 status.unsynced_count = 0; |
| 83 status.conflicting_count = 0; | 84 status.conflicting_count = 0; |
| 84 status.initial_sync_ended = false; | 85 status.initial_sync_ended = false; |
| 85 status.syncer_stuck = false; | 86 status.syncer_stuck = false; |
| 86 status.max_consecutive_errors = 0; | 87 status.max_consecutive_errors = 0; |
| 87 status.server_broken = false; | 88 status.server_broken = false; |
| 88 status.updates_available = 0; | 89 status.updates_available = 0; |
| 89 status.updates_received = 0; | 90 status.updates_received = 0; |
| 90 return status; | 91 return status; |
| 91 } | 92 } |
| 92 | 93 |
| 93 AllStatus::Status AllStatus::CalcSyncing(const SyncerEvent &event) const { | 94 AllStatus::Status AllStatus::CalcSyncing(const SyncerEvent &event) const { |
| 94 Status status = CreateBlankStatus(); | 95 Status status = CreateBlankStatus(); |
| 95 SyncerStatus syncerStatus(event.last_session); | 96 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; |
| 96 status.unsynced_count += static_cast<int>(syncerStatus.unsynced_count()); | 97 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); |
| 97 status.conflicting_count += syncerStatus.conflicting_commits(); | 98 status.conflicting_count += snapshot->errors.num_conflicting_commits; |
| 98 // The syncer may not be done yet, which could cause conflicting updates. | 99 // The syncer may not be done yet, which could cause conflicting updates. |
| 99 // But this is only used for status, so it is better to have visibility. | 100 // But this is only used for status, so it is better to have visibility. |
| 100 status.conflicting_count += syncerStatus.conflicting_updates(); | 101 status.conflicting_count += snapshot->num_conflicting_updates; |
| 101 | 102 |
| 102 status.syncing |= syncerStatus.syncing(); | 103 status.syncing |= snapshot->syncer_status.syncing; |
| 103 // Show a syncer as syncing if it's got stalled updates. | 104 status.syncing = snapshot->has_more_to_sync && snapshot->is_silenced; |
| 104 status.syncing = event.last_session->HasMoreToSync() && | 105 status.initial_sync_ended |= snapshot->is_share_usable; |
| 105 event.last_session->silenced_until().is_null(); | 106 status.syncer_stuck |= snapshot->syncer_status.syncer_stuck; |
| 106 status.initial_sync_ended |= syncerStatus.IsShareUsable(); | 107 |
| 107 status.syncer_stuck |= syncerStatus.syncer_stuck(); | 108 const sessions::ErrorCounters& errors(snapshot->errors); |
| 108 if (syncerStatus.consecutive_errors() > status.max_consecutive_errors) | 109 if (errors.consecutive_errors > status.max_consecutive_errors) |
| 109 status.max_consecutive_errors = syncerStatus.consecutive_errors(); | 110 status.max_consecutive_errors = errors.consecutive_errors; |
| 110 | 111 |
| 111 // 100 is an arbitrary limit. | 112 // 100 is an arbitrary limit. |
| 112 if (syncerStatus.consecutive_transient_error_commits() > 100) | 113 if (errors.consecutive_transient_error_commits > 100) |
| 113 status.server_broken = true; | 114 status.server_broken = true; |
| 114 | 115 |
| 115 status.updates_available += syncerStatus.num_server_changes_remaining(); | 116 const sessions::ChangelogProgress& progress(snapshot->changelog_progress); |
| 116 status.updates_received += syncerStatus.current_sync_timestamp(); | 117 status.updates_available += progress.num_server_changes_remaining; |
| 118 status.updates_received += progress.current_sync_timestamp; |
| 117 return status; | 119 return status; |
| 118 } | 120 } |
| 119 | 121 |
| 120 AllStatus::Status AllStatus::CalcSyncing() const { | 122 AllStatus::Status AllStatus::CalcSyncing() const { |
| 121 return CreateBlankStatus(); | 123 return CreateBlankStatus(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 int AllStatus::CalcStatusChanges(Status* old_status) { | 126 int AllStatus::CalcStatusChanges(Status* old_status) { |
| 125 int what_changed = 0; | 127 int what_changed = 0; |
| 126 | 128 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 allstatus_->mutex_.Release(); | 331 allstatus_->mutex_.Release(); |
| 330 if (event_.what_changed) | 332 if (event_.what_changed) |
| 331 allstatus_->channel()->NotifyListeners(event_); | 333 allstatus_->channel()->NotifyListeners(event_); |
| 332 } | 334 } |
| 333 | 335 |
| 334 void ScopedStatusLockWithNotify::NotifyOverQuota() { | 336 void ScopedStatusLockWithNotify::NotifyOverQuota() { |
| 335 event_.what_changed |= AllStatusEvent::OVER_QUOTA; | 337 event_.what_changed |= AllStatusEvent::OVER_QUOTA; |
| 336 } | 338 } |
| 337 | 339 |
| 338 } // namespace browser_sync | 340 } // namespace browser_sync |
| OLD | NEW |