summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/notifier
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 10:00:20 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 10:00:20 +0000
commitc540f5d9fa6840a17ffccc6a5898a84f45b670a3 (patch)
treef3b292f1691e1b8d6786623cc0c025d7a5e463c6 /chrome/browser/sync/notifier
parentfa4332dc5decca49028a64d123c49cc2f3417f2d (diff)
downloadchromium_src-c540f5d9fa6840a17ffccc6a5898a84f45b670a3.zip
chromium_src-c540f5d9fa6840a17ffccc6a5898a84f45b670a3.tar.gz
chromium_src-c540f5d9fa6840a17ffccc6a5898a84f45b670a3.tar.bz2
[Sync] Avoid reinitializing server notifier client on XMPP reconnect
Will be unit-tested in a separate CL. BUG=63857 TEST=Manual :( Review URL: http://codereview.chromium.org/5293001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/notifier')
-rw-r--r--chrome/browser/sync/notifier/chrome_invalidation_client.cc14
-rw-r--r--chrome/browser/sync/notifier/chrome_invalidation_client.h5
-rw-r--r--chrome/browser/sync/notifier/server_notifier_thread.cc45
-rw-r--r--chrome/browser/sync/notifier/server_notifier_thread.h8
4 files changed, 37 insertions, 35 deletions
diff --git a/chrome/browser/sync/notifier/chrome_invalidation_client.cc b/chrome/browser/sync/notifier/chrome_invalidation_client.cc
index 48cf3f4..0192371 100644
--- a/chrome/browser/sync/notifier/chrome_invalidation_client.cc
+++ b/chrome/browser/sync/notifier/chrome_invalidation_client.cc
@@ -38,7 +38,6 @@ void ChromeInvalidationClient::Start(
Listener* listener, StateWriter* state_writer,
base::WeakPtr<talk_base::Task> base_task) {
DCHECK(non_thread_safe_.CalledOnValidThread());
- DCHECK(base_task.get());
Stop();
chrome_system_resources_.StartScheduler();
@@ -64,14 +63,21 @@ void ChromeInvalidationClient::Start(
&chrome_system_resources_, client_type, client_id, client_config,
this));
invalidation_client_->Start(state);
- cache_invalidation_packet_handler_.reset(
- new CacheInvalidationPacketHandler(base_task,
- invalidation_client_.get()));
+ ChangeBaseTask(base_task);
registration_manager_.reset(
new RegistrationManager(invalidation_client_.get()));
RegisterTypes();
}
+void ChromeInvalidationClient::ChangeBaseTask(
+ base::WeakPtr<talk_base::Task> base_task) {
+ DCHECK(invalidation_client_.get());
+ DCHECK(base_task.get());
+ cache_invalidation_packet_handler_.reset(
+ new CacheInvalidationPacketHandler(base_task,
+ invalidation_client_.get()));
+}
+
void ChromeInvalidationClient::Stop() {
DCHECK(non_thread_safe_.CalledOnValidThread());
if (!invalidation_client_.get()) {
diff --git a/chrome/browser/sync/notifier/chrome_invalidation_client.h b/chrome/browser/sync/notifier/chrome_invalidation_client.h
index 53e37f8..e6219f7 100644
--- a/chrome/browser/sync/notifier/chrome_invalidation_client.h
+++ b/chrome/browser/sync/notifier/chrome_invalidation_client.h
@@ -59,6 +59,11 @@ class ChromeInvalidationClient
void Stop();
+ // Changes the task used to |base_task|, which must still be
+ // non-NULL. Must only be called between calls to Start() and
+ // Stop().
+ void ChangeBaseTask(base::WeakPtr<talk_base::Task> base_task);
+
// Register the sync types that we're interested in getting
// notifications for. Must only be called between calls to Start()
// and Stop().
diff --git a/chrome/browser/sync/notifier/server_notifier_thread.cc b/chrome/browser/sync/notifier/server_notifier_thread.cc
index ede1a47..24a1c47 100644
--- a/chrome/browser/sync/notifier/server_notifier_thread.cc
+++ b/chrome/browser/sync/notifier/server_notifier_thread.cc
@@ -34,8 +34,7 @@ void ServerNotifierThread::ListenForUpdates() {
DCHECK_EQ(MessageLoop::current(), parent_message_loop_);
worker_message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &ServerNotifierThread::StartInvalidationListener));
+ NewRunnableMethod(this, &ServerNotifierThread::DoListenForUpdates));
}
void ServerNotifierThread::SubscribeForUpdates(
@@ -97,38 +96,34 @@ void ServerNotifierThread::WriteState(const std::string& state) {
state_writers_->Notify(&StateWriter::WriteState, state);
}
-void ServerNotifierThread::OnDisconnect() {
- DCHECK_EQ(MessageLoop::current(), worker_message_loop());
- StopInvalidationListener();
- MediatorThreadImpl::OnDisconnect();
-}
-
-void ServerNotifierThread::StartInvalidationListener() {
+void ServerNotifierThread::DoListenForUpdates() {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
if (!base_task_.get()) {
return;
}
- StopInvalidationListener();
- chrome_invalidation_client_.reset(new ChromeInvalidationClient());
-
- // TODO(akalin): Make cache_guid() part of the client ID. If we do
- // so and we somehow propagate it up to the server somehow, we can
- // make it so that we won't receive any notifications that were
- // generated from our own changes.
- const std::string kClientId = "server_notifier_thread";
- chrome_invalidation_client_->Start(
- kClientId, state_, this, this, base_task_);
- state_.clear();
+ if (chrome_invalidation_client_.get()) {
+ // If we already have an invalidation client, simply change the
+ // base task.
+ chrome_invalidation_client_->ChangeBaseTask(base_task_);
+ } else {
+ // Otherwise, create the invalidation client.
+ chrome_invalidation_client_.reset(new ChromeInvalidationClient());
+
+ // TODO(akalin): Make cache_guid() part of the client ID. If we do
+ // so and we somehow propagate it up to the server somehow, we can
+ // make it so that we won't receive any notifications that were
+ // generated from our own changes.
+ const std::string kClientId = "server_notifier_thread";
+ chrome_invalidation_client_->Start(
+ kClientId, state_, this, this, base_task_);
+ state_.clear();
+ }
}
void ServerNotifierThread::RegisterTypesAndSignalSubscribed() {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
- // |chrome_invalidation_client_| can be NULL if we receive an
- // OnDisconnect() event after we gets posted but before we run.
- if (!chrome_invalidation_client_.get()) {
- return;
- }
+ DCHECK(chrome_invalidation_client_.get());
chrome_invalidation_client_->RegisterTypes();
observers_->Notify(&Observer::OnSubscriptionStateChange, true);
}
diff --git a/chrome/browser/sync/notifier/server_notifier_thread.h b/chrome/browser/sync/notifier/server_notifier_thread.h
index 76ec4f1..55b60fe 100644
--- a/chrome/browser/sync/notifier/server_notifier_thread.h
+++ b/chrome/browser/sync/notifier/server_notifier_thread.h
@@ -65,18 +65,14 @@ class ServerNotifierThread
// StateWriter implementation.
virtual void WriteState(const std::string& state);
- protected:
- virtual void OnDisconnect();
-
private:
// Posted to the worker thread by ListenForUpdates().
- void StartInvalidationListener();
+ void DoListenForUpdates();
// Posted to the worker thread by SubscribeForUpdates().
void RegisterTypesAndSignalSubscribed();
- // Called by StartInvalidationListener() and posted to the worker
- // thread by Stop().
+ // Posted to the worker thread by Logout().
void StopInvalidationListener();
std::string state_;