diff options
author | raz@chromium.org <raz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 17:55:50 +0000 |
---|---|---|
committer | raz@chromium.org <raz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 17:55:50 +0000 |
commit | 990de36904afa4af6bd23728cd5fae8468593d30 (patch) | |
tree | 538d168fa02e533899cbb15ca8c840e8e5a010b4 /chrome/browser/sync/profile_sync_service.cc | |
parent | 26edf1d3c373fe9b6044b57fc218a5f20bb65cda (diff) | |
download | chromium_src-990de36904afa4af6bd23728cd5fae8468593d30.zip chromium_src-990de36904afa4af6bd23728cd5fae8468593d30.tar.gz chromium_src-990de36904afa4af6bd23728cd5fae8468593d30.tar.bz2 |
Add timeout to clearing server data
Background: the sync nudge infrastructure is highly tuned for sync scenarios -- a fire-and-forget nudge is sent tothe sync thread which kicks off sync. If the syncer is disconnected, throttled, paused, etc, then the nudge is dropped as a sync cannot happen.
Problem: one-shot commands such as clearing server data can also be dropped without any acknowledgment, which means that the UI is never updated. There were a few alternatives for fixing this: 1) threading the clear through, 2) adding a timeout, or 3) fixing the nudge infrastructure to support more reliable messaging semantics. #3 was the ideal choice, however not doable for M8. Until the syncer is redesigned, #2 is our stop-gap solution.
On success, sync is disabled and the dialog dialog is closed. We do not care if a timeout event occurred thereafter, and theres no reason to show an error message to the user at that point. A similar situation exists if you are looking at the dialog and someone clears from another browser: the dialog closes itself without warning and without regard to any local requests to clear.
BUG=57360
TEST=
Review URL: http://codereview.chromium.org/3720001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/profile_sync_service.cc')
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 276ad22..41069c8 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -56,6 +56,8 @@ const char* ProfileSyncService::kSyncServerUrl = const char* ProfileSyncService::kDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; +static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. + ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, Profile* profile, const std::string& cros_user) @@ -445,6 +447,9 @@ void ProfileSyncService::Shutdown(bool sync_disabled) { void ProfileSyncService::ClearServerData() { clear_server_data_state_ = CLEAR_CLEARING; + clear_server_data_timer_.Start( + base::TimeDelta::FromSeconds(kSyncClearDataTimeoutInSeconds), this, + &ProfileSyncService::OnClearServerDataTimeout); backend_->RequestClearServerData(); } @@ -606,14 +611,36 @@ void ProfileSyncService::OnStopSyncingPermanently() { DisableForUser(); } +void ProfileSyncService::OnClearServerDataTimeout() { + if (clear_server_data_state_ != CLEAR_SUCCEEDED && + clear_server_data_state_ != CLEAR_FAILED) { + clear_server_data_state_ = CLEAR_FAILED; + FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); + } +} + void ProfileSyncService::OnClearServerDataFailed() { - clear_server_data_state_ = CLEAR_FAILED; - FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); + clear_server_data_timer_.Stop(); + + // Only once clear has succeeded there is no longer a need to transition to + // a failed state as sync is disabled locally. Also, no need to fire off + // the observers if the state didn't change (i.e. it was FAILED before). + if (clear_server_data_state_ != CLEAR_SUCCEEDED && + clear_server_data_state_ != CLEAR_FAILED) { + clear_server_data_state_ = CLEAR_FAILED; + FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); + } } void ProfileSyncService::OnClearServerDataSucceeded() { - clear_server_data_state_ = CLEAR_SUCCEEDED; - FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); + clear_server_data_timer_.Stop(); + + // Even if the timout fired, we still transition to the succeeded state as + // we want UI to update itself and no longer allow the user to press "clear" + if (clear_server_data_state_ != CLEAR_SUCCEEDED) { + clear_server_data_state_ = CLEAR_SUCCEEDED; + FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); + } } void ProfileSyncService::ShowLoginDialog(gfx::NativeWindow parent_window) { |