diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 00:10:01 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 00:10:01 +0000 |
commit | e9769df52561fdbe20a662b8f162563d2427e2e3 (patch) | |
tree | 52581981680f76e849aa37f59902ab4d727e632e /chrome/browser/sync | |
parent | 97ff82441b7ab9cf2aae383667ab216c30f2fb03 (diff) | |
download | chromium_src-e9769df52561fdbe20a662b8f162563d2427e2e3.zip chromium_src-e9769df52561fdbe20a662b8f162563d2427e2e3.tar.gz chromium_src-e9769df52561fdbe20a662b8f162563d2427e2e3.tar.bz2 |
[Sync] Replace TalkMediator delegate handling with thread-safe observer lists
Speculative fix for crash in bug.
BUG=chromium-os:7797
TEST=Manually with bug repro
Review URL: http://codereview.chromium.org/3837002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/notifier/server_notifier_thread.cc | 57 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/server_notifier_thread.h | 16 |
2 files changed, 19 insertions, 54 deletions
diff --git a/chrome/browser/sync/notifier/server_notifier_thread.cc b/chrome/browser/sync/notifier/server_notifier_thread.cc index 5251255..4c73445 100644 --- a/chrome/browser/sync/notifier/server_notifier_thread.cc +++ b/chrome/browser/sync/notifier/server_notifier_thread.cc @@ -19,10 +19,13 @@ ServerNotifierThread::ServerNotifierThread( const notifier::NotifierOptions& notifier_options, const std::string& state, StateWriter* state_writer) : notifier::MediatorThreadImpl(notifier_options), - state_(state), state_writer_(state_writer) { + state_(state), + state_writers_(new ObserverListThreadSafe<StateWriter>()), + state_writer_(state_writer) { DCHECK_EQ(notifier::NOTIFICATION_SERVER, notifier_options.notification_method); DCHECK(state_writer_); + state_writers_->AddObserver(state_writer_); } ServerNotifierThread::~ServerNotifierThread() {} @@ -46,6 +49,7 @@ void ServerNotifierThread::SubscribeForUpdates( void ServerNotifierThread::Logout() { DCHECK_EQ(MessageLoop::current(), parent_message_loop_); + state_writers_->RemoveObserver(state_writer_); state_writer_ = NULL; worker_message_loop()->PostTask( FROM_HERE, @@ -72,31 +76,23 @@ void ServerNotifierThread::OnInvalidate(syncable::ModelType model_type) { LOG(INFO) << "OnInvalidate: " << syncable::ModelTypeToString(model_type); } // TODO(akalin): Signal notification only for the invalidated types. - parent_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &ServerNotifierThread::SignalIncomingNotification)); + // TODO(akalin): Fill this in with something meaningful. + IncomingNotificationData notification_data; + observers_->Notify(&Observer::OnIncomingNotification, notification_data); } void ServerNotifierThread::OnInvalidateAll() { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); LOG(INFO) << "OnInvalidateAll"; - parent_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &ServerNotifierThread::SignalIncomingNotification)); + // TODO(akalin): Fill this in with something meaningful. + IncomingNotificationData notification_data; + observers_->Notify(&Observer::OnIncomingNotification, notification_data); } void ServerNotifierThread::WriteState(const std::string& state) { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); VLOG(1) << "WriteState"; - parent_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &ServerNotifierThread::SignalWriteState, state)); + state_writers_->Notify(&StateWriter::WriteState, state); } void ServerNotifierThread::OnDisconnect() { @@ -132,34 +128,7 @@ void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { return; } chrome_invalidation_client_->RegisterTypes(); - parent_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &ServerNotifierThread::SignalSubscribed)); -} - -void ServerNotifierThread::SignalSubscribed() { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); - if (delegate_) { - delegate_->OnSubscriptionStateChange(true); - } -} - -void ServerNotifierThread::SignalIncomingNotification() { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); - if (delegate_) { - // TODO(akalin): Fill this in with something meaningful. - IncomingNotificationData notification_data; - delegate_->OnIncomingNotification(notification_data); - } -} - -void ServerNotifierThread::SignalWriteState(const std::string& state) { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); - if (state_writer_) { - state_writer_->WriteState(state); - } + observers_->Notify(&Observer::OnSubscriptionStateChange, true); } void ServerNotifierThread::StopInvalidationListener() { diff --git a/chrome/browser/sync/notifier/server_notifier_thread.h b/chrome/browser/sync/notifier/server_notifier_thread.h index 5e48379..76ec4f1 100644 --- a/chrome/browser/sync/notifier/server_notifier_thread.h +++ b/chrome/browser/sync/notifier/server_notifier_thread.h @@ -16,6 +16,8 @@ #include <string> #include <vector> +#include "base/observer_list_threadsafe.h" +#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" #include "chrome/browser/sync/notifier/state_writer.h" @@ -73,21 +75,15 @@ class ServerNotifierThread // Posted to the worker thread by SubscribeForUpdates(). void RegisterTypesAndSignalSubscribed(); - // Signal to the delegate that we're subscribed. - void SignalSubscribed(); - - // Signal to the delegate that we have an incoming notification. - void SignalIncomingNotification(); - - // Signal to the delegate to write the state. - void SignalWriteState(const std::string& state); - // Called by StartInvalidationListener() and posted to the worker // thread by Stop(). void StopInvalidationListener(); std::string state_; - // May be NULL. + // Hack to get the nice thread-safe behavior for |state_writer_|. + scoped_refptr<ObserverListThreadSafe<StateWriter> > state_writers_; + // We still need to keep |state_writer_| around to remove it from + // |state_writers_|. StateWriter* state_writer_; scoped_ptr<ChromeInvalidationClient> chrome_invalidation_client_; }; |