diff options
50 files changed, 740 insertions, 748 deletions
diff --git a/chrome/browser/chrome_to_mobile_service.h b/chrome/browser/chrome_to_mobile_service.h index a71cac9..bb1dc4c 100644 --- a/chrome/browser/chrome_to_mobile_service.h +++ b/chrome/browser/chrome_to_mobile_service.h @@ -24,7 +24,7 @@ #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_fetcher_delegate.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidation_handler.h" class OAuth2AccessTokenFetcher; class Browser; @@ -43,7 +43,7 @@ class ChromeToMobileService : public ProfileKeyedService, public net::URLFetcherDelegate, public content::NotificationObserver, public OAuth2AccessTokenConsumer, - public syncer::SyncNotifierObserver { + public syncer::InvalidationHandler { public: class Observer { public: @@ -155,7 +155,7 @@ class ChromeToMobileService : public ProfileKeyedService, const base::Time& expiration_time) OVERRIDE; virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; - // syncer::SyncNotifierObserver implementation. + // syncer::InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( syncer::NotificationsDisabledReason reason) OVERRIDE; diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h index d964fa3..91182f38 100644 --- a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "base/threading/thread_checker.h" #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_mapper.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidation_handler.h" class InvalidationFrontend; @@ -24,7 +24,7 @@ class PushMessagingInvalidationHandlerDelegate; // invalidation registrations, and dispatches callbacks for any invalidations // received. class PushMessagingInvalidationHandler : public PushMessagingInvalidationMapper, - public syncer::SyncNotifierObserver { + public syncer::InvalidationHandler { public: // |service| and |delegate| must remain valid for the lifetime of this object. // |extension_ids| is the set of extension IDs for which push messaging is @@ -39,7 +39,7 @@ class PushMessagingInvalidationHandler : public PushMessagingInvalidationMapper, virtual void RegisterExtension(const std::string& extension_id) OVERRIDE; virtual void UnregisterExtension(const std::string& extension_id) OVERRIDE; - // SyncNotifierObserver implementation. + // InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( syncer::NotificationsDisabledReason reason) OVERRIDE; diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_unittest.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_unittest.cc index 289a6d9..2dd4ec3 100644 --- a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_unittest.cc +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_unittest.cc @@ -27,11 +27,11 @@ class MockInvalidationFrontend : public InvalidationFrontend { MockInvalidationFrontend(); ~MockInvalidationFrontend(); MOCK_METHOD1(RegisterInvalidationHandler, - void(syncer::SyncNotifierObserver*)); + void(syncer::InvalidationHandler*)); MOCK_METHOD2(UpdateRegisteredInvalidationIds, - void(syncer::SyncNotifierObserver*, const syncer::ObjectIdSet&)); + void(syncer::InvalidationHandler*, const syncer::ObjectIdSet&)); MOCK_METHOD1(UnregisterInvalidationHandler, - void(syncer::SyncNotifierObserver*)); + void(syncer::InvalidationHandler*)); private: DISALLOW_COPY_AND_ASSIGN(MockInvalidationFrontend); @@ -66,7 +66,7 @@ class PushMessagingInvalidationHandlerTest : public ::testing::Test { virtual void SetUpWithArgs(const std::set<std::string>& extension_ids, const syncer::ObjectIdSet& expected_ids) { InSequence seq; - syncer::SyncNotifierObserver* handler[2] = {}; + syncer::InvalidationHandler* handler[2] = {}; EXPECT_CALL(service_, RegisterInvalidationHandler(NotNull())) .WillOnce(SaveArg<0>(&handler[0])); EXPECT_CALL(service_, diff --git a/chrome/browser/sync/glue/bridged_sync_notifier.cc b/chrome/browser/sync/glue/bridged_invalidator.cc index f783418..14ecfa8 100644 --- a/chrome/browser/sync/glue/bridged_sync_notifier.cc +++ b/chrome/browser/sync/glue/bridged_invalidator.cc @@ -2,61 +2,61 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/sync/glue/bridged_sync_notifier.h" +#include "chrome/browser/sync/glue/bridged_invalidator.h" #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" namespace browser_sync { -BridgedSyncNotifier::BridgedSyncNotifier( +BridgedInvalidator::BridgedInvalidator( ChromeSyncNotificationBridge* bridge, - syncer::SyncNotifier* delegate) + syncer::Invalidator* delegate) : bridge_(bridge), delegate_(delegate) { DCHECK(bridge_); } -BridgedSyncNotifier::~BridgedSyncNotifier() { +BridgedInvalidator::~BridgedInvalidator() { } -void BridgedSyncNotifier::RegisterHandler( - syncer::SyncNotifierObserver* handler) { +void BridgedInvalidator::RegisterHandler( + syncer::InvalidationHandler* handler) { if (delegate_.get()) delegate_->RegisterHandler(handler); bridge_->RegisterHandler(handler); } -void BridgedSyncNotifier::UpdateRegisteredIds( - syncer::SyncNotifierObserver* handler, +void BridgedInvalidator::UpdateRegisteredIds( + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) { if (delegate_.get()) delegate_->UpdateRegisteredIds(handler, ids); bridge_->UpdateRegisteredIds(handler, ids); } -void BridgedSyncNotifier::UnregisterHandler( - syncer::SyncNotifierObserver* handler) { +void BridgedInvalidator::UnregisterHandler( + syncer::InvalidationHandler* handler) { if (delegate_.get()) delegate_->UnregisterHandler(handler); bridge_->UnregisterHandler(handler); } -void BridgedSyncNotifier::SetUniqueId(const std::string& unique_id) { +void BridgedInvalidator::SetUniqueId(const std::string& unique_id) { if (delegate_.get()) delegate_->SetUniqueId(unique_id); } -void BridgedSyncNotifier::SetStateDeprecated(const std::string& state) { +void BridgedInvalidator::SetStateDeprecated(const std::string& state) { if (delegate_.get()) delegate_->SetStateDeprecated(state); } -void BridgedSyncNotifier::UpdateCredentials( +void BridgedInvalidator::UpdateCredentials( const std::string& email, const std::string& token) { if (delegate_.get()) delegate_->UpdateCredentials(email, token); } -void BridgedSyncNotifier::SendNotification( +void BridgedInvalidator::SendNotification( syncer::ModelTypeSet changed_types) { if (delegate_.get()) delegate_->SendNotification(changed_types); diff --git a/chrome/browser/sync/glue/bridged_invalidator.h b/chrome/browser/sync/glue/bridged_invalidator.h new file mode 100644 index 0000000..73b1c0c --- /dev/null +++ b/chrome/browser/sync/glue/bridged_invalidator.h @@ -0,0 +1,54 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_GLUE_BRIDGED_INVALIDATOR_H_ +#define CHROME_BROWSER_SYNC_GLUE_BRIDGED_INVALIDATOR_H_ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "sync/notifier/invalidator.h" + +namespace browser_sync { + +class ChromeSyncNotificationBridge; + +// An Invalidator implementation that wraps a ChromeSyncNotificationBridge +// and optionally an Invalidator delegate (which it takes ownership of). +// All Invalidator calls are passed straight through to the delegate, +// with the exception of RegisterHandler, UpdateRegisteredIds, and +// UnregisterHandler, which result in the handler being registered, updated, +// and unregistered with the ChromeSyncNotificationBridge, respectively. +class BridgedInvalidator : public syncer::Invalidator { + public: + // Does not take ownership of |bridge|. Takes ownership of |delegate|. + // |delegate| may be NULL. + BridgedInvalidator(ChromeSyncNotificationBridge* bridge, + syncer::Invalidator* delegate); + virtual ~BridgedInvalidator(); + + // Invalidator implementation. Passes through all calls to the delegate. + // RegisterHandler, UpdateRegisteredIds, and UnregisterHandler calls will + // also be forwarded to the bridge. + virtual void RegisterHandler(syncer::InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredIds(syncer::InvalidationHandler * handler, + const syncer::ObjectIdSet& ids) OVERRIDE; + virtual void UnregisterHandler(syncer::InvalidationHandler* handler) OVERRIDE; + virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; + virtual void SetStateDeprecated(const std::string& state) OVERRIDE; + virtual void UpdateCredentials( + const std::string& email, const std::string& token) OVERRIDE; + virtual void SendNotification( + syncer::ModelTypeSet changed_types) OVERRIDE; + + private: + // The notification bridge that we register the observers with. + ChromeSyncNotificationBridge* bridge_; + + // The delegate we are wrapping. + scoped_ptr<syncer::Invalidator> delegate_; +}; + +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_GLUE_BRIDGED_INVALIDATOR_H_ diff --git a/chrome/browser/sync/glue/bridged_sync_notifier_unittest.cc b/chrome/browser/sync/glue/bridged_invalidator_unittest.cc index a816148..a472de4 100644 --- a/chrome/browser/sync/glue/bridged_sync_notifier_unittest.cc +++ b/chrome/browser/sync/glue/bridged_invalidator_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/sync/glue/bridged_sync_notifier.h" +#include "chrome/browser/sync/glue/bridged_invalidator.h" #include <string> @@ -14,9 +14,9 @@ #include "content/public/test/test_browser_thread.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_test_util.h" -#include "sync/notifier/fake_sync_notifier.h" -#include "sync/notifier/fake_sync_notifier_observer.h" -#include "sync/notifier/sync_notifier.h" +#include "sync/notifier/fake_invalidation_handler.h" +#include "sync/notifier/fake_invalidator.h" +#include "sync/notifier/invalidator.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -36,80 +36,80 @@ class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { : ChromeSyncNotificationBridge(profile, sync_task_runner) {} virtual ~MockChromeSyncNotificationBridge() {} - MOCK_METHOD1(RegisterHandler, void(syncer::SyncNotifierObserver*)); + MOCK_METHOD1(RegisterHandler, void(syncer::InvalidationHandler*)); MOCK_METHOD2(UpdateRegisteredIds, - void(syncer::SyncNotifierObserver*, + void(syncer::InvalidationHandler*, const syncer::ObjectIdSet&)); - MOCK_METHOD1(UnregisterHandler, void(syncer::SyncNotifierObserver*)); + MOCK_METHOD1(UnregisterHandler, void(syncer::InvalidationHandler*)); }; // All tests just verify that each call is passed through to the delegate, with // the exception of RegisterHandler, UnregisterHandler, and // UpdateRegisteredIds, which also verifies the call is forwarded to the // bridge. -class BridgedSyncNotifierTest : public testing::Test { +class BridgedInvalidatorTest : public testing::Test { public: - BridgedSyncNotifierTest() + BridgedInvalidatorTest() : ui_thread_(BrowserThread::UI, &ui_loop_), mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), - // Owned by bridged_notifier_. - fake_delegate_(new syncer::FakeSyncNotifier()), - bridged_notifier_(&mock_bridge_, fake_delegate_) {} - virtual ~BridgedSyncNotifierTest() {} + // Owned by bridged_invalidator_. + fake_delegate_(new syncer::FakeInvalidator()), + bridged_invalidator_(&mock_bridge_, fake_delegate_) {} + virtual ~BridgedInvalidatorTest() {} protected: MessageLoop ui_loop_; content::TestBrowserThread ui_thread_; NiceMock<ProfileMock> mock_profile_; StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; - syncer::FakeSyncNotifier* fake_delegate_; - BridgedSyncNotifier bridged_notifier_; + syncer::FakeInvalidator* fake_delegate_; + BridgedInvalidator bridged_invalidator_; }; -TEST_F(BridgedSyncNotifierTest, RegisterHandler) { +TEST_F(BridgedInvalidatorTest, RegisterHandler) { const syncer::ObjectIdSet& ids = syncer::ModelTypeSetToObjectIdSet( syncer::ModelTypeSet(syncer::APPS, syncer::PREFERENCES)); - syncer::FakeSyncNotifierObserver observer; - EXPECT_CALL(mock_bridge_, RegisterHandler(&observer)); - EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(&observer, ids)); - EXPECT_CALL(mock_bridge_, UnregisterHandler(&observer)); + syncer::FakeInvalidationHandler handler; + EXPECT_CALL(mock_bridge_, RegisterHandler(&handler)); + EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(&handler, ids)); + EXPECT_CALL(mock_bridge_, UnregisterHandler(&handler)); - bridged_notifier_.RegisterHandler(&observer); - EXPECT_TRUE(fake_delegate_->IsHandlerRegistered(&observer)); + bridged_invalidator_.RegisterHandler(&handler); + EXPECT_TRUE(fake_delegate_->IsHandlerRegistered(&handler)); - bridged_notifier_.UpdateRegisteredIds(&observer, ids); - EXPECT_EQ(ids, fake_delegate_->GetRegisteredIds(&observer)); + bridged_invalidator_.UpdateRegisteredIds(&handler, ids); + EXPECT_EQ(ids, fake_delegate_->GetRegisteredIds(&handler)); - bridged_notifier_.UnregisterHandler(&observer); - EXPECT_FALSE(fake_delegate_->IsHandlerRegistered(&observer)); + bridged_invalidator_.UnregisterHandler(&handler); + EXPECT_FALSE(fake_delegate_->IsHandlerRegistered(&handler)); } -TEST_F(BridgedSyncNotifierTest, SetUniqueId) { +TEST_F(BridgedInvalidatorTest, SetUniqueId) { const std::string& unique_id = "unique id"; - bridged_notifier_.SetUniqueId(unique_id); + bridged_invalidator_.SetUniqueId(unique_id); EXPECT_EQ(unique_id, fake_delegate_->GetUniqueId()); } -TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { +TEST_F(BridgedInvalidatorTest, SetStateDeprecated) { const std::string& state = "state"; - bridged_notifier_.SetStateDeprecated(state); + bridged_invalidator_.SetStateDeprecated(state); EXPECT_EQ(state, fake_delegate_->GetStateDeprecated()); } -TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { +TEST_F(BridgedInvalidatorTest, UpdateCredentials) { const std::string& email = "email"; const std::string& token = "token"; - bridged_notifier_.UpdateCredentials(email, token); + bridged_invalidator_.UpdateCredentials(email, token); EXPECT_EQ(email, fake_delegate_->GetCredentialsEmail()); EXPECT_EQ(token, fake_delegate_->GetCredentialsToken()); } -TEST_F(BridgedSyncNotifierTest, SendNotification) { +TEST_F(BridgedInvalidatorTest, SendNotification) { const syncer::ModelTypeSet changed_types( syncer::SESSIONS, syncer::EXTENSIONS); - bridged_notifier_.SendNotification(changed_types); + bridged_invalidator_.SendNotification(changed_types); EXPECT_TRUE(fake_delegate_->GetLastChangedTypes().Equals(changed_types)); } diff --git a/chrome/browser/sync/glue/bridged_sync_notifier.h b/chrome/browser/sync/glue/bridged_sync_notifier.h deleted file mode 100644 index 616e16d..0000000 --- a/chrome/browser/sync/glue/bridged_sync_notifier.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_SYNC_GLUE_BRIDGED_SYNC_NOTIFIER_H_ -#define CHROME_BROWSER_SYNC_GLUE_BRIDGED_SYNC_NOTIFIER_H_ - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "sync/notifier/sync_notifier.h" - -namespace browser_sync { - -class ChromeSyncNotificationBridge; - -// A SyncNotifier implementation that wraps a ChromeSyncNotificationBridge -// and optionally a SyncNotifier delegate (which it takes ownership of). -// All SyncNotifier calls are passed straight through to the delegate, -// with the exception of AddObserver/RemoveObserver, which also result in -// the observer being registered/deregistered with the -// ChromeSyncNotificationBridge. -class BridgedSyncNotifier : public syncer::SyncNotifier { - public: - // Does not take ownership of |bridge|. Takes ownership of |delegate|. - // |delegate| may be NULL. - BridgedSyncNotifier(ChromeSyncNotificationBridge* bridge, - syncer::SyncNotifier* delegate); - virtual ~BridgedSyncNotifier(); - - // SyncNotifier implementation. Passes through all calls to the delegate. - // RegisterHandler, UnregisterHandler, and UpdateRegisteredIds calls will - // also be forwarded to the bridge. - virtual void RegisterHandler(syncer::SyncNotifierObserver* handler) OVERRIDE; - virtual void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, - const syncer::ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterHandler( - syncer::SyncNotifierObserver* handler) OVERRIDE; - virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; - virtual void SetStateDeprecated(const std::string& state) OVERRIDE; - virtual void UpdateCredentials( - const std::string& email, const std::string& token) OVERRIDE; - virtual void SendNotification( - syncer::ModelTypeSet changed_types) OVERRIDE; - - private: - // The notification bridge that we register the observers with. - ChromeSyncNotificationBridge* bridge_; - - // The delegate we are wrapping. - scoped_ptr<syncer::SyncNotifier> delegate_; -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_BRIDGED_SYNC_NOTIFIER_H_ diff --git a/chrome/browser/sync/glue/chrome_sync_notification_bridge.cc b/chrome/browser/sync/glue/chrome_sync_notification_bridge.cc index dfd3e1f..6d9b7de 100644 --- a/chrome/browser/sync/glue/chrome_sync_notification_bridge.cc +++ b/chrome/browser/sync/glue/chrome_sync_notification_bridge.cc @@ -11,8 +11,8 @@ #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" -#include "sync/notifier/sync_notifier_observer.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidation_handler.h" +#include "sync/notifier/invalidator_registrar.h" using content::BrowserThread; @@ -31,10 +31,10 @@ class ChromeSyncNotificationBridge::Core void CleanupOnSyncThread(); void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types); - void RegisterHandler(syncer::SyncNotifierObserver* handler); - void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, + void RegisterHandler(syncer::InvalidationHandler* handler); + void UpdateRegisteredIds(syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids); - void UnregisterHandler(syncer::SyncNotifierObserver* handler); + void UnregisterHandler(syncer::InvalidationHandler* handler); void EmitNotification( const syncer::ModelTypeStateMap& state_map, @@ -50,7 +50,7 @@ class ChromeSyncNotificationBridge::Core // Used only on |sync_task_runner_|. syncer::ModelTypeSet enabled_types_; - scoped_ptr<syncer::SyncNotifierRegistrar> notifier_registrar_; + scoped_ptr<syncer::InvalidatorRegistrar> notifier_registrar_; }; ChromeSyncNotificationBridge::Core::Core( @@ -67,7 +67,7 @@ ChromeSyncNotificationBridge::Core::~Core() { } void ChromeSyncNotificationBridge::Core::InitializeOnSyncThread() { - notifier_registrar_.reset(new syncer::SyncNotifierRegistrar()); + notifier_registrar_.reset(new syncer::InvalidatorRegistrar()); } void ChromeSyncNotificationBridge::Core::CleanupOnSyncThread() { @@ -81,20 +81,20 @@ void ChromeSyncNotificationBridge::Core::UpdateEnabledTypes( } void ChromeSyncNotificationBridge::Core::RegisterHandler( - syncer::SyncNotifierObserver* handler) { + syncer::InvalidationHandler* handler) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); notifier_registrar_->RegisterHandler(handler); } void ChromeSyncNotificationBridge::Core::UpdateRegisteredIds( - syncer::SyncNotifierObserver* handler, + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); notifier_registrar_->UpdateRegisteredIds(handler, ids); } void ChromeSyncNotificationBridge::Core::UnregisterHandler( - syncer::SyncNotifierObserver* handler) { + syncer::InvalidationHandler* handler) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); notifier_registrar_->UnregisterHandler(handler); } @@ -147,20 +147,20 @@ void ChromeSyncNotificationBridge::UpdateEnabledTypes( } void ChromeSyncNotificationBridge::RegisterHandler( - syncer::SyncNotifierObserver* handler) { + syncer::InvalidationHandler* handler) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); core_->RegisterHandler(handler); } void ChromeSyncNotificationBridge::UpdateRegisteredIds( - syncer::SyncNotifierObserver* handler, + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); core_->UpdateRegisteredIds(handler, ids); } void ChromeSyncNotificationBridge::UnregisterHandler( - syncer::SyncNotifierObserver* handler) { + syncer::InvalidationHandler* handler) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); core_->UnregisterHandler(handler); } diff --git a/chrome/browser/sync/glue/chrome_sync_notification_bridge.h b/chrome/browser/sync/glue/chrome_sync_notification_bridge.h index 0216df9..5d85bec 100644 --- a/chrome/browser/sync/glue/chrome_sync_notification_bridge.h +++ b/chrome/browser/sync/glue/chrome_sync_notification_bridge.h @@ -16,7 +16,7 @@ class Profile; namespace syncer { -class SyncNotifierObserver; +class InvalidationHandler; } // namespace namespace browser_sync { @@ -44,10 +44,10 @@ class ChromeSyncNotificationBridge : public content::NotificationObserver { // Must be called on the sync task runner. void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types); // Marked virtual for tests. - virtual void RegisterHandler(syncer::SyncNotifierObserver* handler); - virtual void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, + virtual void RegisterHandler(syncer::InvalidationHandler* handler); + virtual void UpdateRegisteredIds(syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids); - virtual void UnregisterHandler(syncer::SyncNotifierObserver* handler); + virtual void UnregisterHandler(syncer::InvalidationHandler* handler); // NotificationObserver implementation. Called on UI thread. virtual void Observe(int type, diff --git a/chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc b/chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc index e410903..1769b7e 100644 --- a/chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc +++ b/chrome/browser/sync/glue/chrome_sync_notification_bridge_unittest.cc @@ -22,8 +22,8 @@ #include "content/public/test/test_browser_thread.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_state_map.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/object_id_state_map_test_util.h" -#include "sync/notifier/sync_notifier_observer.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -42,9 +42,9 @@ using content::BrowserThread; // Note: Because this object lives on the sync thread, we use a fake // (vs a mock) so we don't have to worry about possible thread safety // issues within GTest/GMock. -class FakeSyncNotifierObserver : public syncer::SyncNotifierObserver { +class FakeInvalidationHandler : public syncer::InvalidationHandler { public: - FakeSyncNotifierObserver( + FakeInvalidationHandler( const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, ChromeSyncNotificationBridge* bridge, const syncer::ObjectIdStateMap& expected_states, @@ -62,12 +62,12 @@ class FakeSyncNotifierObserver : public syncer::SyncNotifierObserver { bridge_->UpdateRegisteredIds(this, ids); } - virtual ~FakeSyncNotifierObserver() { + virtual ~FakeInvalidationHandler() { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); bridge_->UnregisterHandler(this); } - // SyncNotifierObserver implementation. + // InvalidationHandler implementation. virtual void OnIncomingNotification( const syncer::ObjectIdStateMap& id_state_map, syncer::IncomingNotificationSource source) OVERRIDE { @@ -109,8 +109,8 @@ class ChromeSyncNotificationBridgeTest : public testing::Test { ChromeSyncNotificationBridgeTest() : ui_thread_(BrowserThread::UI), sync_thread_("Sync thread"), - sync_observer_(NULL), - sync_observer_notification_failure_(false), + sync_handler_(NULL), + sync_handler_notification_failure_(false), done_(true, false) {} virtual ~ChromeSyncNotificationBridgeTest() {} @@ -128,8 +128,8 @@ class ChromeSyncNotificationBridgeTest : public testing::Test { sync_thread_.Stop(); // Must be reset only after the sync thread is stopped. bridge_.reset(); - EXPECT_EQ(NULL, sync_observer_); - if (sync_observer_notification_failure_) + EXPECT_EQ(NULL, sync_handler_); + if (sync_handler_notification_failure_) ADD_FAILURE() << "Sync Observer did not receive proper notification."; } @@ -180,13 +180,13 @@ class ChromeSyncNotificationBridgeTest : public testing::Test { private: void VerifyAndDestroyObserverOnSyncThread() { DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); - if (!sync_observer_) { - sync_observer_notification_failure_ = true; + if (!sync_handler_) { + sync_handler_notification_failure_ = true; } else { - sync_observer_notification_failure_ = - !sync_observer_->ReceivedProperNotification(); - delete sync_observer_; - sync_observer_ = NULL; + sync_handler_notification_failure_ = + !sync_handler_->ReceivedProperNotification(); + delete sync_handler_; + sync_handler_ = NULL; } } @@ -194,7 +194,7 @@ class ChromeSyncNotificationBridgeTest : public testing::Test { const syncer::ObjectIdStateMap& expected_states, syncer::IncomingNotificationSource expected_source) { DCHECK(sync_thread_.message_loop_proxy()->RunsTasksOnCurrentThread()); - sync_observer_ = new FakeSyncNotifierObserver( + sync_handler_ = new FakeInvalidationHandler( sync_thread_.message_loop_proxy(), bridge_.get(), expected_states, @@ -227,8 +227,8 @@ class ChromeSyncNotificationBridgeTest : public testing::Test { base::Thread sync_thread_; NiceMock<ProfileMock> mock_profile_; // Created/used/destroyed on sync thread. - FakeSyncNotifierObserver* sync_observer_; - bool sync_observer_notification_failure_; + FakeInvalidationHandler* sync_handler_; + bool sync_handler_notification_failure_; scoped_ptr<ChromeSyncNotificationBridge> bridge_; base::WaitableEvent done_; }; diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index adfa8f6..6033c1e 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -23,7 +23,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/token_service.h" -#include "chrome/browser/sync/glue/bridged_sync_notifier.h" +#include "chrome/browser/sync/glue/bridged_invalidator.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/chrome_encryptor.h" #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" @@ -49,7 +49,7 @@ #include "sync/internal_api/public/sync_manager_factory.h" #include "sync/internal_api/public/util/experiments.h" #include "sync/internal_api/public/util/sync_string_conversions.h" -#include "sync/notifier/sync_notifier.h" +#include "sync/notifier/invalidator.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/sync.pb.h" #include "sync/util/nigori.h" @@ -81,7 +81,7 @@ class SyncBackendHost::Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, public syncer::SyncEncryptionHandler::Observer, public syncer::SyncManager::Observer, - public syncer::SyncNotifierObserver { + public syncer::InvalidationHandler { public: Core(const std::string& name, const FilePath& sync_data_folder_path, @@ -118,7 +118,7 @@ class SyncBackendHost::Core syncer::Cryptographer* cryptographer) OVERRIDE; virtual void OnPassphraseStateChanged(syncer::PassphraseState state) OVERRIDE; - // syncer::SyncNotifierObserver implementation. + // syncer::InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( syncer::NotificationsDisabledReason reason) OVERRIDE; @@ -322,7 +322,7 @@ SyncBackendHost::SyncBackendHost( weak_ptr_factory_.GetWeakPtr())), initialization_state_(NOT_ATTEMPTED), sync_prefs_(sync_prefs), - sync_notifier_factory_( + invalidator_factory_( ParseNotifierOptions(*CommandLine::ForCurrentProcess(), profile_->GetRequestContext()), content::GetUserAgent(GURL()), @@ -338,7 +338,7 @@ SyncBackendHost::SyncBackendHost(Profile* profile) profile_(profile), name_("Unknown"), initialization_state_(NOT_ATTEMPTED), - sync_notifier_factory_( + invalidator_factory_( ParseNotifierOptions(*CommandLine::ForCurrentProcess(), profile_->GetRequestContext()), content::GetUserAgent(GURL()), @@ -451,7 +451,7 @@ void SyncBackendHost::Initialize( make_scoped_refptr(profile_->GetRequestContext())), credentials, chrome_sync_notification_bridge_.get(), - &sync_notifier_factory_, + &invalidator_factory_, sync_manager_factory, delete_sync_data_folder, sync_prefs_->GetEncryptionBootstrapToken(), @@ -839,7 +839,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, const syncer::SyncCredentials& credentials, ChromeSyncNotificationBridge* chrome_sync_notification_bridge, - syncer::SyncNotifierFactory* sync_notifier_factory, + syncer::InvalidatorFactory* invalidator_factory, syncer::SyncManagerFactory* sync_manager_factory, bool delete_sync_data_folder, const std::string& restored_key_for_bootstrapping, @@ -858,7 +858,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( make_http_bridge_factory_fn(make_http_bridge_factory_fn), credentials(credentials), chrome_sync_notification_bridge(chrome_sync_notification_bridge), - sync_notifier_factory(sync_notifier_factory), + invalidator_factory(invalidator_factory), sync_manager_factory(sync_manager_factory), delete_sync_data_folder(delete_sync_data_folder), restored_key_for_bootstrapping(restored_key_for_bootstrapping), @@ -1116,9 +1116,9 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { options.extensions_activity_monitor, options.registrar /* as SyncManager::ChangeDelegate */, options.credentials, - scoped_ptr<syncer::SyncNotifier>(new BridgedSyncNotifier( + scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( options.chrome_sync_notification_bridge, - options.sync_notifier_factory->CreateSyncNotifier())), + options.invalidator_factory->CreateInvalidator())), options.restored_key_for_bootstrapping, options.restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory>( diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index 6e616b6..0d1da25 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -27,8 +27,8 @@ #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" #include "sync/internal_api/public/util/unrecoverable_error_handler.h" #include "sync/internal_api/public/util/weak_handle.h" -#include "sync/notifier/sync_notifier_factory.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidation_handler.h" +#include "sync/notifier/invalidator_factory.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/sync_protocol_error.h" @@ -53,7 +53,7 @@ class SyncPrefs; // activity. // NOTE: All methods will be invoked by a SyncBackendHost on the same thread // used to create that SyncBackendHost. -class SyncFrontend : public syncer::SyncNotifierObserver { +class SyncFrontend : public syncer::InvalidationHandler { public: SyncFrontend() {} @@ -299,7 +299,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, const syncer::SyncCredentials& credentials, ChromeSyncNotificationBridge* chrome_sync_notification_bridge, - syncer::SyncNotifierFactory* sync_notifier_factory, + syncer::InvalidatorFactory* invalidator_factory, syncer::SyncManagerFactory* sync_manager_factory, bool delete_sync_data_folder, const std::string& restored_key_for_bootstrapping, @@ -321,7 +321,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; syncer::SyncCredentials credentials; ChromeSyncNotificationBridge* const chrome_sync_notification_bridge; - syncer::SyncNotifierFactory* const sync_notifier_factory; + syncer::InvalidatorFactory* const invalidator_factory; syncer::SyncManagerFactory* const sync_manager_factory; std::string lsid; bool delete_sync_data_folder; @@ -471,7 +471,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { void HandleNigoriConfigurationCompletedOnFrontendLoop( syncer::ModelTypeSet failed_configuration_types); - // syncer::SyncNotifierObserver-like functions. + // syncer::InvalidationHandler-like functions. void HandleNotificationsEnabledOnFrontendLoop(); void HandleNotificationsDisabledOnFrontendLoop( syncer::NotificationsDisabledReason reason); @@ -508,7 +508,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { // into invalidations (on the sync thread). scoped_ptr<ChromeSyncNotificationBridge> chrome_sync_notification_bridge_; - syncer::SyncNotifierFactory sync_notifier_factory_; + syncer::InvalidatorFactory invalidator_factory_; ChromeExtensionsActivityMonitor extensions_activity_monitor_; diff --git a/chrome/browser/sync/invalidation_frontend.h b/chrome/browser/sync/invalidation_frontend.h index 9914271..87d6a97 100644 --- a/chrome/browser/sync/invalidation_frontend.h +++ b/chrome/browser/sync/invalidation_frontend.h @@ -8,7 +8,7 @@ #include "sync/notifier/invalidation_util.h" namespace syncer { -class SyncNotifierObserver; +class InvalidationHandler; } // namespace syncer // Interface for classes that handle invalidation registrations and send out @@ -20,7 +20,7 @@ class InvalidationFrontend { // // Handler registrations are persisted across restarts of sync. virtual void RegisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) = 0; + syncer::InvalidationHandler* handler) = 0; // Updates the set of ObjectIds associated with |handler|. |handler| must // not be NULL, and must already be registered. An ID must be registered for @@ -28,7 +28,7 @@ class InvalidationFrontend { // // Registered IDs are persisted across restarts of sync. virtual void UpdateRegisteredInvalidationIds( - syncer::SyncNotifierObserver* handler, + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) = 0; // Stops sending notifications to |handler|. |handler| must not be NULL, and @@ -37,7 +37,7 @@ class InvalidationFrontend { // // Handler registrations are persisted across restarts of sync. virtual void UnregisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) = 0; + syncer::InvalidationHandler* handler) = 0; protected: virtual ~InvalidationFrontend() { } diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 7f06c72..3f0b87d 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -431,7 +431,7 @@ void ProfileSyncService::StartUp() { // http://crbug.com/140354). if (backend_.get()) { backend_->UpdateRegisteredInvalidationIds( - notifier_registrar_.GetAllRegisteredIds()); + invalidator_registrar_.GetAllRegisteredIds()); } if (!sync_global_error_.get()) { @@ -445,26 +445,26 @@ void ProfileSyncService::StartUp() { } void ProfileSyncService::RegisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) { - notifier_registrar_.RegisterHandler(handler); + syncer::InvalidationHandler* handler) { + invalidator_registrar_.RegisterHandler(handler); } void ProfileSyncService::UpdateRegisteredInvalidationIds( - syncer::SyncNotifierObserver* handler, + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) { - notifier_registrar_.UpdateRegisteredIds(handler, ids); + invalidator_registrar_.UpdateRegisteredIds(handler, ids); // If |backend_| is NULL, its registered IDs will be updated when // it's created and initialized. if (backend_.get()) { backend_->UpdateRegisteredInvalidationIds( - notifier_registrar_.GetAllRegisteredIds()); + invalidator_registrar_.GetAllRegisteredIds()); } } void ProfileSyncService::UnregisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) { - notifier_registrar_.UnregisterHandler(handler); + syncer::InvalidationHandler* handler) { + invalidator_registrar_.UnregisterHandler(handler); } void ProfileSyncService::Shutdown() { @@ -660,18 +660,18 @@ void ProfileSyncService::DisableBrokenDatatype( } void ProfileSyncService::OnNotificationsEnabled() { - notifier_registrar_.EmitOnNotificationsEnabled(); + invalidator_registrar_.EmitOnNotificationsEnabled(); } void ProfileSyncService::OnNotificationsDisabled( syncer::NotificationsDisabledReason reason) { - notifier_registrar_.EmitOnNotificationsDisabled(reason); + invalidator_registrar_.EmitOnNotificationsDisabled(reason); } void ProfileSyncService::OnIncomingNotification( const syncer::ObjectIdStateMap& id_state_map, syncer::IncomingNotificationSource source) { - notifier_registrar_.DispatchInvalidationsToHandlers(id_state_map, source); + invalidator_registrar_.DispatchInvalidationsToHandlers(id_state_map, source); } void ProfileSyncService::OnBackendInitialized( diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 7a2d489..a09766b 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -40,7 +40,7 @@ #include "sync/internal_api/public/util/experiments.h" #include "sync/internal_api/public/util/unrecoverable_error_handler.h" #include "sync/js/sync_js_controller.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator_registrar.h" class Profile; class ProfileSyncComponentsFactory; @@ -258,7 +258,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, virtual bool HasSyncSetupCompleted() const; virtual void SetSyncSetupCompleted(); - // syncer::SyncNotifier implementation (via SyncFrontend). + // syncer::InvalidationHandler implementation (via SyncFrontend). virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( syncer::NotificationsDisabledReason reason) OVERRIDE; @@ -597,7 +597,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // // Handler registrations are persisted across restarts of sync. virtual void RegisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) OVERRIDE; + syncer::InvalidationHandler* handler) OVERRIDE; // Updates the set of ObjectIds associated with |handler|. |handler| must // not be NULL, and must already be registered. An ID must be registered for @@ -605,7 +605,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // // Registered IDs are persisted across restarts of sync. virtual void UpdateRegisteredInvalidationIds( - syncer::SyncNotifierObserver* handler, + syncer::InvalidationHandler* handler, const syncer::ObjectIdSet& ids) OVERRIDE; // Stops sending notifications to |handler|. |handler| must not be NULL, and @@ -614,7 +614,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // // Handler registrations are persisted across restarts of sync. virtual void UnregisterInvalidationHandler( - syncer::SyncNotifierObserver* handler) OVERRIDE; + syncer::InvalidationHandler* handler) OVERRIDE; // ProfileKeyedService implementation. virtual void Shutdown() OVERRIDE; @@ -891,7 +891,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, syncer::SyncManagerFactory sync_manager_factory_; // Dispatches invalidations to handlers. - syncer::SyncNotifierRegistrar notifier_registrar_; + syncer::InvalidatorRegistrar invalidator_registrar_; DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); }; diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index afc88eb..53dba54 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -25,7 +25,7 @@ #include "sync/js/js_arg_list.h" #include "sync/js/js_event_details.h" #include "sync/js/js_test_util.h" -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -371,9 +371,9 @@ TEST_F(ProfileSyncServiceTest, FailToOpenDatabase) { } // Register for some IDs with the ProfileSyncService and trigger some -// invalidation messages. They should be received by the observer. +// invalidation messages. They should be received by the handler. // Then unregister and trigger the invalidation messages again. Those -// shouldn't be received by the observer. +// shouldn't be received by the handler. TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { StartSyncService(); @@ -383,29 +383,29 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { const syncer::ObjectIdStateMap& states = syncer::ObjectIdSetToStateMap(ids, "payload"); - syncer::FakeSyncNotifierObserver observer; + syncer::FakeInvalidationHandler handler; - service_->RegisterInvalidationHandler(&observer); - service_->UpdateRegisteredInvalidationIds(&observer, ids); + service_->RegisterInvalidationHandler(&handler); + service_->UpdateRegisteredInvalidationIds(&handler, ids); SyncBackendHostForProfileSyncTest* const backend = service_->GetBackendForTest(); backend->EmitOnNotificationsEnabled(); EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, - observer.GetNotificationsDisabledReason()); + handler.GetNotificationsDisabledReason()); backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); - EXPECT_THAT(states, Eq(observer.GetLastNotificationIdStateMap())); - EXPECT_EQ(syncer::REMOTE_NOTIFICATION, observer.GetLastNotificationSource()); + EXPECT_THAT(states, Eq(handler.GetLastNotificationIdStateMap())); + EXPECT_EQ(syncer::REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, - observer.GetNotificationsDisabledReason()); + handler.GetNotificationsDisabledReason()); - Mock::VerifyAndClearExpectations(&observer); + Mock::VerifyAndClearExpectations(&handler); - service_->UnregisterInvalidationHandler(&observer); + service_->UnregisterInvalidationHandler(&handler); backend->EmitOnNotificationsEnabled(); backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); @@ -414,7 +414,7 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { // Register for some IDs with the ProfileSyncService, restart sync, // and trigger some invalidation messages. They should still be -// received by the observer. +// received by the handler. TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { StartSyncService(); @@ -423,10 +423,10 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { const syncer::ObjectIdStateMap& states = syncer::ObjectIdSetToStateMap(ids, "payload"); - syncer::FakeSyncNotifierObserver observer; + syncer::FakeInvalidationHandler handler; - service_->RegisterInvalidationHandler(&observer); - service_->UpdateRegisteredInvalidationIds(&observer, ids); + service_->RegisterInvalidationHandler(&handler); + service_->UpdateRegisteredInvalidationIds(&handler, ids); service_->StopAndSuppress(); service_->UnsuppressAndStart(); @@ -436,15 +436,15 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { backend->EmitOnNotificationsEnabled(); EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, - observer.GetNotificationsDisabledReason()); + handler.GetNotificationsDisabledReason()); backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); - EXPECT_THAT(states, Eq(observer.GetLastNotificationIdStateMap())); - EXPECT_EQ(syncer::REMOTE_NOTIFICATION, observer.GetLastNotificationSource()); + EXPECT_THAT(states, Eq(handler.GetLastNotificationIdStateMap())); + EXPECT_EQ(syncer::REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, - observer.GetNotificationsDisabledReason()); + handler.GetNotificationsDisabledReason()); } } // namespace diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 7dcc56a..9fb7eb4 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -53,7 +53,7 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" -#include "sync/notifier/p2p_notifier.h" +#include "sync/notifier/p2p_invalidator.h" #include "sync/protocol/sync.pb.h" #include "sync/engine/sync_scheduler_impl.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index c2c2803..4e4fd84 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2282,8 +2282,8 @@ 'browser/sync/glue/bookmark_data_type_controller.h', 'browser/sync/glue/bookmark_model_associator.cc', 'browser/sync/glue/bookmark_model_associator.h', - 'browser/sync/glue/bridged_sync_notifier.cc', - 'browser/sync/glue/bridged_sync_notifier.h', + 'browser/sync/glue/bridged_invalidator.cc', + 'browser/sync/glue/bridged_invalidator.h', 'browser/sync/glue/browser_thread_model_worker.cc', 'browser/sync/glue/browser_thread_model_worker.h', 'browser/sync/glue/change_processor.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 93a658a..846fee3 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1584,7 +1584,7 @@ 'browser/sync/glue/app_notification_data_type_controller_unittest.cc', 'browser/sync/glue/autofill_data_type_controller_unittest.cc', 'browser/sync/glue/bookmark_data_type_controller_unittest.cc', - 'browser/sync/glue/bridged_sync_notifier_unittest.cc', + 'browser/sync/glue/bridged_invalidator_unittest.cc', 'browser/sync/glue/browser_thread_model_worker_unittest.cc', 'browser/sync/glue/change_processor_mock.cc', 'browser/sync/glue/change_processor_mock.h', diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h index 5facc1e..dfd3cb3 100644 --- a/sync/internal_api/public/sync_manager.h +++ b/sync/internal_api/public/sync_manager.h @@ -38,11 +38,11 @@ struct Experiments; class ExtensionsActivityMonitor; class HttpPostProviderFactory; class InternalComponentsFactory; +class InvalidationHandler; +class Invalidator; class JsBackend; class JsEventHandler; class SyncEncryptionHandler; -class SyncNotifier; -class SyncNotifierObserver; class SyncScheduler; class UnrecoverableErrorHandler; struct UserShare; @@ -290,7 +290,7 @@ class SyncManager { // |model_safe_worker| ownership is given to the SyncManager. // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent // HTTP header. Used internally when collecting stats to classify clients. - // |sync_notifier| is owned and used to listen for notifications. + // |invalidator| is owned and used to listen for invalidations. // |restored_key_for_bootstrapping| is the key used to boostrap the // cryptographer // |keystore_encryption_enabled| determines whether we enable the keystore @@ -311,7 +311,7 @@ class SyncManager { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<SyncNotifier> sync_notifier, + scoped_ptr<Invalidator> invalidator, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory> internal_components_factory, @@ -342,18 +342,18 @@ class SyncManager { virtual void UpdateEnabledTypes( const ModelTypeSet& enabled_types) = 0; - // Forwards to the underlying notifier (see comments in sync_notifier.h). + // Forwards to the underlying invalidator (see comments in invalidator.h). virtual void RegisterInvalidationHandler( - SyncNotifierObserver* handler) = 0; + InvalidationHandler* handler) = 0; - // Forwards to the underlying notifier (see comments in sync_notifier.h). + // Forwards to the underlying notifier (see comments in invalidator.h). virtual void UpdateRegisteredInvalidationIds( - SyncNotifierObserver* handler, + InvalidationHandler* handler, const ObjectIdSet& ids) = 0; - // Forwards to the underlying notifier (see comments in sync_notifier.h). + // Forwards to the underlying notifier (see comments in invalidator.h). virtual void UnregisterInvalidationHandler( - SyncNotifierObserver* handler) = 0; + InvalidationHandler* handler) = 0; // Put the syncer in normal mode ready to perform nudges and polls. virtual void StartSyncingNormally( diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h index 604429f..9661659 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -10,7 +10,7 @@ #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "sync/internal_api/public/sync_manager.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator_registrar.h" namespace base { class SequencedTaskRunner; @@ -81,7 +81,7 @@ class FakeSyncManager : public SyncManager { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<SyncNotifier> sync_notifier, + scoped_ptr<Invalidator> invalidator, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory> internal_components_factory, @@ -97,12 +97,12 @@ class FakeSyncManager : public SyncManager { virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; virtual void UpdateEnabledTypes(const ModelTypeSet& types) OVERRIDE; virtual void RegisterInvalidationHandler( - SyncNotifierObserver* handler) OVERRIDE; + InvalidationHandler* handler) OVERRIDE; virtual void UpdateRegisteredInvalidationIds( - SyncNotifierObserver* handler, + InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; virtual void UnregisterInvalidationHandler( - SyncNotifierObserver* handler) OVERRIDE; + InvalidationHandler* handler) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -149,8 +149,8 @@ class FakeSyncManager : public SyncManager { // The set of types that have been enabled. ModelTypeSet enabled_types_; - // Faked notifier state. - SyncNotifierRegistrar registrar_; + // Faked invalidator state. + InvalidatorRegistrar registrar_; scoped_ptr<FakeSyncEncryptionHandler> fake_encryption_handler_; diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index 9e832e7..13f2ae4 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -40,7 +40,7 @@ #include "sync/js/js_event_handler.h" #include "sync/js/js_reply_handler.h" #include "sync/notifier/invalidation_util.h" -#include "sync/notifier/sync_notifier.h" +#include "sync/notifier/invalidator.h" #include "sync/protocol/proto_value_conversions.h" #include "sync/protocol/sync.pb.h" #include "sync/syncable/directory.h" @@ -349,7 +349,7 @@ void SyncManagerImpl::Init( ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<SyncNotifier> sync_notifier, + scoped_ptr<Invalidator> invalidator, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory> internal_components_factory, @@ -369,8 +369,8 @@ void SyncManagerImpl::Init( change_delegate_ = change_delegate; - sync_notifier_ = sync_notifier.Pass(); - sync_notifier_->RegisterHandler(this); + invalidator_ = invalidator.Pass(); + invalidator_->RegisterHandler(this); AddObserver(&js_sync_manager_observer_); SetJsEventHandler(event_handler); @@ -425,7 +425,7 @@ void SyncManagerImpl::Init( std::string unique_id = directory()->cache_guid(); DVLOG(1) << "Read notification unique ID: " << unique_id; allstatus_.SetUniqueId(unique_id); - sync_notifier_->SetUniqueId(unique_id); + invalidator_->SetUniqueId(unique_id); std::string state = directory()->GetNotificationState(); if (VLOG_IS_ON(1)) { @@ -436,7 +436,7 @@ void SyncManagerImpl::Init( // TODO(tim): Remove once invalidation state has been migrated to new // InvalidationStateTracker store. Bug 124140. - sync_notifier_->SetStateDeprecated(state); + invalidator_->SetStateDeprecated(state); // Build a SyncSessionContext and store the worker in it. DVLOG(1) << "Sync is bringing up SyncSessionContext."; @@ -653,7 +653,7 @@ void SyncManagerImpl::UpdateCredentials( if (!connection_manager_->set_auth_token(credentials.sync_token)) return; // Auth token is known to be invalid, so exit early. - sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); + invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); scheduler_->OnCredentialsUpdated(); } @@ -661,31 +661,31 @@ void SyncManagerImpl::UpdateEnabledTypes( const ModelTypeSet& enabled_types) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(initialized_); - sync_notifier_->UpdateRegisteredIds( + invalidator_->UpdateRegisteredIds( this, ModelTypeSetToObjectIdSet(enabled_types)); } void SyncManagerImpl::RegisterInvalidationHandler( - SyncNotifierObserver* handler) { + InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(initialized_); - sync_notifier_->RegisterHandler(handler); + invalidator_->RegisterHandler(handler); } void SyncManagerImpl::UpdateRegisteredInvalidationIds( - SyncNotifierObserver* handler, + InvalidationHandler* handler, const ObjectIdSet& ids) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(initialized_); - sync_notifier_->UpdateRegisteredIds(handler, ids); + invalidator_->UpdateRegisteredIds(handler, ids); } void SyncManagerImpl::UnregisterInvalidationHandler( - SyncNotifierObserver* handler) { + InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(initialized_); - sync_notifier_->UnregisterHandler(handler); + invalidator_->UnregisterHandler(handler); } bool SyncManagerImpl::GetKeystoreKeyBootstrapToken(std::string* token) { @@ -731,14 +731,14 @@ void SyncManagerImpl::ShutdownOnSyncThread() { RemoveObserver(&debug_info_event_listener_); - // |sync_notifier_| and |connection_manager_| may end up being NULL here in + // |invalidator_| and |connection_manager_| may end up being NULL here in // tests (in synchronous initialization mode). // // TODO(akalin): Fix this behavior. - if (sync_notifier_.get()) - sync_notifier_->UnregisterHandler(this); - sync_notifier_.reset(); + if (invalidator_.get()) + invalidator_->UnregisterHandler(this); + invalidator_.reset(); if (connection_manager_.get()) connection_manager_->RemoveListener(this); @@ -1019,12 +1019,12 @@ void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { bool is_notifiable_commit = (event.snapshot.model_neutral_state().num_successful_commits > 0); if (is_notifiable_commit) { - if (sync_notifier_.get()) { + if (invalidator_.get()) { const ModelTypeSet changed_types = ModelTypeStateMapToSet(event.snapshot.source().types); - sync_notifier_->SendNotification(changed_types); + invalidator_->SendNotification(changed_types); } else { - DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; + DVLOG(1) << "Not sending notification: invalidator_ is NULL"; } } } diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index 3a44969..7fa917e7 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -22,8 +22,8 @@ #include "sync/internal_api/public/sync_manager.h" #include "sync/internal_api/sync_encryption_handler_impl.h" #include "sync/js/js_backend.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/notifications_disabled_reason.h" -#include "sync/notifier/sync_notifier_observer.h" #include "sync/syncable/directory_change_delegate.h" #include "sync/util/cryptographer.h" #include "sync/util/time.h" @@ -48,7 +48,7 @@ class SyncSessionContext; // same thread. class SyncManagerImpl : public SyncManager, public net::NetworkChangeNotifier::IPAddressObserver, - public SyncNotifierObserver, + public InvalidationHandler, public JsBackend, public SyncEngineEventListener, public ServerConnectionEventListener, @@ -72,7 +72,7 @@ class SyncManagerImpl : public SyncManager, ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<SyncNotifier> sync_notifier, + scoped_ptr<Invalidator> invalidator, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory> internal_components_factory, @@ -89,12 +89,12 @@ class SyncManagerImpl : public SyncManager, virtual void UpdateEnabledTypes( const ModelTypeSet& enabled_types) OVERRIDE; virtual void RegisterInvalidationHandler( - SyncNotifierObserver* handler) OVERRIDE; + InvalidationHandler* handler) OVERRIDE; virtual void UpdateRegisteredInvalidationIds( - SyncNotifierObserver* handler, + InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; virtual void UnregisterInvalidationHandler( - SyncNotifierObserver* handler) OVERRIDE; + InvalidationHandler* handler) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -167,7 +167,7 @@ class SyncManagerImpl : public SyncManager, const syncable::ImmutableWriteTransactionInfo& write_transaction_info, syncable::BaseTransaction* trans) OVERRIDE; - // SyncNotifierObserver implementation. + // InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; @@ -332,8 +332,8 @@ class SyncManagerImpl : public SyncManager, // Start()ed. scoped_ptr<SyncScheduler> scheduler_; - // The SyncNotifier which notifies us when updates need to be downloaded. - scoped_ptr<SyncNotifier> sync_notifier_; + // The Invalidator which notifies us when updates need to be downloaded. + scoped_ptr<Invalidator> invalidator_; // A multi-purpose status watch object that aggregates stats from various // sync components. diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index b64ecc3..2d133a1 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -44,10 +44,10 @@ #include "sync/js/js_event_handler.h" #include "sync/js/js_reply_handler.h" #include "sync/js/js_test_util.h" -#include "sync/notifier/fake_sync_notifier.h" -#include "sync/notifier/fake_sync_notifier_observer.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" +#include "sync/notifier/fake_invalidator.h" +#include "sync/notifier/invalidation_handler.h" +#include "sync/notifier/invalidator.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/extension_specifics.pb.h" @@ -718,14 +718,14 @@ class SyncManagerTest : public testing::Test, }; SyncManagerTest() - : fake_notifier_(NULL), + : fake_invalidator_(NULL), sync_manager_("Test sync manager") { switches_.encryption_method = InternalComponentsFactory::ENCRYPTION_KEYSTORE; } virtual ~SyncManagerTest() { - EXPECT_FALSE(fake_notifier_); + EXPECT_FALSE(fake_invalidator_); } // Test implementation. @@ -736,7 +736,7 @@ class SyncManagerTest : public testing::Test, credentials.email = "foo@bar.com"; credentials.sync_token = "sometoken"; - fake_notifier_ = new FakeSyncNotifier(); + fake_invalidator_ = new FakeInvalidator(); sync_manager_.AddObserver(&manager_observer_); EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)). @@ -748,7 +748,7 @@ class SyncManagerTest : public testing::Test, ModelSafeRoutingInfo routing_info; GetModelSafeRoutingInfo(&routing_info); - // Takes ownership of |fake_notifier_|. + // Takes ownership of |fake_invalidator_|. sync_manager_.Init(temp_dir_.path(), WeakHandle<JsEventHandler>(), "bogus", 0, false, @@ -757,7 +757,7 @@ class SyncManagerTest : public testing::Test, new TestHttpPostProviderFactory()), workers, &extensions_activity_monitor_, this, credentials, - scoped_ptr<SyncNotifier>(fake_notifier_), + scoped_ptr<Invalidator>(fake_invalidator_), "", "", // bootstrap tokens scoped_ptr<InternalComponentsFactory>(GetFactory()), &encryptor_, @@ -775,16 +775,16 @@ class SyncManagerTest : public testing::Test, } PumpLoop(); - EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&sync_manager_)); + EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_)); } void TearDown() { sync_manager_.RemoveObserver(&manager_observer_); sync_manager_.ShutdownOnSyncThread(); // We can't assert that |sync_manager_| isn't registered with - // |fake_notifier_| anymore because |fake_notifier_| is now + // |fake_invalidator_| anymore because |fake_invalidator_| is now // destroyed. - fake_notifier_ = NULL; + fake_invalidator_ = NULL; PumpLoop(); } @@ -957,7 +957,7 @@ class SyncManagerTest : public testing::Test, protected: FakeEncryptor encryptor_; TestUnrecoverableErrorHandler handler_; - FakeSyncNotifier* fake_notifier_; + FakeInvalidator* fake_invalidator_; SyncManagerImpl sync_manager_; WeakHandle<JsBackend> js_backend_; StrictMock<SyncManagerObserverMock> manager_observer_; @@ -971,21 +971,21 @@ TEST_F(SyncManagerTest, UpdateEnabledTypes) { const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); sync_manager_.UpdateEnabledTypes(enabled_types); EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), - fake_notifier_->GetRegisteredIds(&sync_manager_)); + fake_invalidator_->GetRegisteredIds(&sync_manager_)); } TEST_F(SyncManagerTest, RegisterInvalidationHandler) { - FakeSyncNotifierObserver fake_observer; - sync_manager_.RegisterInvalidationHandler(&fake_observer); - EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&fake_observer)); + FakeInvalidationHandler fake_handler; + sync_manager_.RegisterInvalidationHandler(&fake_handler); + EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); const ObjectIdSet& ids = ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES)); - sync_manager_.UpdateRegisteredInvalidationIds(&fake_observer, ids); - EXPECT_EQ(ids, fake_notifier_->GetRegisteredIds(&fake_observer)); + sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids); + EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler)); - sync_manager_.UnregisterInvalidationHandler(&fake_observer); - EXPECT_FALSE(fake_notifier_->IsHandlerRegistered(&fake_observer)); + sync_manager_.UnregisterInvalidationHandler(&fake_handler); + EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); } TEST_F(SyncManagerTest, ProcessJsMessage) { diff --git a/sync/internal_api/test/fake_sync_manager.cc b/sync/internal_api/test/fake_sync_manager.cc index 6bf55fc..299bb41 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -17,8 +17,8 @@ #include "sync/internal_api/public/internal_components_factory.h" #include "sync/internal_api/public/util/weak_handle.h" #include "sync/notifier/notifications_disabled_reason.h" +#include "sync/notifier/invalidator.h" #include "sync/notifier/object_id_state_map.h" -#include "sync/notifier/sync_notifier.h" #include "sync/test/fake_sync_encryption_handler.h" namespace syncer { @@ -111,7 +111,7 @@ void FakeSyncManager::Init( ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<SyncNotifier> sync_notifier, + scoped_ptr<Invalidator> invalidator, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory> internal_components_factory, @@ -163,18 +163,18 @@ void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { } void FakeSyncManager::RegisterInvalidationHandler( - SyncNotifierObserver* handler) { + InvalidationHandler* handler) { registrar_.RegisterHandler(handler); } void FakeSyncManager::UpdateRegisteredInvalidationIds( - SyncNotifierObserver* handler, + InvalidationHandler* handler, const ObjectIdSet& ids) { registrar_.UpdateRegisteredIds(handler, ids); } void FakeSyncManager::UnregisterInvalidationHandler( - SyncNotifierObserver* handler) { + InvalidationHandler* handler) { registrar_.UnregisterHandler(handler); } diff --git a/sync/notifier/fake_sync_notifier_observer.cc b/sync/notifier/fake_invalidation_handler.cc index b95f9a9..6c06587 100644 --- a/sync/notifier/fake_sync_notifier_observer.cc +++ b/sync/notifier/fake_invalidation_handler.cc @@ -2,46 +2,46 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" namespace syncer { -FakeSyncNotifierObserver::FakeSyncNotifierObserver() +FakeInvalidationHandler::FakeInvalidationHandler() : reason_(TRANSIENT_NOTIFICATION_ERROR), last_source_(LOCAL_NOTIFICATION), notification_count_(0) {} -FakeSyncNotifierObserver::~FakeSyncNotifierObserver() {} +FakeInvalidationHandler::~FakeInvalidationHandler() {} NotificationsDisabledReason -FakeSyncNotifierObserver::GetNotificationsDisabledReason() const { +FakeInvalidationHandler::GetNotificationsDisabledReason() const { return reason_; } const ObjectIdStateMap& -FakeSyncNotifierObserver::GetLastNotificationIdStateMap() const { +FakeInvalidationHandler::GetLastNotificationIdStateMap() const { return last_id_state_map_; } IncomingNotificationSource -FakeSyncNotifierObserver::GetLastNotificationSource() const { +FakeInvalidationHandler::GetLastNotificationSource() const { return last_source_; } -int FakeSyncNotifierObserver::GetNotificationCount() const { +int FakeInvalidationHandler::GetNotificationCount() const { return notification_count_; } -void FakeSyncNotifierObserver::OnNotificationsEnabled() { +void FakeInvalidationHandler::OnNotificationsEnabled() { reason_ = NO_NOTIFICATION_ERROR; } -void FakeSyncNotifierObserver::OnNotificationsDisabled( +void FakeInvalidationHandler::OnNotificationsDisabled( NotificationsDisabledReason reason) { reason_ = reason; } -void FakeSyncNotifierObserver::OnIncomingNotification( +void FakeInvalidationHandler::OnIncomingNotification( const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { last_id_state_map_ = id_state_map; diff --git a/sync/notifier/fake_sync_notifier_observer.h b/sync/notifier/fake_invalidation_handler.h index e1195d9..1d9dcfbd 100644 --- a/sync/notifier/fake_sync_notifier_observer.h +++ b/sync/notifier/fake_invalidation_handler.h @@ -8,21 +8,21 @@ #include <string> #include "base/compiler_specific.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidation_handler.h" namespace syncer { -class FakeSyncNotifierObserver : public SyncNotifierObserver { +class FakeInvalidationHandler : public InvalidationHandler { public: - FakeSyncNotifierObserver(); - virtual ~FakeSyncNotifierObserver(); + FakeInvalidationHandler(); + virtual ~FakeInvalidationHandler(); NotificationsDisabledReason GetNotificationsDisabledReason() const; const ObjectIdStateMap& GetLastNotificationIdStateMap() const; IncomingNotificationSource GetLastNotificationSource() const; int GetNotificationCount() const; - // SyncNotifierObserver implementation. + // InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; diff --git a/sync/notifier/fake_invalidator.cc b/sync/notifier/fake_invalidator.cc new file mode 100644 index 0000000..85696ad --- /dev/null +++ b/sync/notifier/fake_invalidator.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/notifier/fake_invalidator.h" + +namespace syncer { + +FakeInvalidator::FakeInvalidator() {} + +FakeInvalidator::~FakeInvalidator() {} + +bool FakeInvalidator::IsHandlerRegistered(InvalidationHandler* handler) const { + return registrar_.IsHandlerRegisteredForTest(handler); +} + +ObjectIdSet FakeInvalidator::GetRegisteredIds( + InvalidationHandler* handler) const { + return registrar_.GetRegisteredIdsForTest(handler); +} + +void FakeInvalidator::RegisterHandler(InvalidationHandler* handler) { + registrar_.RegisterHandler(handler); +} + +const std::string& FakeInvalidator::GetUniqueId() const { + return unique_id_; +} + +const std::string& FakeInvalidator::GetStateDeprecated() const { + return state_; +} + +const std::string& FakeInvalidator::GetCredentialsEmail() const { + return email_; +} + +const std::string& FakeInvalidator::GetCredentialsToken() const { + return token_; +} + +ModelTypeSet FakeInvalidator::GetLastChangedTypes() const { + return last_changed_types_; +} + +void FakeInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, + const ObjectIdSet& ids) { + registrar_.UpdateRegisteredIds(handler, ids); +} + +void FakeInvalidator::UnregisterHandler(InvalidationHandler* handler) { + registrar_.UnregisterHandler(handler); +} + +void FakeInvalidator::SetUniqueId(const std::string& unique_id) { + unique_id_ = unique_id; +} + +void FakeInvalidator::SetStateDeprecated(const std::string& state) { + state_ = state; +} + +void FakeInvalidator::UpdateCredentials( + const std::string& email, const std::string& token) { + email_ = email; + token_ = token; +} + +void FakeInvalidator::SendNotification(ModelTypeSet changed_types) { + last_changed_types_ = changed_types; +} + +} // namespace syncer diff --git a/sync/notifier/fake_sync_notifier.h b/sync/notifier/fake_invalidator.h index 74cfdf1..26c5ad8 100644 --- a/sync/notifier/fake_sync_notifier.h +++ b/sync/notifier/fake_invalidator.h @@ -2,35 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_ -#define SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_ +#ifndef SYNC_NOTIFIER_FAKE_INVALIDATOR_H_ +#define SYNC_NOTIFIER_FAKE_INVALIDATOR_H_ #include <string> #include "base/compiler_specific.h" #include "sync/notifier/invalidation_util.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/invalidator_registrar.h" namespace syncer { -class FakeSyncNotifier : public SyncNotifier { +class FakeInvalidator : public Invalidator { public: - FakeSyncNotifier(); - virtual ~FakeSyncNotifier(); + FakeInvalidator(); + virtual ~FakeInvalidator(); - bool IsHandlerRegistered(SyncNotifierObserver* handler) const; - ObjectIdSet GetRegisteredIds(SyncNotifierObserver* handler) const; + bool IsHandlerRegistered(InvalidationHandler* handler) const; + ObjectIdSet GetRegisteredIds(InvalidationHandler* handler) const; const std::string& GetUniqueId() const; const std::string& GetStateDeprecated() const; const std::string& GetCredentialsEmail() const; const std::string& GetCredentialsToken() const; ModelTypeSet GetLastChangedTypes() const; - virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; - virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, + virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; + virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; virtual void SetStateDeprecated(const std::string& state) OVERRIDE; virtual void UpdateCredentials( @@ -38,7 +38,7 @@ class FakeSyncNotifier : public SyncNotifier { virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; private: - SyncNotifierRegistrar registrar_; + InvalidatorRegistrar registrar_; std::string unique_id_; std::string state_; std::string email_; @@ -48,4 +48,4 @@ class FakeSyncNotifier : public SyncNotifier { } // namespace syncer -#endif // SYNC_NOTIFIER_FAKE_SYNC_NOTIFIER_H_ +#endif // SYNC_NOTIFIER_FAKE_INVALIDATOR_H_ diff --git a/sync/notifier/fake_sync_notifier.cc b/sync/notifier/fake_sync_notifier.cc deleted file mode 100644 index 0ef5ef9..0000000 --- a/sync/notifier/fake_sync_notifier.cc +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sync/notifier/fake_sync_notifier.h" - -namespace syncer { - -FakeSyncNotifier::FakeSyncNotifier() {} - -FakeSyncNotifier::~FakeSyncNotifier() {} - -bool FakeSyncNotifier::IsHandlerRegistered( - SyncNotifierObserver* handler) const { - return registrar_.IsHandlerRegisteredForTest(handler); -} - -ObjectIdSet FakeSyncNotifier::GetRegisteredIds( - SyncNotifierObserver* handler) const { - return registrar_.GetRegisteredIdsForTest(handler); -} - -void FakeSyncNotifier::RegisterHandler(SyncNotifierObserver* handler) { - registrar_.RegisterHandler(handler); -} - -const std::string& FakeSyncNotifier::GetUniqueId() const { - return unique_id_; -} - -const std::string& FakeSyncNotifier::GetStateDeprecated() const { - return state_; -} - -const std::string& FakeSyncNotifier::GetCredentialsEmail() const { - return email_; -} - -const std::string& FakeSyncNotifier::GetCredentialsToken() const { - return token_; -} - -ModelTypeSet FakeSyncNotifier::GetLastChangedTypes() const { - return last_changed_types_; -} - -void FakeSyncNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, - const ObjectIdSet& ids) { - registrar_.UpdateRegisteredIds(handler, ids); -} - -void FakeSyncNotifier::UnregisterHandler(SyncNotifierObserver* handler) { - registrar_.UnregisterHandler(handler); -} - -void FakeSyncNotifier::SetUniqueId(const std::string& unique_id) { - unique_id_ = unique_id; -} - -void FakeSyncNotifier::SetStateDeprecated(const std::string& state) { - state_ = state; -} - -void FakeSyncNotifier::UpdateCredentials( - const std::string& email, const std::string& token) { - email_ = email; - token_ = token; -} - -void FakeSyncNotifier::SendNotification(ModelTypeSet changed_types) { - last_changed_types_ = changed_types; -} - -} // namespace syncer diff --git a/sync/notifier/sync_notifier_observer.h b/sync/notifier/invalidation_handler.h index 1dd5ea6..c1252ac 100644 --- a/sync/notifier/sync_notifier_observer.h +++ b/sync/notifier/invalidation_handler.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_OBSERVER_H_ -#define SYNC_NOTIFIER_SYNC_NOTIFIER_OBSERVER_H_ +#ifndef SYNC_NOTIFIER_INVALIDATION_HANDLER_H_ +#define SYNC_NOTIFIER_INVALIDATION_HANDLER_H_ #include "sync/notifier/object_id_state_map.h" #include "sync/notifier/notifications_disabled_reason.h" @@ -17,7 +17,7 @@ enum IncomingNotificationSource { LOCAL_NOTIFICATION, }; -class SyncNotifierObserver { +class InvalidationHandler { public: // Called when notifications are enabled. virtual void OnNotificationsEnabled() = 0; @@ -34,9 +34,9 @@ class SyncNotifierObserver { IncomingNotificationSource source) = 0; protected: - virtual ~SyncNotifierObserver() {} + virtual ~InvalidationHandler() {} }; } // namespace syncer -#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_OBSERVER_H_ +#endif // SYNC_NOTIFIER_INVALIDATION_HANDLER_H_ diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index f56bbd6..0775d74 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -11,7 +11,7 @@ #include "google/cacheinvalidation/include/invalidation-client-factory.h" #include "jingle/notifier/listener/push_client.h" #include "net/url_request/url_request_context.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidation_handler.h" #include "talk/xmpp/jid.h" #include "talk/xmpp/xmppclientsettings.h" @@ -35,19 +35,19 @@ InvalidationNotifier::~InvalidationNotifier() { DCHECK(CalledOnValidThread()); } -void InvalidationNotifier::RegisterHandler(SyncNotifierObserver* handler) { +void InvalidationNotifier::RegisterHandler(InvalidationHandler* handler) { DCHECK(CalledOnValidThread()); registrar_.RegisterHandler(handler); } -void InvalidationNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, +void InvalidationNotifier::UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) { DCHECK(CalledOnValidThread()); registrar_.UpdateRegisteredIds(handler, ids); invalidation_client_.UpdateRegisteredIds(registrar_.GetAllRegisteredIds()); } -void InvalidationNotifier::UnregisterHandler(SyncNotifierObserver* handler) { +void InvalidationNotifier::UnregisterHandler(InvalidationHandler* handler) { DCHECK(CalledOnValidThread()); registrar_.UnregisterHandler(handler); } diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index 91c16c3..79bc4ae 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// An implementation of SyncNotifier that wraps an invalidation +// An implementation of Invalidator that wraps an invalidation // client. Handles the details of connecting to XMPP and hooking it // up to the invalidation client. // @@ -22,8 +22,8 @@ #include "sync/internal_api/public/util/weak_handle.h" #include "sync/notifier/chrome_invalidation_client.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/invalidator_registrar.h" namespace notifier { class PushClient; @@ -32,8 +32,9 @@ class PushClient; namespace syncer { // This class must live on the IO thread. +// TODO(dcheng): Think of a name better than InvalidationInvalidator. class InvalidationNotifier - : public SyncNotifier, + : public Invalidator, public ChromeInvalidationClient::Listener, public base::NonThreadSafe { public: @@ -48,11 +49,11 @@ class InvalidationNotifier virtual ~InvalidationNotifier(); - // SyncNotifier implementation. - virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; - virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, + // Invalidator implementation. + virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; + virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; virtual void SetStateDeprecated(const std::string& state) OVERRIDE; virtual void UpdateCredentials( @@ -77,7 +78,7 @@ class InvalidationNotifier }; State state_; - SyncNotifierRegistrar registrar_; + InvalidatorRegistrar registrar_; // Passed to |invalidation_client_|. const InvalidationVersionMap initial_max_invalidation_versions_; diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc index 6ced3ef..563e7ec 100644 --- a/sync/notifier/invalidation_notifier_unittest.cc +++ b/sync/notifier/invalidation_notifier_unittest.cc @@ -13,8 +13,8 @@ #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/util/weak_handle.h" +#include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/fake_invalidation_state_tracker.h" -#include "sync/notifier/fake_sync_notifier_observer.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" @@ -35,7 +35,7 @@ class InvalidationNotifierTest : public testing::Test { } // Constructs an InvalidationNotifier, places it in |invalidation_notifier_|, - // and registers |fake_observer_| as a handler. This remains in place until + // and registers |fake_handler_| as a handler. This remains in place until // either TearDown (automatic) or ResetNotifier (manual) is called. void CreateNotifier( const std::string& initial_invalidation_state) { @@ -50,11 +50,11 @@ class InvalidationNotifierTest : public testing::Test { initial_invalidation_state, MakeWeakHandle(fake_tracker_.AsWeakPtr()), "fake_client_info")); - invalidation_notifier_->RegisterHandler(&fake_observer_); + invalidation_notifier_->RegisterHandler(&fake_handler_); } void ResetNotifier() { - invalidation_notifier_->UnregisterHandler(&fake_observer_); + invalidation_notifier_->UnregisterHandler(&fake_handler_); // Stopping the invalidation notifier stops its scheduler, which deletes any // pending tasks without running them. Some tasks "run and delete" another // task, so they must be run in order to avoid leaking the inner task. @@ -76,7 +76,7 @@ class InvalidationNotifierTest : public testing::Test { protected: scoped_ptr<InvalidationNotifier> invalidation_notifier_; FakeInvalidationStateTracker fake_tracker_; - FakeSyncNotifierObserver fake_observer_; + FakeInvalidationHandler fake_handler_; }; TEST_F(InvalidationNotifierTest, Basic) { @@ -88,7 +88,7 @@ TEST_F(InvalidationNotifierTest, Basic) { ModelTypeSetToStateMap(models, "payload")); invalidation_notifier_->UpdateRegisteredIds( - &fake_observer_, ModelTypeSetToObjectIdSet(models)); + &fake_handler_, ModelTypeSetToObjectIdSet(models)); // TODO(tim): This call should be a no-op, Remove once bug 124140 and // associated issues are fixed. @@ -101,22 +101,22 @@ TEST_F(InvalidationNotifierTest, Basic) { invalidation_notifier_->OnNotificationsEnabled(); EXPECT_EQ(NO_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); invalidation_notifier_->OnInvalidate(id_state_map); EXPECT_THAT(id_state_map, - Eq(fake_observer_.GetLastNotificationIdStateMap())); - EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource()); + Eq(fake_handler_.GetLastNotificationIdStateMap())); + EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); invalidation_notifier_->OnNotificationsDisabled( TRANSIENT_NOTIFICATION_ERROR); EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); invalidation_notifier_->OnNotificationsDisabled( NOTIFICATION_CREDENTIALS_REJECTED); EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); } TEST_F(InvalidationNotifierTest, MigrateState) { diff --git a/sync/notifier/sync_notifier.h b/sync/notifier/invalidator.h index 9191b90..2765a67 100644 --- a/sync/notifier/sync_notifier.h +++ b/sync/notifier/invalidator.h @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Interface to the sync notifier, which is an object that receives -// notifications when updates are available for a set of sync types. -// All the observers are notified when such an event happens. +// Interface to the invalidator, which is an object that receives +// invalidations for registered object IDs. The corresponding +// InvalidationHandler is notifier when such an event occurs. -#ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_H_ -#define SYNC_NOTIFIER_SYNC_NOTIFIER_H_ +#ifndef SYNC_NOTIFIER_INVALIDATOR_H_ +#define SYNC_NOTIFIER_INVALIDATOR_H_ #include <string> @@ -15,28 +15,28 @@ #include "sync/notifier/invalidation_util.h" namespace syncer { -class SyncNotifierObserver; +class InvalidationHandler; -class SyncNotifier { +class Invalidator { public: - SyncNotifier() {} - virtual ~SyncNotifier() {} + Invalidator() {} + virtual ~Invalidator() {} // Clients should follow the pattern below: // // When starting the client: // - // notifier->RegisterHandler(client_handler); + // invalidator->RegisterHandler(client_handler); // // When the set of IDs to register changes for the client during its lifetime // (i.e., between calls to RegisterHandler(client_handler) and // UnregisterHandler(client_handler): // - // notifier->UpdateRegisteredIds(client_handler, client_ids); + // invalidator->UpdateRegisteredIds(client_handler, client_ids); // - // When shutting down the client for browser shutdown: + // When shutting down the client for profile shutdown: // - // notifier->UnregisterHandler(client_handler); + // invalidator->UnregisterHandler(client_handler); // // Note that there's no call to UpdateRegisteredIds() -- this is because the // invalidation API persists registrations across browser restarts. @@ -44,23 +44,23 @@ class SyncNotifier { // When permanently shutting down the client, e.g. when disabling the related // feature: // - // notifier->UpdateRegisteredIds(client_handler, ObjectIdSet()); - // notifier->UnregisterHandler(client_handler); + // invalidator->UpdateRegisteredIds(client_handler, ObjectIdSet()); + // invalidator->UnregisterHandler(client_handler); // Starts sending notifications to |handler|. |handler| must not be NULL, // and it must already be registered. - virtual void RegisterHandler(SyncNotifierObserver* handler) = 0; + virtual void RegisterHandler(InvalidationHandler* handler) = 0; // Updates the set of ObjectIds associated with |handler|. |handler| must // not be NULL, and must already be registered. An ID must be registered for // at most one handler. - virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, + virtual void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) = 0; // Stops sending notifications to |handler|. |handler| must not be NULL, and // it must already be registered. Note that this doesn't unregister the IDs // associated with |handler|. - virtual void UnregisterHandler(SyncNotifierObserver* handler) = 0; + virtual void UnregisterHandler(InvalidationHandler* handler) = 0; // SetUniqueId must be called once, before any call to // UpdateCredentials. |unique_id| should be a non-empty globally @@ -86,4 +86,4 @@ class SyncNotifier { }; } // namespace syncer -#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_H_ +#endif // SYNC_NOTIFIER_INVALIDATOR_H_ diff --git a/sync/notifier/sync_notifier_factory.cc b/sync/notifier/invalidator_factory.cc index 3737f71..80ceb16 100644 --- a/sync/notifier/sync_notifier_factory.cc +++ b/sync/notifier/invalidator_factory.cc @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/sync_notifier_factory.h" +#include "sync/notifier/invalidator_factory.h" #include <string> #include "base/logging.h" #include "jingle/notifier/listener/push_client.h" -#include "sync/notifier/non_blocking_invalidation_notifier.h" -#include "sync/notifier/p2p_notifier.h" -#include "sync/notifier/sync_notifier.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/non_blocking_invalidator.h" +#include "sync/notifier/p2p_invalidator.h" namespace syncer { namespace { -SyncNotifier* CreateDefaultSyncNotifier( +Invalidator* CreateDefaultInvalidator( const notifier::NotifierOptions& notifier_options, const InvalidationVersionMap& initial_max_invalidation_versions, const std::string& initial_invalidation_state, @@ -26,12 +26,12 @@ SyncNotifier* CreateDefaultSyncNotifier( // NOTIFY_OTHERS. There's no good reason to notify ourselves of our own // commits. We self-notify for now only because the integration tests rely // on this behaviour. See crbug.com/97780. - return new P2PNotifier( + return new P2PInvalidator( notifier::PushClient::CreateDefault(notifier_options), NOTIFY_ALL); } - return new NonBlockingInvalidationNotifier( + return new NonBlockingInvalidator( notifier_options, initial_max_invalidation_versions, initial_invalidation_state, invalidation_state_tracker, client_info); } @@ -39,7 +39,7 @@ SyncNotifier* CreateDefaultSyncNotifier( } // namespace // TODO(akalin): Remove the dependency on jingle if OS_ANDROID is defined. -SyncNotifierFactory::SyncNotifierFactory( +InvalidatorFactory::InvalidatorFactory( const notifier::NotifierOptions& notifier_options, const std::string& client_info, const base::WeakPtr<InvalidationStateTracker>& @@ -57,19 +57,19 @@ SyncNotifierFactory::SyncNotifierFactory( invalidation_state_tracker_(invalidation_state_tracker) { } -SyncNotifierFactory::~SyncNotifierFactory() { +InvalidatorFactory::~InvalidatorFactory() { } -SyncNotifier* SyncNotifierFactory::CreateSyncNotifier() { +Invalidator* InvalidatorFactory::CreateInvalidator() { #if defined(OS_ANDROID) // Android uses ChromeSyncNotificationBridge exclusively. return NULL; #else - return CreateDefaultSyncNotifier(notifier_options_, - initial_max_invalidation_versions_, - initial_invalidation_state_, - invalidation_state_tracker_, - client_info_); + return CreateDefaultInvalidator(notifier_options_, + initial_max_invalidation_versions_, + initial_invalidation_state_, + invalidation_state_tracker_, + client_info_); #endif } } // namespace syncer diff --git a/sync/notifier/sync_notifier_factory.h b/sync/notifier/invalidator_factory.h index 0c8a2d3..48763cd 100644 --- a/sync/notifier/sync_notifier_factory.h +++ b/sync/notifier/invalidator_factory.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_FACTORY_H_ -#define SYNC_NOTIFIER_SYNC_NOTIFIER_FACTORY_H_ +#ifndef SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ +#define SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ #include <string> @@ -14,26 +14,26 @@ namespace syncer { -class SyncNotifier; +class Invalidator; -// Class to instantiate various implementations of the SyncNotifier +// Class to instantiate various implementations of the Invalidator // interface. -class SyncNotifierFactory { +class InvalidatorFactory { public: // |client_info| is a string identifying the client, e.g. a user // agent string. |invalidation_state_tracker| may be NULL (for // tests). - SyncNotifierFactory( + InvalidatorFactory( const notifier::NotifierOptions& notifier_options, const std::string& client_info, const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker); - ~SyncNotifierFactory(); + ~InvalidatorFactory(); - // Creates a sync notifier. Caller takes ownership of the returned + // Creates an invalidator. Caller takes ownership of the returned // object. However, the returned object must not outlive the // factory from which it was created. Can be called on any thread. - SyncNotifier* CreateSyncNotifier(); + Invalidator* CreateInvalidator(); private: const notifier::NotifierOptions notifier_options_; @@ -46,4 +46,4 @@ class SyncNotifierFactory { } // namespace syncer -#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_FACTORY_H_ +#endif // SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ diff --git a/sync/notifier/sync_notifier_factory_unittest.cc b/sync/notifier/invalidator_factory_unittest.cc index 6e2bc58..2b17e35 100644 --- a/sync/notifier/sync_notifier_factory_unittest.cc +++ b/sync/notifier/invalidator_factory_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/sync_notifier_factory.h" +#include "sync/notifier/invalidator_factory.h" #include "base/command_line.h" #include "base/compiler_specific.h" @@ -15,15 +15,15 @@ #include "jingle/notifier/base/notifier_options.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/sync_notifier.h" +#include "sync/notifier/invalidator.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { namespace { -class SyncNotifierFactoryTest : public testing::Test { +class InvalidatorFactoryTest : public testing::Test { protected: virtual void SetUp() OVERRIDE { @@ -33,50 +33,50 @@ class SyncNotifierFactoryTest : public testing::Test { virtual void TearDown() OVERRIDE { message_loop_.RunAllPending(); - EXPECT_EQ(0, fake_observer_.GetNotificationCount()); + EXPECT_EQ(0, fake_handler_.GetNotificationCount()); } MessageLoop message_loop_; - FakeSyncNotifierObserver fake_observer_; + FakeInvalidationHandler fake_handler_; notifier::NotifierOptions notifier_options_; - scoped_ptr<SyncNotifierFactory> factory_; + scoped_ptr<InvalidatorFactory> factory_; }; // Test basic creation of a NonBlockingInvalidationNotifier. -TEST_F(SyncNotifierFactoryTest, Basic) { +TEST_F(InvalidatorFactoryTest, Basic) { notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; - SyncNotifierFactory factory( + InvalidatorFactory factory( notifier_options_, "test client info", base::WeakPtr<InvalidationStateTracker>()); - scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); + scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); #if defined(OS_ANDROID) - ASSERT_FALSE(notifier.get()); + ASSERT_FALSE(invalidator.get()); #else - ASSERT_TRUE(notifier.get()); + ASSERT_TRUE(invalidator.get()); ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); - notifier->RegisterHandler(&fake_observer_); - notifier->UpdateRegisteredIds(&fake_observer_, ids); - notifier->UnregisterHandler(&fake_observer_); + invalidator->RegisterHandler(&fake_handler_); + invalidator->UpdateRegisteredIds(&fake_handler_, ids); + invalidator->UnregisterHandler(&fake_handler_); #endif } // Test basic creation of a P2PNotifier. -TEST_F(SyncNotifierFactoryTest, Basic_P2P) { +TEST_F(InvalidatorFactoryTest, Basic_P2P) { notifier_options_.notification_method = notifier::NOTIFICATION_P2P; - SyncNotifierFactory factory( + InvalidatorFactory factory( notifier_options_, "test client info", base::WeakPtr<InvalidationStateTracker>()); - scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); + scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); #if defined(OS_ANDROID) - ASSERT_FALSE(notifier.get()); + ASSERT_FALSE(invalidator.get()); #else - ASSERT_TRUE(notifier.get()); + ASSERT_TRUE(invalidator.get()); ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); - notifier->RegisterHandler(&fake_observer_); - notifier->UpdateRegisteredIds(&fake_observer_, ids); - notifier->UnregisterHandler(&fake_observer_); + invalidator->RegisterHandler(&fake_handler_); + invalidator->UpdateRegisteredIds(&fake_handler_, ids); + invalidator->UnregisterHandler(&fake_handler_); #endif } diff --git a/sync/notifier/sync_notifier_registrar.cc b/sync/notifier/invalidator_registrar.cc index a6960f5..a7ac5b0 100644 --- a/sync/notifier/sync_notifier_registrar.cc +++ b/sync/notifier/invalidator_registrar.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator_registrar.h" #include <cstddef> #include <utility> @@ -11,21 +11,21 @@ namespace syncer { -SyncNotifierRegistrar::SyncNotifierRegistrar() {} +InvalidatorRegistrar::InvalidatorRegistrar() {} -SyncNotifierRegistrar::~SyncNotifierRegistrar() { +InvalidatorRegistrar::~InvalidatorRegistrar() { DCHECK(thread_checker_.CalledOnValidThread()); } -void SyncNotifierRegistrar::RegisterHandler(SyncNotifierObserver* handler) { +void InvalidatorRegistrar::RegisterHandler(InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); CHECK(handler); CHECK(!handlers_.HasObserver(handler)); handlers_.AddObserver(handler); } -void SyncNotifierRegistrar::UpdateRegisteredIds( - SyncNotifierObserver* handler, +void InvalidatorRegistrar::UpdateRegisteredIds( + InvalidationHandler* handler, const ObjectIdSet& ids) { DCHECK(thread_checker_.CalledOnValidThread()); CHECK(handler); @@ -56,14 +56,14 @@ void SyncNotifierRegistrar::UpdateRegisteredIds( } } -void SyncNotifierRegistrar::UnregisterHandler(SyncNotifierObserver* handler) { +void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); CHECK(handler); CHECK(handlers_.HasObserver(handler)); handlers_.RemoveObserver(handler); } -ObjectIdSet SyncNotifierRegistrar::GetAllRegisteredIds() const { +ObjectIdSet InvalidatorRegistrar::GetAllRegisteredIds() const { DCHECK(thread_checker_.CalledOnValidThread()); ObjectIdSet registered_ids; for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); @@ -73,7 +73,7 @@ ObjectIdSet SyncNotifierRegistrar::GetAllRegisteredIds() const { return registered_ids; } -void SyncNotifierRegistrar::DispatchInvalidationsToHandlers( +void InvalidatorRegistrar::DispatchInvalidationsToHandlers( const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -82,19 +82,19 @@ void SyncNotifierRegistrar::DispatchInvalidationsToHandlers( return; } - typedef std::map<SyncNotifierObserver*, ObjectIdStateMap> DispatchMap; + typedef std::map<InvalidationHandler*, ObjectIdStateMap> DispatchMap; DispatchMap dispatch_map; for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); it != id_state_map.end(); ++it) { - SyncNotifierObserver* const handler = ObjectIdToHandler(it->first); + InvalidationHandler* const handler = ObjectIdToHandler(it->first); // Filter out invalidations for IDs with no handler. if (handler) dispatch_map[handler].insert(*it); } // Emit invalidations only for handlers in |handlers_|. - ObserverListBase<SyncNotifierObserver>::Iterator it(handlers_); - SyncNotifierObserver* handler = NULL; + ObserverListBase<InvalidationHandler>::Iterator it(handlers_); + InvalidationHandler* handler = NULL; while ((handler = it.GetNext()) != NULL) { DispatchMap::const_iterator dispatch_it = dispatch_map.find(handler); if (dispatch_it != dispatch_map.end()) @@ -102,26 +102,26 @@ void SyncNotifierRegistrar::DispatchInvalidationsToHandlers( } } -void SyncNotifierRegistrar::EmitOnNotificationsEnabled() { +void InvalidatorRegistrar::EmitOnNotificationsEnabled() { DCHECK(thread_checker_.CalledOnValidThread()); - FOR_EACH_OBSERVER(SyncNotifierObserver, handlers_, OnNotificationsEnabled()); + FOR_EACH_OBSERVER(InvalidationHandler, handlers_, OnNotificationsEnabled()); } -void SyncNotifierRegistrar::EmitOnNotificationsDisabled( +void InvalidatorRegistrar::EmitOnNotificationsDisabled( NotificationsDisabledReason reason) { DCHECK(thread_checker_.CalledOnValidThread()); - FOR_EACH_OBSERVER(SyncNotifierObserver, handlers_, + FOR_EACH_OBSERVER(InvalidationHandler, handlers_, OnNotificationsDisabled(reason)); } -bool SyncNotifierRegistrar::IsHandlerRegisteredForTest( - SyncNotifierObserver* handler) const { +bool InvalidatorRegistrar::IsHandlerRegisteredForTest( + InvalidationHandler* handler) const { DCHECK(thread_checker_.CalledOnValidThread()); return handlers_.HasObserver(handler); } -ObjectIdSet SyncNotifierRegistrar::GetRegisteredIdsForTest( - SyncNotifierObserver* handler) const { +ObjectIdSet InvalidatorRegistrar::GetRegisteredIdsForTest( + InvalidationHandler* handler) const { DCHECK(thread_checker_.CalledOnValidThread()); ObjectIdSet registered_ids; for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); @@ -133,12 +133,12 @@ ObjectIdSet SyncNotifierRegistrar::GetRegisteredIdsForTest( return registered_ids; } -void SyncNotifierRegistrar::DetachFromThreadForTest() { +void InvalidatorRegistrar::DetachFromThreadForTest() { DCHECK(thread_checker_.CalledOnValidThread()); thread_checker_.DetachFromThread(); } -SyncNotifierObserver* SyncNotifierRegistrar::ObjectIdToHandler( +InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( const invalidation::ObjectId& id) { DCHECK(thread_checker_.CalledOnValidThread()); IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); diff --git a/sync/notifier/sync_notifier_registrar.h b/sync/notifier/invalidator_registrar.h index 38a81c4..6bb481b 100644 --- a/sync/notifier/sync_notifier_registrar.h +++ b/sync/notifier/invalidator_registrar.h @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ -#define SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ +#ifndef SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_ +#define SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_ #include <map> #include "base/basictypes.h" #include "base/observer_list.h" #include "base/threading/thread_checker.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/object_id_state_map.h" -#include "sync/notifier/sync_notifier_observer.h" namespace invalidation { class ObjectId; @@ -20,30 +20,29 @@ class ObjectId; namespace syncer { -// A helper class for implementations of the SyncNotifier interface. It helps +// A helper class for implementations of the Invalidator interface. It helps // keep track of registered handlers and which object ID registrations are // associated with which handlers, so implementors can just reuse the logic // here to dispatch invalidations and other interesting notifications. -class SyncNotifierRegistrar { +class InvalidatorRegistrar { public: - SyncNotifierRegistrar(); - ~SyncNotifierRegistrar(); + InvalidatorRegistrar(); + ~InvalidatorRegistrar(); // Starts sending notifications to |handler|. |handler| must not be NULL, // and it must already be registered. - void RegisterHandler(SyncNotifierObserver* handler); - + void RegisterHandler(InvalidationHandler* handler); // Updates the set of ObjectIds associated with |handler|. |handler| must // not be NULL, and must already be registered. An ID must be registered for // at most one handler. - void UpdateRegisteredIds(SyncNotifierObserver* handler, + void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids); // Stops sending notifications to |handler|. |handler| must not be NULL, and // it must already be registered. Note that this doesn't unregister the IDs // associated with |handler|. - void UnregisterHandler(SyncNotifierObserver* handler); + void UnregisterHandler(InvalidationHandler* handler); // Returns the set of all IDs that are registered to some handler (even // handlers that have been unregistered). @@ -60,26 +59,26 @@ class SyncNotifierRegistrar { void EmitOnNotificationsEnabled(); void EmitOnNotificationsDisabled(NotificationsDisabledReason reason); - bool IsHandlerRegisteredForTest(SyncNotifierObserver* handler) const; - ObjectIdSet GetRegisteredIdsForTest(SyncNotifierObserver* handler) const; + bool IsHandlerRegisteredForTest(InvalidationHandler* handler) const; + ObjectIdSet GetRegisteredIdsForTest(InvalidationHandler* handler) const; // Needed for death tests. void DetachFromThreadForTest(); private: - typedef std::map<invalidation::ObjectId, SyncNotifierObserver*, + typedef std::map<invalidation::ObjectId, InvalidationHandler*, ObjectIdLessThan> IdHandlerMap; - SyncNotifierObserver* ObjectIdToHandler(const invalidation::ObjectId& id); + InvalidationHandler* ObjectIdToHandler(const invalidation::ObjectId& id); base::ThreadChecker thread_checker_; - ObserverList<SyncNotifierObserver> handlers_; + ObserverList<InvalidationHandler> handlers_; IdHandlerMap id_to_handler_map_; - DISALLOW_COPY_AND_ASSIGN(SyncNotifierRegistrar); + DISALLOW_COPY_AND_ASSIGN(InvalidatorRegistrar); }; } // namespace syncer -#endif // SYNC_NOTIFIER_SYNC_NOTIFIER_REGISTRAR_H_ +#endif // SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_ diff --git a/sync/notifier/sync_notifier_registrar_unittest.cc b/sync/notifier/invalidator_registrar_unittest.cc index a9e57c5..f79a720 100644 --- a/sync/notifier/sync_notifier_registrar_unittest.cc +++ b/sync/notifier/invalidator_registrar_unittest.cc @@ -3,18 +3,18 @@ // found in the LICENSE file. #include "google/cacheinvalidation/types.pb.h" -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" +#include "sync/notifier/invalidator_registrar.h" #include "sync/notifier/object_id_state_map_test_util.h" -#include "sync/notifier/sync_notifier_registrar.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { namespace { -class SyncNotifierRegistrarTest : public testing::Test { +class InvalidatorRegistrarTest : public testing::Test { protected: - SyncNotifierRegistrarTest() + InvalidatorRegistrarTest() : kObjectId1(ipc::invalidation::ObjectSource::TEST, "a"), kObjectId2(ipc::invalidation::ObjectSource::TEST, "b"), kObjectId3(ipc::invalidation::ObjectSource::TEST, "c"), @@ -30,10 +30,10 @@ class SyncNotifierRegistrarTest : public testing::Test { // Register a handler, register some IDs for that handler, and then unregister // the handler, dispatching invalidations in between. The handler should only // see invalidations when its registered and its IDs are registered. -TEST_F(SyncNotifierRegistrarTest, Basic) { - FakeSyncNotifierObserver handler; +TEST_F(InvalidatorRegistrarTest, Basic) { + FakeInvalidationHandler handler; - SyncNotifierRegistrar registrar; + InvalidatorRegistrar registrar; registrar.RegisterHandler(&handler); @@ -89,13 +89,13 @@ TEST_F(SyncNotifierRegistrarTest, Basic) { // dispatch some notifications and invalidations. Handlers that are registered // should get notifications, and the ones that have registered IDs should // receive invalidations for those IDs. -TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { - FakeSyncNotifierObserver handler1; - FakeSyncNotifierObserver handler2; - FakeSyncNotifierObserver handler3; - FakeSyncNotifierObserver handler4; +TEST_F(InvalidatorRegistrarTest, MultipleHandlers) { + FakeInvalidationHandler handler1; + FakeInvalidationHandler handler2; + FakeInvalidationHandler handler3; + FakeInvalidationHandler handler4; - SyncNotifierRegistrar registrar; + InvalidatorRegistrar registrar; registrar.RegisterHandler(&handler1); registrar.RegisterHandler(&handler2); @@ -179,13 +179,13 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { // Multiple registrations by different handlers on the same object ID should // cause a CHECK. -TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { - SyncNotifierRegistrar registrar; +TEST_F(InvalidatorRegistrarTest, MultipleRegistration) { + InvalidatorRegistrar registrar; - FakeSyncNotifierObserver handler1; + FakeInvalidationHandler handler1; registrar.RegisterHandler(&handler1); - FakeSyncNotifierObserver handler2; + FakeInvalidationHandler handler2; registrar.RegisterHandler(&handler2); ObjectIdSet ids; @@ -201,13 +201,13 @@ TEST_F(SyncNotifierRegistrarTest, MultipleRegistration) { // Make sure that passing an empty set to UpdateRegisteredIds clears the // corresponding entries for the handler. -TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { - FakeSyncNotifierObserver handler1; +TEST_F(InvalidatorRegistrarTest, EmptySetUnregisters) { + FakeInvalidationHandler handler1; // Control observer. - FakeSyncNotifierObserver handler2; + FakeInvalidationHandler handler2; - SyncNotifierRegistrar registrar; + InvalidatorRegistrar registrar; registrar.RegisterHandler(&handler1); registrar.RegisterHandler(&handler2); diff --git a/sync/notifier/non_blocking_invalidation_notifier.cc b/sync/notifier/non_blocking_invalidator.cc index 89fb19a..ab4f166 100644 --- a/sync/notifier/non_blocking_invalidation_notifier.cc +++ b/sync/notifier/non_blocking_invalidator.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/non_blocking_invalidation_notifier.h" +#include "sync/notifier/non_blocking_invalidator.h" #include <cstddef> @@ -17,15 +17,15 @@ namespace syncer { -class NonBlockingInvalidationNotifier::Core - : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, - // SyncNotifierObserver to observe the InvalidationNotifier we create. - public SyncNotifierObserver { +class NonBlockingInvalidator::Core + : public base::RefCountedThreadSafe<NonBlockingInvalidator::Core>, + // InvalidationHandler to observe the InvalidationNotifier we create. + public InvalidationHandler { public: // Called on parent thread. |delegate_observer| should be // initialized. explicit Core( - const WeakHandle<SyncNotifierObserver>& delegate_observer); + const WeakHandle<InvalidationHandler>& delegate_observer); // Helpers called on I/O thread. void Initialize( @@ -40,7 +40,7 @@ class NonBlockingInvalidationNotifier::Core void SetStateDeprecated(const std::string& state); void UpdateCredentials(const std::string& email, const std::string& token); - // SyncNotifierObserver implementation (all called on I/O thread by + // InvalidationHandler implementation (all called on I/O thread by // InvalidationNotifier). virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( @@ -51,28 +51,28 @@ class NonBlockingInvalidationNotifier::Core private: friend class - base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; + base::RefCountedThreadSafe<NonBlockingInvalidator::Core>; // Called on parent or I/O thread. ~Core(); // The variables below should be used only on the I/O thread. - const WeakHandle<SyncNotifierObserver> delegate_observer_; + const WeakHandle<InvalidationHandler> delegate_observer_; scoped_ptr<InvalidationNotifier> invalidation_notifier_; scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; DISALLOW_COPY_AND_ASSIGN(Core); }; -NonBlockingInvalidationNotifier::Core::Core( - const WeakHandle<SyncNotifierObserver>& delegate_observer) +NonBlockingInvalidator::Core::Core( + const WeakHandle<InvalidationHandler>& delegate_observer) : delegate_observer_(delegate_observer) { DCHECK(delegate_observer_.IsInitialized()); } -NonBlockingInvalidationNotifier::Core::~Core() { +NonBlockingInvalidator::Core::~Core() { } -void NonBlockingInvalidationNotifier::Core::Initialize( +void NonBlockingInvalidator::Core::Initialize( const notifier::NotifierOptions& notifier_options, const InvalidationVersionMap& initial_max_invalidation_versions, const std::string& initial_invalidation_state, @@ -94,60 +94,58 @@ void NonBlockingInvalidationNotifier::Core::Initialize( invalidation_notifier_->RegisterHandler(this); } -void NonBlockingInvalidationNotifier::Core::Teardown() { +void NonBlockingInvalidator::Core::Teardown() { DCHECK(network_task_runner_->BelongsToCurrentThread()); invalidation_notifier_->UnregisterHandler(this); invalidation_notifier_.reset(); network_task_runner_ = NULL; } -void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds( - const ObjectIdSet& ids) { +void NonBlockingInvalidator::Core::UpdateRegisteredIds(const ObjectIdSet& ids) { DCHECK(network_task_runner_->BelongsToCurrentThread()); invalidation_notifier_->UpdateRegisteredIds(this, ids); } -void NonBlockingInvalidationNotifier::Core::SetUniqueId( - const std::string& unique_id) { +void NonBlockingInvalidator::Core::SetUniqueId(const std::string& unique_id) { DCHECK(network_task_runner_->BelongsToCurrentThread()); invalidation_notifier_->SetUniqueId(unique_id); } -void NonBlockingInvalidationNotifier::Core::SetStateDeprecated( +void NonBlockingInvalidator::Core::SetStateDeprecated( const std::string& state) { DCHECK(network_task_runner_->BelongsToCurrentThread()); invalidation_notifier_->SetStateDeprecated(state); } -void NonBlockingInvalidationNotifier::Core::UpdateCredentials( - const std::string& email, const std::string& token) { +void NonBlockingInvalidator::Core::UpdateCredentials(const std::string& email, + const std::string& token) { DCHECK(network_task_runner_->BelongsToCurrentThread()); invalidation_notifier_->UpdateCredentials(email, token); } -void NonBlockingInvalidationNotifier::Core::OnNotificationsEnabled() { +void NonBlockingInvalidator::Core::OnNotificationsEnabled() { DCHECK(network_task_runner_->BelongsToCurrentThread()); delegate_observer_.Call(FROM_HERE, - &SyncNotifierObserver::OnNotificationsEnabled); + &InvalidationHandler::OnNotificationsEnabled); } -void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( +void NonBlockingInvalidator::Core::OnNotificationsDisabled( NotificationsDisabledReason reason) { DCHECK(network_task_runner_->BelongsToCurrentThread()); delegate_observer_.Call( - FROM_HERE, &SyncNotifierObserver::OnNotificationsDisabled, reason); + FROM_HERE, &InvalidationHandler::OnNotificationsDisabled, reason); } -void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( +void NonBlockingInvalidator::Core::OnIncomingNotification( const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(network_task_runner_->BelongsToCurrentThread()); delegate_observer_.Call(FROM_HERE, - &SyncNotifierObserver::OnIncomingNotification, + &InvalidationHandler::OnIncomingNotification, id_state_map, source); } -NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( +NonBlockingInvalidator::NonBlockingInvalidator( const notifier::NotifierOptions& notifier_options, const InvalidationVersionMap& initial_max_invalidation_versions, const std::string& initial_invalidation_state, @@ -164,7 +162,7 @@ NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( if (!network_task_runner_->PostTask( FROM_HERE, base::Bind( - &NonBlockingInvalidationNotifier::Core::Initialize, + &NonBlockingInvalidator::Core::Initialize, core_.get(), notifier_options, initial_max_invalidation_versions, @@ -175,96 +173,90 @@ NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( } } -NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { +NonBlockingInvalidator::~NonBlockingInvalidator() { DCHECK(parent_task_runner_->BelongsToCurrentThread()); if (!network_task_runner_->PostTask( FROM_HERE, - base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, + base::Bind(&NonBlockingInvalidator::Core::Teardown, core_.get()))) { NOTREACHED(); } } -void NonBlockingInvalidationNotifier::RegisterHandler( - SyncNotifierObserver* handler) { +void NonBlockingInvalidator::RegisterHandler(InvalidationHandler* handler) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.RegisterHandler(handler); } -void NonBlockingInvalidationNotifier::UpdateRegisteredIds( - SyncNotifierObserver* handler, - const ObjectIdSet& ids) { +void NonBlockingInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, + const ObjectIdSet& ids) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.UpdateRegisteredIds(handler, ids); if (!network_task_runner_->PostTask( FROM_HERE, base::Bind( - &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, + &NonBlockingInvalidator::Core::UpdateRegisteredIds, core_.get(), registrar_.GetAllRegisteredIds()))) { NOTREACHED(); } } -void NonBlockingInvalidationNotifier::UnregisterHandler( - SyncNotifierObserver* handler) { +void NonBlockingInvalidator::UnregisterHandler(InvalidationHandler* handler) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.UnregisterHandler(handler); } -void NonBlockingInvalidationNotifier::SetUniqueId( - const std::string& unique_id) { +void NonBlockingInvalidator::SetUniqueId(const std::string& unique_id) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); if (!network_task_runner_->PostTask( FROM_HERE, - base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, + base::Bind(&NonBlockingInvalidator::Core::SetUniqueId, core_.get(), unique_id))) { NOTREACHED(); } } -void NonBlockingInvalidationNotifier::SetStateDeprecated( - const std::string& state) { +void NonBlockingInvalidator::SetStateDeprecated(const std::string& state) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); if (!network_task_runner_->PostTask( FROM_HERE, base::Bind( - &NonBlockingInvalidationNotifier::Core::SetStateDeprecated, + &NonBlockingInvalidator::Core::SetStateDeprecated, core_.get(), state))) { NOTREACHED(); } } -void NonBlockingInvalidationNotifier::UpdateCredentials( - const std::string& email, const std::string& token) { +void NonBlockingInvalidator::UpdateCredentials(const std::string& email, + const std::string& token) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); if (!network_task_runner_->PostTask( FROM_HERE, - base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, + base::Bind(&NonBlockingInvalidator::Core::UpdateCredentials, core_.get(), email, token))) { NOTREACHED(); } } -void NonBlockingInvalidationNotifier::SendNotification( - ModelTypeSet changed_types) { +void NonBlockingInvalidator::SendNotification(ModelTypeSet changed_types) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); // InvalidationClient doesn't implement SendNotification(), so no // need to forward on the call. } -void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { +void NonBlockingInvalidator::OnNotificationsEnabled() { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.EmitOnNotificationsEnabled(); } -void NonBlockingInvalidationNotifier::OnNotificationsDisabled( +void NonBlockingInvalidator::OnNotificationsDisabled( NotificationsDisabledReason reason) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.EmitOnNotificationsDisabled(reason); } -void NonBlockingInvalidationNotifier::OnIncomingNotification( +void NonBlockingInvalidator::OnIncomingNotification( const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); diff --git a/sync/notifier/non_blocking_invalidation_notifier.h b/sync/notifier/non_blocking_invalidator.h index 849c9813..cd98fe5 100644 --- a/sync/notifier/non_blocking_invalidation_notifier.h +++ b/sync/notifier/non_blocking_invalidator.h @@ -5,8 +5,8 @@ // An implementation of SyncNotifier that wraps InvalidationNotifier // on its own thread. -#ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ -#define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ +#ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ +#define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ #include <string> @@ -16,10 +16,10 @@ #include "base/memory/weak_ptr.h" #include "jingle/notifier/base/notifier_options.h" #include "sync/internal_api/public/util/weak_handle.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_observer.h" -#include "sync/notifier/sync_notifier_registrar.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/invalidator_registrar.h" namespace base { class SingleThreadTaskRunner; @@ -27,15 +27,15 @@ class SingleThreadTaskRunner; namespace syncer { -// TODO(akalin): Generalize to NonBlockingSyncNotifier +// TODO(akalin): Generalize the interface so it can use any Invalidator. // (http://crbug.com/140409). -class NonBlockingInvalidationNotifier - : public SyncNotifier, - // SyncNotifierObserver to "observe" our Core via WeakHandle. - public SyncNotifierObserver { +class NonBlockingInvalidator + : public Invalidator, + // InvalidationHandler to "observe" our Core via WeakHandle. + public InvalidationHandler { public: // |invalidation_state_tracker| must be initialized. - NonBlockingInvalidationNotifier( + NonBlockingInvalidator( const notifier::NotifierOptions& notifier_options, const InvalidationVersionMap& initial_max_invalidation_versions, const std::string& initial_invalidation_state, @@ -43,20 +43,20 @@ class NonBlockingInvalidationNotifier invalidation_state_tracker, const std::string& client_info); - virtual ~NonBlockingInvalidationNotifier(); + virtual ~NonBlockingInvalidator(); - // SyncNotifier implementation. - virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; - virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, + // Invalidator implementation. + virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; + virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; virtual void SetStateDeprecated(const std::string& state) OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; - // SyncNotifierObserver implementation. + // InvalidationHandler implementation. virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; @@ -67,19 +67,19 @@ class NonBlockingInvalidationNotifier private: class Core; - base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; + base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; - SyncNotifierRegistrar registrar_; + InvalidatorRegistrar registrar_; - // The real guts of NonBlockingInvalidationNotifier, which allows - // this class to live completely on the parent thread. + // The real guts of NonBlockingInvalidator, which allows this class to live + // completely on the parent thread. scoped_refptr<Core> core_; scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; - DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); + DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); }; } // namespace syncer -#endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ +#endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ diff --git a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/sync/notifier/non_blocking_invalidator_unittest.cc index a749b64..8704cd2 100644 --- a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc +++ b/sync/notifier/non_blocking_invalidator_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/non_blocking_invalidation_notifier.h" +#include "sync/notifier/non_blocking_invalidator.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -14,7 +14,7 @@ #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/util/weak_handle.h" -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" @@ -27,9 +27,9 @@ namespace { using ::testing::InSequence; using ::testing::StrictMock; -class NonBlockingInvalidationNotifierTest : public testing::Test { +class NonBlockingInvalidatorTest : public testing::Test { public: - NonBlockingInvalidationNotifierTest() : io_thread_("Test IO thread") {} + NonBlockingInvalidatorTest() : io_thread_("Test IO thread") {} protected: virtual void SetUp() { @@ -41,17 +41,17 @@ class NonBlockingInvalidationNotifierTest : public testing::Test { notifier::NotifierOptions notifier_options; notifier_options.request_context_getter = request_context_getter_; invalidation_notifier_.reset( - new NonBlockingInvalidationNotifier( + new NonBlockingInvalidator( notifier_options, InvalidationVersionMap(), std::string(), // initial_invalidation_state MakeWeakHandle(base::WeakPtr<InvalidationStateTracker>()), "fake_client_info")); - invalidation_notifier_->RegisterHandler(&fake_observer_); + invalidation_notifier_->RegisterHandler(&fake_handler_); } virtual void TearDown() { - invalidation_notifier_->UnregisterHandler(&fake_observer_); + invalidation_notifier_->UnregisterHandler(&fake_handler_); invalidation_notifier_.reset(); request_context_getter_ = NULL; io_thread_.Stop(); @@ -61,21 +61,21 @@ class NonBlockingInvalidationNotifierTest : public testing::Test { MessageLoop ui_loop_; base::Thread io_thread_; scoped_refptr<net::URLRequestContextGetter> request_context_getter_; - scoped_ptr<NonBlockingInvalidationNotifier> invalidation_notifier_; - FakeSyncNotifierObserver fake_observer_; + scoped_ptr<NonBlockingInvalidator> invalidation_notifier_; + FakeInvalidationHandler fake_handler_; notifier::FakeBaseTask fake_base_task_; }; // TODO(akalin): Add real unit tests (http://crbug.com/140410). -TEST_F(NonBlockingInvalidationNotifierTest, Basic) { +TEST_F(NonBlockingInvalidatorTest, Basic) { const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); const ObjectIdStateMap& id_state_map = ModelTypeStateMapToObjectIdStateMap( ModelTypeSetToStateMap(models, "payload")); invalidation_notifier_->UpdateRegisteredIds( - &fake_observer_, ModelTypeSetToObjectIdSet(models)); + &fake_handler_, ModelTypeSetToObjectIdSet(models)); invalidation_notifier_->SetStateDeprecated("fake_state"); invalidation_notifier_->SetUniqueId("fake_id"); @@ -83,23 +83,23 @@ TEST_F(NonBlockingInvalidationNotifierTest, Basic) { invalidation_notifier_->OnNotificationsEnabled(); EXPECT_EQ(NO_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); invalidation_notifier_->OnIncomingNotification( id_state_map, REMOTE_NOTIFICATION); EXPECT_THAT(id_state_map, - Eq(fake_observer_.GetLastNotificationIdStateMap())); - EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource()); + Eq(fake_handler_.GetLastNotificationIdStateMap())); + EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); invalidation_notifier_->OnNotificationsDisabled( TRANSIENT_NOTIFICATION_ERROR); EXPECT_EQ(TRANSIENT_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); invalidation_notifier_->OnNotificationsDisabled( NOTIFICATION_CREDENTIALS_REJECTED); EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); ui_loop_.RunAllPending(); } diff --git a/sync/notifier/p2p_notifier.cc b/sync/notifier/p2p_invalidator.cc index 44fa05a..34822ff 100644 --- a/sync/notifier/p2p_notifier.cc +++ b/sync/notifier/p2p_invalidator.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/p2p_notifier.h" +#include "sync/notifier/p2p_invalidator.h" #include <algorithm> @@ -12,8 +12,8 @@ #include "base/values.h" #include "jingle/notifier/listener/push_client.h" #include "sync/internal_api/public/base/model_type_state_map.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidation_util.h" -#include "sync/notifier/sync_notifier_observer.h" namespace syncer { @@ -141,8 +141,8 @@ bool P2PNotificationData::ResetFromString(const std::string& str) { return true; } -P2PNotifier::P2PNotifier(scoped_ptr<notifier::PushClient> push_client, - P2PNotificationTarget send_notification_target) +P2PInvalidator::P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, + P2PNotificationTarget send_notification_target) : push_client_(push_client.Pass()), logged_in_(false), notifications_enabled_(false), @@ -152,17 +152,17 @@ P2PNotifier::P2PNotifier(scoped_ptr<notifier::PushClient> push_client, push_client_->AddObserver(this); } -P2PNotifier::~P2PNotifier() { +P2PInvalidator::~P2PInvalidator() { DCHECK(thread_checker_.CalledOnValidThread()); push_client_->RemoveObserver(this); } -void P2PNotifier::RegisterHandler(SyncNotifierObserver* handler) { +void P2PInvalidator::RegisterHandler(InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); registrar_.RegisterHandler(handler); } -void P2PNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, +void P2PInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) { // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411). DCHECK(thread_checker_.CalledOnValidThread()); @@ -177,22 +177,22 @@ void P2PNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, enabled_types_ = enabled_types; } -void P2PNotifier::UnregisterHandler(SyncNotifierObserver* handler) { +void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { DCHECK(thread_checker_.CalledOnValidThread()); registrar_.UnregisterHandler(handler); } -void P2PNotifier::SetUniqueId(const std::string& unique_id) { +void P2PInvalidator::SetUniqueId(const std::string& unique_id) { DCHECK(thread_checker_.CalledOnValidThread()); unique_id_ = unique_id; } -void P2PNotifier::SetStateDeprecated(const std::string& state) { +void P2PInvalidator::SetStateDeprecated(const std::string& state) { DCHECK(thread_checker_.CalledOnValidThread()); // Do nothing. } -void P2PNotifier::UpdateCredentials( +void P2PInvalidator::UpdateCredentials( const std::string& email, const std::string& token) { DCHECK(thread_checker_.CalledOnValidThread()); notifier::Subscription subscription; @@ -209,14 +209,14 @@ void P2PNotifier::UpdateCredentials( logged_in_ = true; } -void P2PNotifier::SendNotification(ModelTypeSet changed_types) { +void P2PInvalidator::SendNotification(ModelTypeSet changed_types) { DCHECK(thread_checker_.CalledOnValidThread()); const P2PNotificationData notification_data( unique_id_, send_notification_target_, changed_types); SendNotificationData(notification_data); } -void P2PNotifier::OnNotificationsEnabled() { +void P2PInvalidator::OnNotificationsEnabled() { DCHECK(thread_checker_.CalledOnValidThread()); bool just_turned_on = (notifications_enabled_ == false); notifications_enabled_ = true; @@ -228,13 +228,13 @@ void P2PNotifier::OnNotificationsEnabled() { } } -void P2PNotifier::OnNotificationsDisabled( +void P2PInvalidator::OnNotificationsDisabled( notifier::NotificationsDisabledReason reason) { DCHECK(thread_checker_.CalledOnValidThread()); registrar_.EmitOnNotificationsDisabled(FromNotifierReason(reason)); } -void P2PNotifier::OnIncomingNotification( +void P2PInvalidator::OnIncomingNotification( const notifier::Notification& notification) { DCHECK(thread_checker_.CalledOnValidThread()); DVLOG(1) << "Received notification " << notification.ToString(); @@ -275,13 +275,13 @@ void P2PNotifier::OnIncomingNotification( REMOTE_NOTIFICATION); } -void P2PNotifier::SendNotificationDataForTest( +void P2PInvalidator::SendNotificationDataForTest( const P2PNotificationData& notification_data) { DCHECK(thread_checker_.CalledOnValidThread()); SendNotificationData(notification_data); } -void P2PNotifier::SendNotificationData( +void P2PInvalidator::SendNotificationData( const P2PNotificationData& notification_data) { DCHECK(thread_checker_.CalledOnValidThread()); if (notification_data.GetChangedTypes().Empty()) { diff --git a/sync/notifier/p2p_notifier.h b/sync/notifier/p2p_invalidator.h index 4457c6f..ce486ac 100644 --- a/sync/notifier/p2p_notifier.h +++ b/sync/notifier/p2p_invalidator.h @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// A notifier that uses p2p notifications based on XMPP push +// An invalidator that uses p2p notifications based on XMPP push // notifications. Used only for sync integration tests. -#ifndef SYNC_NOTIFIER_P2P_NOTIFIER_H_ -#define SYNC_NOTIFIER_P2P_NOTIFIER_H_ +#ifndef SYNC_NOTIFIER_P2P_INVALIDATOR_H_ +#define SYNC_NOTIFIER_P2P_INVALIDATOR_H_ #include <string> @@ -18,9 +18,9 @@ #include "base/threading/thread_checker.h" #include "jingle/notifier/listener/push_client_observer.h" #include "sync/internal_api/public/base/model_type.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/invalidator_registrar.h" #include "sync/notifier/notifications_disabled_reason.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_registrar.h" namespace notifier { class PushClient; @@ -82,24 +82,24 @@ class P2PNotificationData { ModelTypeSet changed_types_; }; -class P2PNotifier : public SyncNotifier, - public notifier::PushClientObserver { +class P2PInvalidator : public Invalidator, + public notifier::PushClientObserver { public: // The |send_notification_target| parameter was added to allow us to send // self-notifications in some cases, but not others. The value should be // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS // to send notifications to all clients except for the one that triggered the // notification. See crbug.com/97780. - P2PNotifier(scoped_ptr<notifier::PushClient> push_client, - P2PNotificationTarget send_notification_target); + P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, + P2PNotificationTarget send_notification_target); - virtual ~P2PNotifier(); + virtual ~P2PInvalidator(); - // SyncNotifier implementation - virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; - virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, + // Invalidator implementation + virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredIds(InvalidationHandler* handler, const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; + virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; virtual void SetStateDeprecated(const std::string& state) OVERRIDE; virtual void UpdateCredentials( @@ -121,7 +121,7 @@ class P2PNotifier : public SyncNotifier, base::ThreadChecker thread_checker_; - SyncNotifierRegistrar registrar_; + InvalidatorRegistrar registrar_; // The push client. scoped_ptr<notifier::PushClient> push_client_; @@ -134,8 +134,10 @@ class P2PNotifier : public SyncNotifier, P2PNotificationTarget send_notification_target_; ModelTypeSet enabled_types_; + + DISALLOW_COPY_AND_ASSIGN(P2PInvalidator); }; } // namespace syncer -#endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ +#endif // SYNC_NOTIFIER_P2P_INVALIDATOR_H_ diff --git a/sync/notifier/p2p_notifier_unittest.cc b/sync/notifier/p2p_invalidator_unittest.cc index 6a62038b..c169cdf 100644 --- a/sync/notifier/p2p_notifier_unittest.cc +++ b/sync/notifier/p2p_invalidator_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/notifier/p2p_notifier.h" +#include "sync/notifier/p2p_invalidator.h" #include <cstddef> #include "jingle/notifier/listener/fake_push_client.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_state_map.h" -#include "sync/notifier/fake_sync_notifier_observer.h" +#include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -17,19 +17,19 @@ namespace syncer { namespace { -class P2PNotifierTest : public testing::Test { +class P2PInvalidatorTest : public testing::Test { protected: - P2PNotifierTest() + P2PInvalidatorTest() : fake_push_client_(new notifier::FakePushClient()), p2p_notifier_( scoped_ptr<notifier::PushClient>(fake_push_client_), NOTIFY_OTHERS), next_sent_notification_to_reflect_(0) { - p2p_notifier_.RegisterHandler(&fake_observer_); + p2p_notifier_.RegisterHandler(&fake_handler_); } - virtual ~P2PNotifierTest() { - p2p_notifier_.UnregisterHandler(&fake_observer_); + virtual ~P2PInvalidatorTest() { + p2p_notifier_.UnregisterHandler(&fake_handler_); } ModelTypeStateMap MakeStateMap(ModelTypeSet types) { @@ -50,15 +50,15 @@ class P2PNotifierTest : public testing::Test { // Owned by |p2p_notifier_|. notifier::FakePushClient* fake_push_client_; - P2PNotifier p2p_notifier_; - FakeSyncNotifierObserver fake_observer_; + P2PInvalidator p2p_notifier_; + FakeInvalidationHandler fake_handler_; private: size_t next_sent_notification_to_reflect_; }; // Make sure the P2PNotificationTarget <-> string conversions work. -TEST_F(P2PNotifierTest, P2PNotificationTarget) { +TEST_F(P2PInvalidatorTest, P2PNotificationTarget) { for (int i = FIRST_NOTIFICATION_TARGET; i <= LAST_NOTIFICATION_TARGET; ++i) { P2PNotificationTarget target = static_cast<P2PNotificationTarget>(i); @@ -70,7 +70,7 @@ TEST_F(P2PNotifierTest, P2PNotificationTarget) { } // Make sure notification targeting works correctly. -TEST_F(P2PNotifierTest, P2PNotificationDataIsTargeted) { +TEST_F(P2PInvalidatorTest, P2PNotificationDataIsTargeted) { { const P2PNotificationData notification_data( "sender", NOTIFY_SELF, ModelTypeSet()); @@ -96,7 +96,7 @@ TEST_F(P2PNotifierTest, P2PNotificationDataIsTargeted) { // Make sure the P2PNotificationData <-> string conversions work for a // default-constructed P2PNotificationData. -TEST_F(P2PNotifierTest, P2PNotificationDataDefault) { +TEST_F(P2PInvalidatorTest, P2PNotificationDataDefault) { const P2PNotificationData notification_data; EXPECT_TRUE(notification_data.IsTargeted("")); EXPECT_FALSE(notification_data.IsTargeted("other1")); @@ -114,7 +114,7 @@ TEST_F(P2PNotifierTest, P2PNotificationDataDefault) { // Make sure the P2PNotificationData <-> string conversions work for a // non-default-constructed P2PNotificationData. -TEST_F(P2PNotifierTest, P2PNotificationDataNonDefault) { +TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { const ModelTypeSet changed_types(BOOKMARKS, THEMES); const P2PNotificationData notification_data( "sender", NOTIFY_ALL, changed_types); @@ -133,14 +133,14 @@ TEST_F(P2PNotifierTest, P2PNotificationDataNonDefault) { EXPECT_TRUE(notification_data.Equals(notification_data_parsed)); } -// Set up the P2PNotifier, simulate a successful connection, and send +// Set up the P2PInvalidator, simulate a successful connection, and send // a notification with the default target (NOTIFY_OTHERS). The // observer should receive only a notification from the call to // UpdateEnabledTypes(). -TEST_F(P2PNotifierTest, NotificationsBasic) { +TEST_F(P2PInvalidatorTest, NotificationsBasic) { const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES); - p2p_notifier_.UpdateRegisteredIds(&fake_observer_, + p2p_notifier_.UpdateRegisteredIds(&fake_handler_, ModelTypeSetToObjectIdSet(enabled_types)); p2p_notifier_.SetUniqueId("sender"); @@ -162,35 +162,35 @@ TEST_F(P2PNotifierTest, NotificationsBasic) { ReflectSentNotifications(); fake_push_client_->EnableNotifications(); EXPECT_EQ(NO_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); ReflectSentNotifications(); - EXPECT_EQ(1, fake_observer_.GetNotificationCount()); + EXPECT_EQ(1, fake_handler_.GetNotificationCount()); EXPECT_THAT( ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), - Eq(fake_observer_.GetLastNotificationIdStateMap())); - EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource()); + Eq(fake_handler_.GetLastNotificationIdStateMap())); + EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); // Sent with target NOTIFY_OTHERS so should not be propagated to - // |fake_observer_|. + // |fake_handler_|. { ModelTypeSet changed_types(THEMES, APPS); p2p_notifier_.SendNotification(changed_types); } ReflectSentNotifications(); - EXPECT_EQ(1, fake_observer_.GetNotificationCount()); + EXPECT_EQ(1, fake_handler_.GetNotificationCount()); } -// Set up the P2PNotifier and send out notifications with various +// Set up the P2PInvalidator and send out notifications with various // target settings. The notifications received by the observer should // be consistent with the target settings. -TEST_F(P2PNotifierTest, SendNotificationData) { +TEST_F(P2PInvalidatorTest, SendNotificationData) { const ModelTypeSet enabled_types(BOOKMARKS, PREFERENCES, THEMES); const ModelTypeSet changed_types(THEMES, APPS); const ModelTypeSet expected_types(THEMES); - p2p_notifier_.UpdateRegisteredIds(&fake_observer_, + p2p_notifier_.UpdateRegisteredIds(&fake_handler_, ModelTypeSetToObjectIdSet(enabled_types)); p2p_notifier_.SetUniqueId("sender"); @@ -199,19 +199,19 @@ TEST_F(P2PNotifierTest, SendNotificationData) { ReflectSentNotifications(); fake_push_client_->EnableNotifications(); EXPECT_EQ(NO_NOTIFICATION_ERROR, - fake_observer_.GetNotificationsDisabledReason()); + fake_handler_.GetNotificationsDisabledReason()); ReflectSentNotifications(); - EXPECT_EQ(1, fake_observer_.GetNotificationCount()); + EXPECT_EQ(1, fake_handler_.GetNotificationCount()); EXPECT_THAT( ModelTypeStateMapToObjectIdStateMap(MakeStateMap(enabled_types)), - Eq(fake_observer_.GetLastNotificationIdStateMap())); - EXPECT_EQ(REMOTE_NOTIFICATION, fake_observer_.GetLastNotificationSource()); + Eq(fake_handler_.GetLastNotificationIdStateMap())); + EXPECT_EQ(REMOTE_NOTIFICATION, fake_handler_.GetLastNotificationSource()); // Should be dropped. p2p_notifier_.SendNotificationDataForTest(P2PNotificationData()); ReflectSentNotifications(); - EXPECT_EQ(1, fake_observer_.GetNotificationCount()); + EXPECT_EQ(1, fake_handler_.GetNotificationCount()); const ObjectIdStateMap& expected_ids = ModelTypeStateMapToObjectIdStateMap(MakeStateMap(expected_types)); @@ -220,67 +220,67 @@ TEST_F(P2PNotifierTest, SendNotificationData) { p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_SELF, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(2, fake_observer_.GetNotificationCount()); + EXPECT_EQ(2, fake_handler_.GetNotificationCount()); EXPECT_THAT( expected_ids, - Eq(fake_observer_.GetLastNotificationIdStateMap())); + Eq(fake_handler_.GetLastNotificationIdStateMap())); // Should be dropped. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_SELF, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(2, fake_observer_.GetNotificationCount()); + EXPECT_EQ(2, fake_handler_.GetNotificationCount()); // Should be dropped. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_SELF, ModelTypeSet())); ReflectSentNotifications(); - EXPECT_EQ(2, fake_observer_.GetNotificationCount()); + EXPECT_EQ(2, fake_handler_.GetNotificationCount()); // Should be dropped. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_OTHERS, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(2, fake_observer_.GetNotificationCount()); + EXPECT_EQ(2, fake_handler_.GetNotificationCount()); // Should be propagated. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_OTHERS, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(3, fake_observer_.GetNotificationCount()); + EXPECT_EQ(3, fake_handler_.GetNotificationCount()); EXPECT_THAT( expected_ids, - Eq(fake_observer_.GetLastNotificationIdStateMap())); + Eq(fake_handler_.GetLastNotificationIdStateMap())); // Should be dropped. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_OTHERS, ModelTypeSet())); ReflectSentNotifications(); - EXPECT_EQ(3, fake_observer_.GetNotificationCount()); + EXPECT_EQ(3, fake_handler_.GetNotificationCount()); // Should be propagated. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_ALL, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(4, fake_observer_.GetNotificationCount()); + EXPECT_EQ(4, fake_handler_.GetNotificationCount()); EXPECT_THAT( expected_ids, - Eq(fake_observer_.GetLastNotificationIdStateMap())); + Eq(fake_handler_.GetLastNotificationIdStateMap())); // Should be propagated. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_ALL, changed_types)); ReflectSentNotifications(); - EXPECT_EQ(5, fake_observer_.GetNotificationCount()); + EXPECT_EQ(5, fake_handler_.GetNotificationCount()); EXPECT_THAT( expected_ids, - Eq(fake_observer_.GetLastNotificationIdStateMap())); + Eq(fake_handler_.GetLastNotificationIdStateMap())); // Should be dropped. p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_ALL, ModelTypeSet())); ReflectSentNotifications(); - EXPECT_EQ(5, fake_observer_.GetNotificationCount()); + EXPECT_EQ(5, fake_handler_.GetNotificationCount()); } } // namespace diff --git a/sync/sync.gyp b/sync/sync.gyp index 397d057..369605b 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -253,18 +253,18 @@ '../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation', ], 'sources': [ + 'notifier/invalidation_handler.h', 'notifier/invalidation_util.cc', 'notifier/invalidation_util.h', + 'notifier/invalidator_factory.cc', + 'notifier/invalidator_factory.h', + 'notifier/invalidator.h', + 'notifier/invalidator_registrar.cc', + 'notifier/invalidator_registrar.h', 'notifier/notifications_disabled_reason.cc', 'notifier/notifications_disabled_reason.h', 'notifier/object_id_state_map.cc', 'notifier/object_id_state_map.h', - 'notifier/sync_notifier.h', - 'notifier/sync_notifier_factory.cc', - 'notifier/sync_notifier_factory.h', - 'notifier/sync_notifier_observer.h', - 'notifier/sync_notifier_registrar.cc', - 'notifier/sync_notifier_registrar.h', ], 'conditions': [ ['OS != "android"', { @@ -276,10 +276,10 @@ 'notifier/invalidation_notifier.cc', 'notifier/invalidation_notifier.h', 'notifier/invalidation_state_tracker.h', - 'notifier/non_blocking_invalidation_notifier.cc', - 'notifier/non_blocking_invalidation_notifier.h', - 'notifier/p2p_notifier.cc', - 'notifier/p2p_notifier.h', + 'notifier/non_blocking_invalidator.cc', + 'notifier/non_blocking_invalidator.h', + 'notifier/p2p_invalidator.cc', + 'notifier/p2p_invalidator.h', 'notifier/push_client_channel.cc', 'notifier/push_client_channel.h', 'notifier/registration_manager.cc', @@ -480,10 +480,10 @@ 'sources': [ 'notifier/fake_invalidation_state_tracker.cc', 'notifier/fake_invalidation_state_tracker.h', - 'notifier/fake_sync_notifier.cc', - 'notifier/fake_sync_notifier.h', - 'notifier/fake_sync_notifier_observer.cc', - 'notifier/fake_sync_notifier_observer.h', + 'notifier/fake_invalidator.cc', + 'notifier/fake_invalidator.h', + 'notifier/fake_invalidation_handler.cc', + 'notifier/fake_invalidation_handler.h', 'notifier/object_id_state_map_test_util.cc', 'notifier/object_id_state_map_test_util.h', ], @@ -664,7 +664,7 @@ '..', ], 'sources': [ - 'notifier/sync_notifier_factory_unittest.cc', + 'notifier/invalidator_factory_unittest.cc', ], 'conditions': [ ['OS != "android"', { @@ -672,11 +672,11 @@ 'notifier/chrome_invalidation_client_unittest.cc', 'notifier/chrome_system_resources_unittest.cc', 'notifier/invalidation_notifier_unittest.cc', - 'notifier/non_blocking_invalidation_notifier_unittest.cc', - 'notifier/p2p_notifier_unittest.cc', + 'notifier/invalidator_registrar_unittest.cc', + 'notifier/non_blocking_invalidator_unittest.cc', + 'notifier/p2p_invalidator_unittest.cc', 'notifier/push_client_channel_unittest.cc', 'notifier/registration_manager_unittest.cc', - 'notifier/sync_notifier_registrar_unittest.cc', ], }], ], diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc index 5f6de2a..9047d48 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -41,8 +41,8 @@ #include "sync/js/js_event_details.h" #include "sync/js/js_event_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_factory.h" +#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/invalidator.h" #include "sync/test/fake_encryptor.h" #if defined(OS_MACOSX) @@ -308,7 +308,7 @@ int SyncClientMain(int argc, char* argv[]) { ParseNotifierOptions(command_line, context_getter); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; - SyncNotifierFactory sync_notifier_factory( + InvalidatorFactory invalidator_factory( notifier_options, kClientInfo, null_invalidation_state_tracker.AsWeakPtr()); @@ -368,8 +368,8 @@ int SyncClientMain(int argc, char* argv[]) { extensions_activity_monitor, &change_delegate, credentials, - scoped_ptr<SyncNotifier>( - sync_notifier_factory.CreateSyncNotifier()), + scoped_ptr<Invalidator>( + invalidator_factory.CreateInvalidator()), kRestoredKeyForBootstrapping, kRestoredKeystoreKeyForBootstrapping, scoped_ptr<InternalComponentsFactory>( diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index ef5ef19..3f3955c 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -26,10 +26,10 @@ #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/notifier/invalidation_state_tracker.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidation_util.h" -#include "sync/notifier/sync_notifier.h" -#include "sync/notifier/sync_notifier_factory.h" -#include "sync/notifier/sync_notifier_observer.h" +#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/invalidator.h" #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" @@ -49,7 +49,7 @@ const char kAllowInsecureConnectionSwitch[] = "allow-insecure-connection"; const char kNotificationMethodSwitch[] = "notification-method"; // Class to print received notifications events. -class NotificationPrinter : public SyncNotifierObserver { +class NotificationPrinter : public InvalidationHandler { public: NotificationPrinter() {} virtual ~NotificationPrinter() {} @@ -233,25 +233,25 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; - SyncNotifierFactory sync_notifier_factory( + InvalidatorFactory invalidator_factory( notifier_options, kClientInfo, null_invalidation_state_tracker.AsWeakPtr()); - scoped_ptr<SyncNotifier> sync_notifier( - sync_notifier_factory.CreateSyncNotifier()); + scoped_ptr<Invalidator> invalidator( + invalidator_factory.CreateInvalidator()); NotificationPrinter notification_printer; const char kUniqueId[] = "fake_unique_id"; - sync_notifier->SetUniqueId(kUniqueId); - sync_notifier->UpdateCredentials(email, token); + invalidator->SetUniqueId(kUniqueId); + invalidator->UpdateCredentials(email, token); // Listen for notifications for all known types. - sync_notifier->RegisterHandler(¬ification_printer); - sync_notifier->UpdateRegisteredIds( + invalidator->RegisterHandler(¬ification_printer); + invalidator->UpdateRegisteredIds( ¬ification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())); ui_loop.Run(); - sync_notifier->UnregisterHandler(¬ification_printer); + invalidator->UnregisterHandler(¬ification_printer); io_thread.Stop(); return 0; } |