| 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 "chrome/browser/sync/engine/auth_watcher.h" | |
| 12 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 11 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 13 #include "chrome/browser/sync/engine/syncer.h" | 12 #include "chrome/browser/sync/engine/syncer.h" |
| 14 #include "chrome/browser/sync/engine/syncer_thread.h" | 13 #include "chrome/browser/sync/engine/syncer_thread.h" |
| 15 #include "chrome/browser/sync/protocol/service_constants.h" | 14 #include "chrome/browser/sync/protocol/service_constants.h" |
| 16 #include "chrome/browser/sync/sessions/session_state.h" | 15 #include "chrome/browser/sync/sessions/session_state.h" |
| 17 #include "chrome/browser/sync/syncable/directory_manager.h" | 16 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 18 #include "chrome/common/deprecated/event_sys-inl.h" | 17 #include "chrome/common/deprecated/event_sys-inl.h" |
| 19 #include "jingle/notifier/listener/talk_mediator.h" | 18 #include "jingle/notifier/listener/talk_mediator.h" |
| 20 | 19 |
| 21 namespace browser_sync { | 20 namespace browser_sync { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 channel_(new Channel(shutdown_event)) { | 40 channel_(new Channel(shutdown_event)) { |
| 42 status_.initial_sync_ended = true; | 41 status_.initial_sync_ended = true; |
| 43 status_.notifications_enabled = false; | 42 status_.notifications_enabled = false; |
| 44 } | 43 } |
| 45 | 44 |
| 46 AllStatus::~AllStatus() { | 45 AllStatus::~AllStatus() { |
| 47 syncer_thread_hookup_.reset(); | 46 syncer_thread_hookup_.reset(); |
| 48 delete channel_; | 47 delete channel_; |
| 49 } | 48 } |
| 50 | 49 |
| 51 void AllStatus::WatchConnectionManager(ServerConnectionManager* conn_mgr) { | |
| 52 conn_mgr_hookup_.reset(NewEventListenerHookup(conn_mgr->channel(), this, | |
| 53 &AllStatus::HandleServerConnectionEvent)); | |
| 54 } | |
| 55 | |
| 56 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) { | 50 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) { |
| 57 syncer_thread_hookup_.reset(syncer_thread == NULL ? NULL : | 51 syncer_thread_hookup_.reset(syncer_thread == NULL ? NULL : |
| 58 syncer_thread->relay_channel()->AddObserver(this)); | 52 syncer_thread->relay_channel()->AddObserver(this)); |
| 59 } | 53 } |
| 60 | 54 |
| 61 AllStatus::Status AllStatus::CreateBlankStatus() const { | 55 AllStatus::Status AllStatus::CreateBlankStatus() const { |
| 62 Status status = status_; | 56 Status status = status_; |
| 63 status.syncing = true; | 57 status.syncing = true; |
| 64 status.unsynced_count = 0; | 58 status.unsynced_count = 0; |
| 65 status.conflicting_count = 0; | 59 status.conflicting_count = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 92 | 86 |
| 93 // 100 is an arbitrary limit. | 87 // 100 is an arbitrary limit. |
| 94 if (errors.consecutive_transient_error_commits > 100) | 88 if (errors.consecutive_transient_error_commits > 100) |
| 95 status.server_broken = true; | 89 status.server_broken = true; |
| 96 | 90 |
| 97 status.updates_available += snapshot->num_server_changes_remaining; | 91 status.updates_available += snapshot->num_server_changes_remaining; |
| 98 status.updates_received += snapshot->max_local_timestamp; | 92 status.updates_received += snapshot->max_local_timestamp; |
| 99 return status; | 93 return status; |
| 100 } | 94 } |
| 101 | 95 |
| 102 AllStatus::Status AllStatus::CalcSyncing() const { | |
| 103 return CreateBlankStatus(); | |
| 104 } | |
| 105 | |
| 106 int AllStatus::CalcStatusChanges(Status* old_status) { | 96 int AllStatus::CalcStatusChanges(Status* old_status) { |
| 107 int what_changed = 0; | 97 int what_changed = 0; |
| 108 | 98 |
| 109 // Calculate what changed and what the new icon should be. | 99 // Calculate what changed and what the new icon should be. |
| 110 if (status_.syncing != old_status->syncing) | 100 if (status_.syncing != old_status->syncing) |
| 111 what_changed |= AllStatusEvent::SYNCING; | 101 what_changed |= AllStatusEvent::SYNCING; |
| 112 if (status_.unsynced_count != old_status->unsynced_count) | 102 if (status_.unsynced_count != old_status->unsynced_count) |
| 113 what_changed |= AllStatusEvent::UNSYNCED_COUNT; | 103 what_changed |= AllStatusEvent::UNSYNCED_COUNT; |
| 114 if (status_.server_up != old_status->server_up) | 104 if (status_.server_up != old_status->server_up) |
| 115 what_changed |= AllStatusEvent::SERVER_UP; | 105 what_changed |= AllStatusEvent::SERVER_UP; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 146 | 136 |
| 147 if (status_.icon != old_status->icon) | 137 if (status_.icon != old_status->icon) |
| 148 what_changed |= AllStatusEvent::ICON; | 138 what_changed |= AllStatusEvent::ICON; |
| 149 | 139 |
| 150 if (0 == what_changed) | 140 if (0 == what_changed) |
| 151 return 0; | 141 return 0; |
| 152 *old_status = status_; | 142 *old_status = status_; |
| 153 return what_changed; | 143 return what_changed; |
| 154 } | 144 } |
| 155 | 145 |
| 156 void AllStatus::HandleAuthWatcherEvent(const AuthWatcherEvent& auth_event) { | |
| 157 ScopedStatusLockWithNotify lock(this); | |
| 158 switch (auth_event.what_happened) { | |
| 159 case AuthWatcherEvent::GAIA_AUTH_FAILED: | |
| 160 case AuthWatcherEvent::SERVICE_AUTH_FAILED: | |
| 161 case AuthWatcherEvent::SERVICE_CONNECTION_FAILED: | |
| 162 case AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START: | |
| 163 status_.authenticated = false; | |
| 164 break; | |
| 165 case AuthWatcherEvent::AUTH_SUCCEEDED: | |
| 166 // If we've already calculated that the server is reachable, since we've | |
| 167 // successfully authenticated, we can be confident that the server is up. | |
| 168 if (status_.server_reachable) | |
| 169 status_.server_up = true; | |
| 170 | |
| 171 if (!status_.authenticated) { | |
| 172 status_.authenticated = true; | |
| 173 status_ = CalcSyncing(); | |
| 174 } else { | |
| 175 lock.set_notify_plan(DONT_NOTIFY); | |
| 176 } | |
| 177 break; | |
| 178 default: | |
| 179 lock.set_notify_plan(DONT_NOTIFY); | |
| 180 break; | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void AllStatus::HandleChannelEvent(const SyncerEvent& event) { | 146 void AllStatus::HandleChannelEvent(const SyncerEvent& event) { |
| 185 ScopedStatusLockWithNotify lock(this); | 147 ScopedStatusLockWithNotify lock(this); |
| 186 switch (event.what_happened) { | 148 switch (event.what_happened) { |
| 187 case SyncerEvent::COMMITS_SUCCEEDED: | 149 case SyncerEvent::COMMITS_SUCCEEDED: |
| 188 break; | 150 break; |
| 189 case SyncerEvent::SYNC_CYCLE_ENDED: | 151 case SyncerEvent::SYNC_CYCLE_ENDED: |
| 190 case SyncerEvent::STATUS_CHANGED: | 152 case SyncerEvent::STATUS_CHANGED: |
| 191 status_ = CalcSyncing(event); | 153 status_ = CalcSyncing(event); |
| 192 break; | 154 break; |
| 193 case SyncerEvent::SHUTDOWN_USE_WITH_CARE: | 155 case SyncerEvent::SHUTDOWN_USE_WITH_CARE: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 215 break; | 177 break; |
| 216 } | 178 } |
| 217 } | 179 } |
| 218 | 180 |
| 219 void AllStatus::HandleServerConnectionEvent( | 181 void AllStatus::HandleServerConnectionEvent( |
| 220 const ServerConnectionEvent& event) { | 182 const ServerConnectionEvent& event) { |
| 221 if (ServerConnectionEvent::STATUS_CHANGED == event.what_happened) { | 183 if (ServerConnectionEvent::STATUS_CHANGED == event.what_happened) { |
| 222 ScopedStatusLockWithNotify lock(this); | 184 ScopedStatusLockWithNotify lock(this); |
| 223 status_.server_up = IsGoodReplyFromServer(event.connection_code); | 185 status_.server_up = IsGoodReplyFromServer(event.connection_code); |
| 224 status_.server_reachable = event.server_reachable; | 186 status_.server_reachable = event.server_reachable; |
| 187 |
| 188 if (event.connection_code == HttpResponse::SERVER_CONNECTION_OK) { |
| 189 if (!status_.authenticated) { |
| 190 status_ = CreateBlankStatus(); |
| 191 } |
| 192 status_.authenticated = true; |
| 193 } else { |
| 194 status_.authenticated = false; |
| 195 } |
| 225 } | 196 } |
| 226 } | 197 } |
| 227 | 198 |
| 228 AllStatus::Status AllStatus::status() const { | 199 AllStatus::Status AllStatus::status() const { |
| 229 AutoLock lock(mutex_); | 200 AutoLock lock(mutex_); |
| 230 return status_; | 201 return status_; |
| 231 } | 202 } |
| 232 | 203 |
| 233 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | 204 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { |
| 234 ScopedStatusLockWithNotify lock(this); | 205 ScopedStatusLockWithNotify lock(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 261 allstatus_->mutex_.Release(); | 232 allstatus_->mutex_.Release(); |
| 262 if (event_.what_changed) | 233 if (event_.what_changed) |
| 263 allstatus_->channel()->NotifyListeners(event_); | 234 allstatus_->channel()->NotifyListeners(event_); |
| 264 } | 235 } |
| 265 | 236 |
| 266 void ScopedStatusLockWithNotify::NotifyOverQuota() { | 237 void ScopedStatusLockWithNotify::NotifyOverQuota() { |
| 267 event_.what_changed |= AllStatusEvent::OVER_QUOTA; | 238 event_.what_changed |= AllStatusEvent::OVER_QUOTA; |
| 268 } | 239 } |
| 269 | 240 |
| 270 } // namespace browser_sync | 241 } // namespace browser_sync |
| OLD | NEW |