diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-29 01:45:09 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-29 01:45:09 +0000 |
commit | dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31 (patch) | |
tree | 20b4a2df530ac7c83bcc5e7d460137e97846685e | |
parent | c146a323f91c8376afe55c93c6a31df0075be62b (diff) | |
download | chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.zip chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.tar.gz chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.tar.bz2 |
Use InvalidationService (retry of r208315)
The InvalidationService was introduced r199520. That commit added the
InvalidationService interface and several implementations of it, but
made no use of the new code. This commit builds on that work.
Up until now, TICL invalidations were handled on the sync thread. The
related objects were instantiated and owned by the SyncBackendHost and
SyncManager. All requests to update the set of object registrations had
to be passed to the sync thread. Components that wanted to receive
invalidations but were not part of sync had to route their communication
with the invalidations server through ProfileSyncService to get to the
sync thread. Things were a bit different on Android, but the system
still tried to pretend that invalidations were owned by the sync thread.
The new InvalidationService implementation is a ProfileKeyedService that
is mostly independent from sync. It still relies on sync to manage sign
in and fetch the appropriate auth tokens. However, it's now much easier
for components outside of sync to communication with the invalidations
server.
The new system allows us to remove a lot of invalidations-related code
from the ProfileSyncService, SyncBackendHost and SyncManager. Sync is
now just one of many clients of the InvalidationService. The
SyncBackendHost is responsible for forwarding messages back and forth
between the InvalidationService and the sync thread.
TBR=dcheng,satorux1,battre,rsimha,bauerb,sky,erg
BUG=124137
Review URL: https://chromiumcodereview.appspot.com/17699005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209264 0039d316-1c4b-4281-b951-d872f2087c98
81 files changed, 961 insertions, 2041 deletions
diff --git a/chrome/browser/chrome_to_mobile_service.cc b/chrome/browser/chrome_to_mobile_service.cc index 4233625..7bd833f 100644 --- a/chrome/browser/chrome_to_mobile_service.cc +++ b/chrome/browser/chrome_to_mobile_service.cc @@ -15,12 +15,12 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/chrome_to_mobile_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/printing/cloud_print/cloud_print_url.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_finder.h" @@ -261,23 +261,24 @@ void ChromeToMobileService::RegisterUserPrefs( ChromeToMobileService::ChromeToMobileService(Profile* profile) : weak_ptr_factory_(this), profile_(profile), - sync_invalidation_enabled_(false) { + invalidation_enabled_(false) { // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183 - ProfileSyncService* profile_sync_service = - profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; - if (profile_sync_service) { + + invalidation::InvalidationService* invalidation_service = profile_ ? + invalidation::InvalidationServiceFactory::GetForProfile(profile_) : NULL; + if (invalidation_service) { CloudPrintURL cloud_print_url(profile_); cloud_print_url_ = cloud_print_url.GetCloudPrintServiceURL(); - sync_invalidation_enabled_ = - (profile_sync_service->GetInvalidatorState() == + invalidation_enabled_ = + (invalidation_service->GetInvalidatorState() == syncer::INVALIDATIONS_ENABLED); // Register for cloud print device list invalidation notifications. - profile_sync_service->RegisterInvalidationHandler(this); + invalidation_service->RegisterInvalidationHandler(this); syncer::ObjectIdSet ids; ids.insert(invalidation::ObjectId( ipc::invalidation::ObjectSource::CHROME_COMPONENTS, kSyncInvalidationObjectIdChromeToMobileDeviceList)); - profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); + invalidation_service->UpdateRegisteredInvalidationIds(this, ids); } } @@ -292,7 +293,7 @@ bool ChromeToMobileService::HasMobiles() const { } const base::ListValue* ChromeToMobileService::GetMobiles() const { - return sync_invalidation_enabled_ ? + return invalidation_enabled_ ? profile_->GetPrefs()->GetList(prefs::kChromeToMobileDeviceList) : NULL; } @@ -384,10 +385,10 @@ void ChromeToMobileService::LearnMore(Browser* browser) const { void ChromeToMobileService::Shutdown() { // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183 // Unregister for cloud print device list invalidation notifications. - ProfileSyncService* profile_sync_service = - profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; - if (profile_sync_service) - profile_sync_service->UnregisterInvalidationHandler(this); + invalidation::InvalidationService* invalidation_service = profile_ ? + invalidation::InvalidationServiceFactory::GetForProfile(profile_) : NULL; + if (invalidation_service) + invalidation_service->UnregisterInvalidationHandler(this); } void ChromeToMobileService::OnURLFetchComplete(const net::URLFetcher* source) { @@ -472,7 +473,7 @@ void ChromeToMobileService::OnGetTokenFailure( void ChromeToMobileService::OnInvalidatorStateChange( syncer::InvalidatorState state) { - sync_invalidation_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); + invalidation_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); } void ChromeToMobileService::OnIncomingInvalidation( @@ -482,12 +483,12 @@ void ChromeToMobileService::OnIncomingInvalidation( ipc::invalidation::ObjectSource::CHROME_COMPONENTS, kSyncInvalidationObjectIdChromeToMobileDeviceList))); // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183 - ProfileSyncService* profile_sync_service = - profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; - if (profile_sync_service) { + invalidation::InvalidationService* invalidation_service = profile_ ? + invalidation::InvalidationServiceFactory::GetForProfile(profile_) : NULL; + if (invalidation_service) { // TODO(dcheng): Only acknowledge the invalidation once the device search // has finished. http://crbug.com/156843. - profile_sync_service->AcknowledgeInvalidation( + invalidation_service->AcknowledgeInvalidation( invalidation_map.begin()->first, invalidation_map.begin()->second.ack_handle); } diff --git a/chrome/browser/chrome_to_mobile_service.h b/chrome/browser/chrome_to_mobile_service.h index ff297b9..7f8391d 100644 --- a/chrome/browser/chrome_to_mobile_service.h +++ b/chrome/browser/chrome_to_mobile_service.h @@ -201,9 +201,9 @@ class ChromeToMobileService : public BrowserContextKeyedService, Profile* profile_; - // Sync invalidation service state. Chrome To Mobile requires this service to - // to keep the mobile device list up to date and prevent page send failures. - bool sync_invalidation_enabled_; + // Invalidation service state. Chrome To Mobile requires this service to keep + // the mobile device list up to date and prevent page send failures. + bool invalidation_enabled_; // Used to recieve TokenService notifications for GaiaOAuth2LoginRefreshToken. content::NotificationRegistrar registrar_; diff --git a/chrome/browser/chrome_to_mobile_service_factory.cc b/chrome/browser/chrome_to_mobile_service_factory.cc index 3c1150a..8b1c0c4 100644 --- a/chrome/browser/chrome_to_mobile_service_factory.cc +++ b/chrome/browser/chrome_to_mobile_service_factory.cc @@ -5,9 +5,9 @@ #include "chrome/browser/chrome_to_mobile_service_factory.h" #include "chrome/browser/chrome_to_mobile_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/token_service_factory.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" // static @@ -36,7 +36,7 @@ ChromeToMobileServiceFactory::ChromeToMobileServiceFactory() : BrowserContextKeyedServiceFactory( "ChromeToMobileService", BrowserContextDependencyManager::GetInstance()) { - DependsOn(ProfileSyncServiceFactory::GetInstance()); + DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); DependsOn(TokenServiceFactory::GetInstance()); // TODO(msw): Uncomment this once it exists. // DependsOn(PrefServiceFactory::GetInstance()); diff --git a/chrome/browser/chrome_to_mobile_service_unittest.cc b/chrome/browser/chrome_to_mobile_service_unittest.cc index 79635c8..3cc210ca 100644 --- a/chrome/browser/chrome_to_mobile_service_unittest.cc +++ b/chrome/browser/chrome_to_mobile_service_unittest.cc @@ -85,6 +85,10 @@ void ChromeToMobileServiceTest::FulfillFeatureRequirements() { // Test that GetMobiles and HasMobiles require Sync Invalidations being enabled. TEST_F(ChromeToMobileServiceTest, GetMobiles) { ChromeToMobileService* service = GetService(); + + // Send a fake notification that Sync Invalidations are disabled. + service->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); + EXPECT_EQ(NULL, service->GetMobiles()); EXPECT_FALSE(service->HasMobiles()); @@ -117,6 +121,9 @@ TEST_F(ChromeToMobileServiceTest, GetMobiles) { // Test fulfilling the requirements to enable the feature. TEST_F(ChromeToMobileServiceTest, RequirementsToEnable) { + // Send a fake notification that Sync Invalidations are disabled. + GetService()->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); + // Navigate to a page with a URL that is valid to send. AddTab(browser(), GURL("http://foo")); EXPECT_FALSE(UpdateAndGetVerifiedCommandState()); diff --git a/chrome/browser/drive/drive_notification_manager.cc b/chrome/browser/drive/drive_notification_manager.cc index 1a4c82e..ae94124 100644 --- a/chrome/browser/drive/drive_notification_manager.cc +++ b/chrome/browser/drive/drive_notification_manager.cc @@ -6,9 +6,9 @@ #include "base/metrics/histogram.h" #include "chrome/browser/drive/drive_notification_observer.h" +#include "chrome/browser/invalidation/invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "google/cacheinvalidation/types.pb.h" namespace drive { @@ -42,15 +42,16 @@ DriveNotificationManager::~DriveNotificationManager() {} void DriveNotificationManager::Shutdown() { // Unregister for Drive notifications. - ProfileSyncService* profile_sync_service = - ProfileSyncServiceFactory::GetForProfile(profile_); - if (!profile_sync_service || !push_notification_registered_) { + invalidation::InvalidationService* invalidation_service = + invalidation::InvalidationServiceFactory::GetForProfile(profile_); + if (!invalidation_service || !push_notification_registered_) { return; } - profile_sync_service->UpdateRegisteredInvalidationIds( - this, syncer::ObjectIdSet()); - profile_sync_service->UnregisterInvalidationHandler(this); + // We unregister the handler without updating unregistering our IDs on + // purpose. See the class comment on the InvalidationService interface for + // more information. + invalidation_service->UnregisterInvalidationHandler(this); } void DriveNotificationManager::OnInvalidatorStateChange( @@ -76,9 +77,10 @@ void DriveNotificationManager::OnIncomingInvalidation( // TODO(dcheng): Only acknowledge the invalidation once the fetch has // completed. http://crbug.com/156843 - ProfileSyncService* profile_sync_service = - ProfileSyncServiceFactory::GetForProfile(profile_); - profile_sync_service->AcknowledgeInvalidation( + invalidation::InvalidationService* invalidation_service = + invalidation::InvalidationServiceFactory::GetForProfile(profile_); + DCHECK(invalidation_service); + invalidation_service->AcknowledgeInvalidation( invalidation_map.begin()->first, invalidation_map.begin()->second.ack_handle); @@ -128,19 +130,19 @@ void DriveNotificationManager::NotifyObserversToUpdate( void DriveNotificationManager::RegisterDriveNotifications() { DCHECK(!push_notification_enabled_); - ProfileSyncService* profile_sync_service = - ProfileSyncServiceFactory::GetForProfile(profile_); - if (!profile_sync_service) + invalidation::InvalidationService* invalidation_service = + invalidation::InvalidationServiceFactory::GetForProfile(profile_); + if (!invalidation_service) return; - profile_sync_service->RegisterInvalidationHandler(this); + invalidation_service->RegisterInvalidationHandler(this); syncer::ObjectIdSet ids; ids.insert(invalidation::ObjectId( ipc::invalidation::ObjectSource::COSMO_CHANGELOG, kDriveInvalidationObjectId)); - profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); + invalidation_service->UpdateRegisteredInvalidationIds(this, ids); push_notification_registered_ = true; - OnInvalidatorStateChange(profile_sync_service->GetInvalidatorState()); + OnInvalidatorStateChange(invalidation_service->GetInvalidatorState()); UMA_HISTOGRAM_BOOLEAN("Drive.PushNotificationRegistered", push_notification_registered_); diff --git a/chrome/browser/drive/drive_notification_manager_factory.cc b/chrome/browser/drive/drive_notification_manager_factory.cc index 0c81194..4792e08 100644 --- a/chrome/browser/drive/drive_notification_manager_factory.cc +++ b/chrome/browser/drive/drive_notification_manager_factory.cc @@ -5,6 +5,7 @@ #include "chrome/browser/drive/drive_notification_manager_factory.h" #include "chrome/browser/drive/drive_notification_manager.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -33,6 +34,7 @@ DriveNotificationManagerFactory::DriveNotificationManagerFactory() "DriveNotificationManager", BrowserContextDependencyManager::GetInstance()) { DependsOn(ProfileSyncServiceFactory::GetInstance()); + DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); } DriveNotificationManagerFactory::~DriveNotificationManagerFactory() {} diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc index c84a393..9d89f17 100644 --- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc @@ -19,11 +19,11 @@ #include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/token_cache/token_cache_service.h" #include "chrome/browser/extensions/token_cache/token_cache_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/api/push_messaging.h" @@ -302,17 +302,18 @@ PushMessagingAPI::GetFactoryInstance() { void PushMessagingAPI::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_); + invalidation::InvalidationService* invalidation_service = + invalidation::InvalidationServiceFactory::GetForProfile(profile_); // This may be NULL; for example, for the ChromeOS guest user. In these cases, // just return without setting up anything, since it won't work anyway. - if (!pss) + if (!invalidation_service) return; if (!event_router_) event_router_.reset(new PushMessagingEventRouter(profile_)); if (!handler_) { handler_.reset(new PushMessagingInvalidationHandler( - pss, event_router_.get())); + invalidation_service, event_router_.get())); } switch (type) { case chrome::NOTIFICATION_EXTENSION_INSTALLED: { @@ -351,7 +352,7 @@ void PushMessagingAPI::SetMapperForTest( template <> void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { DependsOn(ExtensionSystemFactory::GetInstance()); - DependsOn(ProfileSyncServiceFactory::GetInstance()); + DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); } } // namespace extensions diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc index 6960205..6a38470 100644 --- a/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc @@ -10,19 +10,23 @@ #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/extensions/platform_app_launcher.h" +#include "chrome/browser/invalidation/fake_invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "google/cacheinvalidation/types.pb.h" +#include "sync/notifier/fake_invalidator.h" #include "testing/gmock/include/gmock/gmock.h" using ::testing::_; using ::testing::SaveArg; using ::testing::StrictMock; +using invalidation::InvalidationServiceFactory; + namespace extensions { namespace { @@ -52,10 +56,34 @@ MockInvalidationMapper::~MockInvalidationMapper() {} class PushMessagingApiTest : public ExtensionApiTest { public: + PushMessagingApiTest() + : fake_invalidation_service_(NULL) { + } + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionApiTest::SetUpCommandLine(command_line); } + virtual void SetUp() OVERRIDE { + InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); + ExtensionApiTest::SetUp(); + } + + virtual void SetUpOnMainThread() OVERRIDE { + ExtensionApiTest::SetUpOnMainThread(); + fake_invalidation_service_ = + static_cast<invalidation::FakeInvalidationService*>( + InvalidationServiceFactory::GetInstance()->GetForProfile( + profile())); + } + + void EmitInvalidation( + const invalidation::ObjectId& object_id, + const std::string& payload) { + fake_invalidation_service_->EmitInvalidationForTest(object_id, payload); + } + PushMessagingAPI* GetAPI() { return PushMessagingAPI::Get(profile()); } @@ -63,6 +91,8 @@ class PushMessagingApiTest : public ExtensionApiTest { PushMessagingEventRouter* GetEventRouter() { return PushMessagingAPI::Get(profile())->GetEventRouterForTest(); } + + invalidation::FakeInvalidationService* fake_invalidation_service_; }; IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { @@ -92,18 +122,14 @@ IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { ui_test_utils::NavigateToURL( browser(), extension->GetResourceURL("event_dispatch.html")); - ProfileSyncService* pss = - ProfileSyncServiceFactory::GetForProfile(profile()); - ASSERT_TRUE(pss); - // PushMessagingInvalidationHandler suppresses the initial invalidation on // each subchannel at install, so trigger the suppressions first. for (int i = 0; i < 3; ++i) { - pss->EmitInvalidationForTest( + EmitInvalidation( ExtensionAndSubchannelToObjectId(extension->id(), i), std::string()); } - pss->EmitInvalidationForTest( + EmitInvalidation( ExtensionAndSubchannelToObjectId(extension->id(), 1), "payload"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); } diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.cc index 95eb4e7..f9208e5 100644 --- a/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.cc +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.cc @@ -10,7 +10,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_delegate.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "chrome/common/extensions/extension.h" #include "google/cacheinvalidation/types.pb.h" @@ -78,7 +78,7 @@ bool ObjectIdToExtensionAndSubchannel(const invalidation::ObjectId& object_id, } // namespace PushMessagingInvalidationHandler::PushMessagingInvalidationHandler( - invalidation::InvalidationFrontend* service, + invalidation::InvalidationService* service, PushMessagingInvalidationHandlerDelegate* delegate) : service_(service), delegate_(delegate) { 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 ef40b76..4f7d9e3 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 @@ -15,7 +15,7 @@ #include "sync/notifier/invalidation_handler.h" namespace invalidation { -class InvalidationFrontend; +class InvalidationService; } namespace extensions { @@ -32,7 +32,7 @@ class PushMessagingInvalidationHandler : public PushMessagingInvalidationMapper, // |extension_ids| is the set of extension IDs for which push messaging is // enabled. PushMessagingInvalidationHandler( - invalidation::InvalidationFrontend* service, + invalidation::InvalidationService* service, PushMessagingInvalidationHandlerDelegate* delegate); virtual ~PushMessagingInvalidationHandler(); @@ -56,7 +56,7 @@ class PushMessagingInvalidationHandler : public PushMessagingInvalidationMapper, void UpdateRegistrations(); base::ThreadChecker thread_checker_; - invalidation::InvalidationFrontend* const service_; + invalidation::InvalidationService* const service_; std::set<std::string> registered_extensions_; syncer::ObjectIdSet suppressed_ids_; PushMessagingInvalidationHandlerDelegate* const delegate_; 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 9ab280b..9db3b46 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 @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler_delegate.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "google/cacheinvalidation/types.pb.h" #include "sync/internal_api/public/base/invalidation_test_util.h" #include "testing/gmock/include/gmock/gmock.h" @@ -22,10 +22,10 @@ namespace extensions { namespace { -class MockInvalidationFrontend : public invalidation::InvalidationFrontend { +class MockInvalidationService : public invalidation::InvalidationService { public: - MockInvalidationFrontend(); - ~MockInvalidationFrontend(); + MockInvalidationService(); + ~MockInvalidationService(); MOCK_METHOD1(RegisterInvalidationHandler, void(syncer::InvalidationHandler*)); MOCK_METHOD2(UpdateRegisteredInvalidationIds, @@ -35,13 +35,14 @@ class MockInvalidationFrontend : public invalidation::InvalidationFrontend { MOCK_METHOD2(AcknowledgeInvalidation, void(const invalidation::ObjectId&, const syncer::AckHandle&)); MOCK_CONST_METHOD0(GetInvalidatorState, syncer::InvalidatorState()); + MOCK_CONST_METHOD0(GetInvalidatorClientId, std::string()); private: - DISALLOW_COPY_AND_ASSIGN(MockInvalidationFrontend); + DISALLOW_COPY_AND_ASSIGN(MockInvalidationService); }; -MockInvalidationFrontend::MockInvalidationFrontend() {} -MockInvalidationFrontend::~MockInvalidationFrontend() {} +MockInvalidationService::MockInvalidationService() {} +MockInvalidationService::~MockInvalidationService() {} class MockInvalidationHandlerDelegate : public PushMessagingInvalidationHandlerDelegate { @@ -74,7 +75,7 @@ class PushMessagingInvalidationHandlerTest : public ::testing::Test { EXPECT_CALL(service_, UnregisterInvalidationHandler(handler_.get())); handler_.reset(); } - StrictMock<MockInvalidationFrontend> service_; + StrictMock<MockInvalidationService> service_; StrictMock<MockInvalidationHandlerDelegate> delegate_; scoped_ptr<PushMessagingInvalidationHandler> handler_; }; diff --git a/chrome/browser/extensions/api/push_messaging/sync_setup_helper.cc b/chrome/browser/extensions/api/push_messaging/sync_setup_helper.cc index b0292d9..f4dffc3 100644 --- a/chrome/browser/extensions/api/push_messaging/sync_setup_helper.cc +++ b/chrome/browser/extensions/api/push_messaging/sync_setup_helper.cc @@ -29,7 +29,8 @@ SyncSetupHelper::~SyncSetupHelper() {} bool SyncSetupHelper::InitializeSync(Profile* profile) { profile_ = profile; - client_.reset(new ProfileSyncServiceHarness(profile_, username_, password_)); + client_.reset( + ProfileSyncServiceHarness::Create(profile_, username_, password_)); if (client_->service()->IsSyncEnabledAndLoggedIn()) return true; diff --git a/chrome/browser/invalidation/fake_invalidation_service.cc b/chrome/browser/invalidation/fake_invalidation_service.cc new file mode 100644 index 0000000..a54a581 --- /dev/null +++ b/chrome/browser/invalidation/fake_invalidation_service.cc @@ -0,0 +1,62 @@ +// Copyright 2013 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 "chrome/browser/invalidation/fake_invalidation_service.h" + +#include "chrome/browser/invalidation/invalidation_service_util.h" + +namespace invalidation { + +FakeInvalidationService::FakeInvalidationService() + : client_id_(GenerateInvalidatorClientId()) { +} + +FakeInvalidationService::~FakeInvalidationService() { +} + +void FakeInvalidationService::RegisterInvalidationHandler( + syncer::InvalidationHandler* handler) { + invalidator_registrar_.RegisterHandler(handler); +} + +void FakeInvalidationService::UpdateRegisteredInvalidationIds( + syncer::InvalidationHandler* handler, + const syncer::ObjectIdSet& ids) { + invalidator_registrar_.UpdateRegisteredIds(handler, ids); +} + +void FakeInvalidationService::UnregisterInvalidationHandler( + syncer::InvalidationHandler* handler) { + invalidator_registrar_.UnregisterHandler(handler); +} + +void FakeInvalidationService::AcknowledgeInvalidation( + const invalidation::ObjectId& id, + const syncer::AckHandle& ack_handle) { + // TODO(sync): Use assertions to ensure this function is invoked correctly. +} + +syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const { + return syncer::INVALIDATIONS_ENABLED; +} + +std::string FakeInvalidationService::GetInvalidatorClientId() const { + return client_id_; +} + +void FakeInvalidationService::EmitInvalidationForTest( + const invalidation::ObjectId& object_id, + const std::string& payload) { + syncer::ObjectIdInvalidationMap invalidation_map; + + syncer::Invalidation inv; + inv.payload = payload; + inv.ack_handle = syncer::AckHandle::CreateUnique(); + + invalidation_map.insert(std::make_pair(object_id, inv)); + + invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map); +} + +} // namespace invalidation diff --git a/chrome/browser/invalidation/fake_invalidation_service.h b/chrome/browser/invalidation/fake_invalidation_service.h new file mode 100644 index 0000000..50aa619 --- /dev/null +++ b/chrome/browser/invalidation/fake_invalidation_service.h @@ -0,0 +1,48 @@ +// Copyright 2013 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_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ +#define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ + +#include "chrome/browser/invalidation/invalidation_service.h" +#include "sync/notifier/invalidator_registrar.h" + +namespace invalidation { + +// An InvalidationService that emits invalidations only when +// its EmitInvalidationForTest method is called. +class FakeInvalidationService : public InvalidationService { + public: + FakeInvalidationService(); + virtual ~FakeInvalidationService(); + + virtual void RegisterInvalidationHandler( + syncer::InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredInvalidationIds( + syncer::InvalidationHandler* handler, + const syncer::ObjectIdSet& ids) OVERRIDE; + virtual void UnregisterInvalidationHandler( + syncer::InvalidationHandler* handler) OVERRIDE; + + virtual void AcknowledgeInvalidation( + const invalidation::ObjectId& id, + const syncer::AckHandle& ack_handle) OVERRIDE; + + virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; + virtual std::string GetInvalidatorClientId() const OVERRIDE; + + void EmitInvalidationForTest( + const invalidation::ObjectId& object_id, + const std::string& payload); + + private: + std::string client_id_; + syncer::InvalidatorRegistrar invalidator_registrar_; + + DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); +}; + +} // namespace invalidation + +#endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ diff --git a/chrome/browser/invalidation/invalidation_frontend.h b/chrome/browser/invalidation/invalidation_service.h index f8b61a5..7ee0b73 100644 --- a/chrome/browser/invalidation/invalidation_frontend.h +++ b/chrome/browser/invalidation/invalidation_service.h @@ -1,10 +1,11 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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_INVALIDATION_INVALIDATION_FRONTEND_H_ -#define CHROME_BROWSER_INVALIDATION_INVALIDATION_FRONTEND_H_ +#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ +#define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ +#include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/invalidator_state.h" @@ -30,10 +31,19 @@ namespace invalidation { // // frontend->UpdateRegisteredInvalidationIds(client_handler, client_ids); // -// To unregister for all invalidations: +// When shutting down the client for browser shutdown: // // frontend->UnregisterInvalidationHandler(client_handler); // +// Note that there's no call to UpdateRegisteredIds() -- this is because the +// invalidation API persists registrations across browser restarts. +// +// When permanently shutting down the client, e.g. when disabling the related +// feature: +// +// frontend->UpdateRegisteredInvalidationIds(client_handler, ObjectIdSet()); +// frontend->UnregisterInvalidationHandler(client_handler); +// // If an invalidation handler cares about the invalidator state, it should also // do the following when starting the client: // @@ -42,15 +52,20 @@ namespace invalidation { // It can also do the above in OnInvalidatorStateChange(), or it can use the // argument to OnInvalidatorStateChange(). // -// It is an error to have registered handlers when an InvalidationFrontend is -// shut down; clients must ensure that they unregister themselves before then. -// -// TODO(rlarocque): This class should extend BrowserContextKeyedService. +// It is an error to have registered handlers when an +// InvalidationFrontend is shut down; clients must ensure that they +// unregister themselves before then. (Depending on the +// InvalidationFrontend, shutdown may be equivalent to destruction, or +// a separate function call like Shutdown()). // // NOTE(akalin): Invalidations that come in during browser shutdown may get // dropped. This won't matter once we have an Acknowledge API, though: see // http://crbug.com/78462 and http://crbug.com/124149. -class InvalidationFrontend { +// +// This class inherits from ProfileKeyedService to make it possible to correctly +// cast from various InvalidationService implementations to ProfileKeyedService +// in InvalidationServiceFactory. +class InvalidationService : public BrowserContextKeyedService { public: // Starts sending notifications to |handler|. |handler| must not be NULL, // and it must not already be registered. @@ -86,10 +101,14 @@ class InvalidationFrontend { // the updated state. virtual syncer::InvalidatorState GetInvalidatorState() const = 0; + // Returns the ID belonging to this invalidation client. Can be used to + // prevent the receipt of notifications of our own changes. + virtual std::string GetInvalidatorClientId() const = 0; + protected: - virtual ~InvalidationFrontend() { } + virtual ~InvalidationService() { } }; } // namespace invalidation -#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_FRONTEND_H_ +#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ diff --git a/chrome/browser/invalidation/invalidation_service_android.h b/chrome/browser/invalidation/invalidation_service_android.h index 6daef6a..244b1e7 100644 --- a/chrome/browser/invalidation/invalidation_service_android.h +++ b/chrome/browser/invalidation/invalidation_service_android.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/threading/non_thread_safe.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -24,8 +24,7 @@ namespace invalidation { // around Android's invalidations service. class InvalidationServiceAndroid : public base::NonThreadSafe, - public BrowserContextKeyedService, - public InvalidationFrontend, + public InvalidationService, public content::NotificationObserver { public: explicit InvalidationServiceAndroid(Profile* profile); @@ -47,7 +46,7 @@ class InvalidationServiceAndroid const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) OVERRIDE; virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - virtual std::string GetInvalidatorClientId() const; + virtual std::string GetInvalidatorClientId() const OVERRIDE; // content::NotificationObserver implementation. virtual void Observe(int type, diff --git a/chrome/browser/invalidation/invalidation_service_android_unittest.cc b/chrome/browser/invalidation/invalidation_service_android_unittest.cc index feadf24..9e332b2 100644 --- a/chrome/browser/invalidation/invalidation_service_android_unittest.cc +++ b/chrome/browser/invalidation/invalidation_service_android_unittest.cc @@ -4,8 +4,8 @@ #include "chrome/browser/invalidation/invalidation_service_android.h" -#include "chrome/browser/invalidation/invalidation_frontend_test_template.h" #include "chrome/browser/invalidation/invalidation_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service_test_template.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/notification_service.h" @@ -18,20 +18,20 @@ class InvalidationServiceAndroidTestDelegate { InvalidationServiceAndroidTestDelegate() { } ~InvalidationServiceAndroidTestDelegate() { - DestroyInvalidationFrontend(); + DestroyInvalidationService(); } - void CreateInvalidationFrontend() { + void CreateInvalidationService() { profile_.reset(new TestingProfile()); invalidation_service_android_.reset( new InvalidationServiceAndroid(profile_.get())); } - InvalidationFrontend* GetInvalidationFrontend() { + InvalidationService* GetInvalidationService() { return invalidation_service_android_.get(); } - void DestroyInvalidationFrontend() { + void DestroyInvalidationService() { invalidation_service_android_->Shutdown(); } @@ -55,7 +55,7 @@ class InvalidationServiceAndroidTestDelegate { }; INSTANTIATE_TYPED_TEST_CASE_P( - AndroidInvalidationServiceTest, InvalidationFrontendTest, + AndroidInvalidationServiceTest, InvalidationServiceTest, InvalidationServiceAndroidTestDelegate); } // namespace invalidation diff --git a/chrome/browser/invalidation/invalidation_service_factory.cc b/chrome/browser/invalidation/invalidation_service_factory.cc index 0fa857b..20854177 100644 --- a/chrome/browser/invalidation/invalidation_service_factory.cc +++ b/chrome/browser/invalidation/invalidation_service_factory.cc @@ -4,13 +4,19 @@ #include "chrome/browser/invalidation/invalidation_service_factory.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "base/prefs/pref_registry.h" +#include "chrome/browser/invalidation/fake_invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "chrome/browser/invalidation/invalidation_service_android.h" +#include "chrome/browser/invalidation/invalidator_storage.h" #include "chrome/browser/invalidation/p2p_invalidation_service.h" #include "chrome/browser/invalidation/ticl_invalidation_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/profile_oauth2_token_service.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" +#include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" @@ -18,14 +24,12 @@ class TokenService; namespace invalidation { -// TODO(rlarocque): Re-enable this once InvalidationFrontend can -// extend BrowserContextKeyedService. -// // static -// InvalidationFrontend* InvalidationServiceFactory::GetForProfile( -// Profile* profile) { -// return static_cast<InvalidationFrontend*>( -// GetInstance()->GetServiceForBrowserContext(profile, true)); -// } +// static +InvalidationService* InvalidationServiceFactory::GetForProfile( + Profile* profile) { + return static_cast<InvalidationService*>( + GetInstance()->GetServiceForBrowserContext(profile, true)); +} // static InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { @@ -35,24 +39,52 @@ InvalidationServiceFactory* InvalidationServiceFactory::GetInstance() { InvalidationServiceFactory::InvalidationServiceFactory() : BrowserContextKeyedServiceFactory( "InvalidationService", - BrowserContextDependencyManager::GetInstance()) { + BrowserContextDependencyManager::GetInstance()), + build_fake_invalidators_(false) { #if !defined(OS_ANDROID) DependsOn(SigninManagerFactory::GetInstance()); - DependsOn(TokenServiceFactory::GetInstance()); + DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); #endif } InvalidationServiceFactory::~InvalidationServiceFactory() {} -// static -BrowserContextKeyedService* -InvalidationServiceFactory::BuildP2PInvalidationServiceFor(Profile* profile) { +namespace { + +BrowserContextKeyedService* BuildP2PInvalidationService( + content::BrowserContext* context) { + Profile* profile = static_cast<Profile*>(context); return new P2PInvalidationService(profile); } +BrowserContextKeyedService* BuildFakeInvalidationService( + content::BrowserContext* context) { + return new FakeInvalidationService(); +} + +} // namespace + +void InvalidationServiceFactory::SetBuildOnlyFakeInvalidatorsForTest( + bool test_mode_enabled) { + build_fake_invalidators_ = test_mode_enabled; +} + +P2PInvalidationService* +InvalidationServiceFactory::BuildAndUseP2PInvalidationServiceForTest( + content::BrowserContext* context) { + BrowserContextKeyedService* service = + SetTestingFactoryAndUse(context, BuildP2PInvalidationService); + return static_cast<P2PInvalidationService*>(service); +} + BrowserContextKeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { Profile* profile = static_cast<Profile*>(context); + + if (build_fake_invalidators_) { + return BuildFakeInvalidationService(context); + } + #if defined(OS_ANDROID) InvalidationServiceAndroid* service = new InvalidationServiceAndroid(profile); return service; @@ -60,12 +92,22 @@ BrowserContextKeyedService* InvalidationServiceFactory::BuildServiceInstanceFor( SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(profile); TokenService* token_service = TokenServiceFactory::GetForProfile(profile); + OAuth2TokenService* oauth2_token_service = + ProfileOAuth2TokenServiceFactory::GetForProfile(profile); TiclInvalidationService* service = new TiclInvalidationService( - signin_manager, token_service, profile); + signin_manager, + token_service, + oauth2_token_service, + profile); service->Init(); return service; #endif } +void InvalidationServiceFactory::RegisterUserPrefs( + user_prefs::PrefRegistrySyncable* registry) { + InvalidatorStorage::RegisterUserPrefs(registry); +} + } // namespace invalidation diff --git a/chrome/browser/invalidation/invalidation_service_factory.h b/chrome/browser/invalidation/invalidation_service_factory.h index da6900a..fa2828a 100644 --- a/chrome/browser/invalidation/invalidation_service_factory.h +++ b/chrome/browser/invalidation/invalidation_service_factory.h @@ -9,15 +9,22 @@ #include "base/memory/singleton.h" #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h" +namespace user_prefs { +class PrefRegistrySyncable; +} + namespace syncer { class Invalidator; } -class InvalidationFrontend; class Profile; namespace invalidation { +class InvalidationService; +class P2PInvalidationService; +class FakeInvalidationService; + // A BrowserContextKeyedServiceFactory to construct InvalidationServices. The // implementation of the InvalidationService may be completely different on // different platforms; this class should help to hide this complexity. It also @@ -25,16 +32,18 @@ namespace invalidation { // on invalidations. class InvalidationServiceFactory : public BrowserContextKeyedServiceFactory { public: - // TODO(rlarocque): Re-enable this once InvalidationFrontend can extend - // BrowserContextKeyedService. - // static InvalidationFrontend* GetForProfile(Profile* profile); + static InvalidationService* GetForProfile(Profile* profile); static InvalidationServiceFactory* GetInstance(); - static BrowserContextKeyedService* BuildP2PInvalidationServiceFor( - Profile* profile); - static BrowserContextKeyedService* BuildTestServiceInstanceFor( - Profile* profile); + // A helper function to set this factory to return FakeInvalidationServices + // instead of the default InvalidationService objects. + void SetBuildOnlyFakeInvalidatorsForTest(bool test_mode_enabled); + + // These helper functions to set the factory to build a test-only type of + // invalidator and return the instance immeidately. + P2PInvalidationService* BuildAndUseP2PInvalidationServiceForTest( + content::BrowserContext* context); private: friend struct DefaultSingletonTraits<InvalidationServiceFactory>; @@ -44,10 +53,12 @@ class InvalidationServiceFactory : public BrowserContextKeyedServiceFactory { // BrowserContextKeyedServiceFactory: virtual BrowserContextKeyedService* BuildServiceInstanceFor( - content::BrowserContext* profile) const OVERRIDE; - // TODO(rlarocque): Use this class, not InvalidatorStorage, to register - // for user prefs. - // virtual void RegisterUserPrefs(PrefRegistrySyncable* registry) OVERRIDE; + content::BrowserContext* context) const OVERRIDE; + virtual void RegisterUserPrefs( + user_prefs::PrefRegistrySyncable* registry) OVERRIDE; + + // If true, this factory will return only FakeInvalidationService instances. + bool build_fake_invalidators_; DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactory); }; diff --git a/chrome/browser/invalidation/invalidation_frontend_test_template.cc b/chrome/browser/invalidation/invalidation_service_test_template.cc index b454623..1b591e8 100644 --- a/chrome/browser/invalidation/invalidation_frontend_test_template.cc +++ b/chrome/browser/invalidation/invalidation_service_test_template.cc @@ -1,13 +1,13 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 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 "chrome/browser/invalidation/invalidation_frontend_test_template.h" +#include "chrome/browser/invalidation/invalidation_service_test_template.h" namespace internal { BoundFakeInvalidationHandler::BoundFakeInvalidationHandler( - const invalidation::InvalidationFrontend& invalidator) + const invalidation::InvalidationService& invalidator) : invalidator_(invalidator), last_retrieved_state_(syncer::DEFAULT_INVALIDATION_ERROR) {} @@ -24,4 +24,4 @@ void BoundFakeInvalidationHandler::OnInvalidatorStateChange( last_retrieved_state_ = invalidator_.GetInvalidatorState(); } -} +} // namespace internal diff --git a/chrome/browser/invalidation/invalidation_frontend_test_template.h b/chrome/browser/invalidation/invalidation_service_test_template.h index 9643504..baad132 100644 --- a/chrome/browser/invalidation/invalidation_frontend_test_template.h +++ b/chrome/browser/invalidation/invalidation_service_test_template.h @@ -1,37 +1,37 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -// This class defines tests that implementations of InvalidationFrontend should +// This class defines tests that implementations of InvalidationService should // pass in order to be conformant. Here's how you use it to test your // implementation. // -// Say your class is called MyInvalidationFrontend. Then you need to define a -// class called MyInvalidationFrontendTestDelegate in +// Say your class is called MyInvalidationService. Then you need to define a +// class called MyInvalidationServiceTestDelegate in // my_invalidation_frontend_unittest.cc like this: // -// class MyInvalidationFrontendTestDelegate { +// class MyInvalidationServiceTestDelegate { // public: -// MyInvalidationFrontendTestDelegate() ... +// MyInvalidationServiceTestDelegate() ... // -// ~MyInvalidationFrontendTestDelegate() { +// ~MyInvalidationServiceTestDelegate() { // // DestroyInvalidator() may not be explicitly called by tests. // DestroyInvalidator(); // } // -// // Create the InvalidationFrontend implementation with the given params. -// void CreateInvalidationFrontend() { +// // Create the InvalidationService implementation with the given params. +// void CreateInvalidationService() { // ... // } // -// // Should return the InvalidationFrontend implementation. Only called +// // Should return the InvalidationService implementation. Only called // // after CreateInvalidator and before DestroyInvalidator. -// MyInvalidationFrontend* GetInvalidationFrontend() { +// MyInvalidationService* GetInvalidationService() { // ... // } // -// // Destroy the InvalidationFrontend implementation. -// void DestroyInvalidationFrontend() { +// // Destroy the InvalidationService implementation. +// void DestroyInvalidationService() { // ... // } // @@ -39,14 +39,14 @@ // // the call are visible on the current thread. // // // Should cause OnInvalidatorStateChange() to be called on all -// // observers of the InvalidationFrontend implementation with the given +// // observers of the InvalidationService implementation with the given // // parameters. // void TriggerOnInvalidatorStateChange(InvalidatorState state) { // ... // } // // // Should cause OnIncomingInvalidation() to be called on all -// // observers of the InvalidationFrontend implementation with the given +// // observers of the InvalidationService implementation with the given // // parameters. // void TriggerOnIncomingInvalidation( // const ObjectIdInvalidationMap& invalidation_map) { @@ -54,7 +54,7 @@ // } // }; // -// The InvalidationFrontendTest test harness will have a member variable of +// The InvalidationServiceTest test harness will have a member variable of // this delegate type and will call its functions in the various // tests. // @@ -62,18 +62,18 @@ // following statement to my_sync_notifier_unittest.cc: // // INSTANTIATE_TYPED_TEST_CASE_P( -// MyInvalidationFrontend, -// InvalidationFrontendTest, +// MyInvalidationService, +// InvalidationServiceTest, // MyInvalidatorTestDelegate); // // Easy! -#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_FRONTEND_TEST_TEMPLATE_H_ -#define CHROME_BROWSER_INVALIDATION_INVALIDATION_FRONTEND_TEST_TEMPLATE_H_ +#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ +#define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "google/cacheinvalidation/include/types.h" #include "google/cacheinvalidation/types.pb.h" #include "sync/notifier/fake_invalidation_handler.h" @@ -82,22 +82,22 @@ #include "testing/gtest/include/gtest/gtest.h" template <typename InvalidatorTestDelegate> -class InvalidationFrontendTest : public testing::Test { +class InvalidationServiceTest : public testing::Test { protected: // Note: The IDs defined below must be valid. Otherwise they won't make it // through the round-trip to ModelTypeInvalidationMap and back that the // AndroidInvalidation test requires. - InvalidationFrontendTest() + InvalidationServiceTest() : id1(ipc::invalidation::ObjectSource::CHROME_SYNC, "BOOKMARK"), id2(ipc::invalidation::ObjectSource::CHROME_SYNC, "PREFERENCE"), id3(ipc::invalidation::ObjectSource::CHROME_SYNC, "AUTOFILL"), id4(ipc::invalidation::ObjectSource::CHROME_SYNC, "EXPERIMENTS") { } - invalidation::InvalidationFrontend* - CreateAndInitializeInvalidationFrontend() { - this->delegate_.CreateInvalidationFrontend(); - return this->delegate_.GetInvalidationFrontend(); + invalidation::InvalidationService* + CreateAndInitializeInvalidationService() { + this->delegate_.CreateInvalidationService(); + return this->delegate_.GetInvalidationService(); } InvalidatorTestDelegate delegate_; @@ -108,15 +108,15 @@ class InvalidationFrontendTest : public testing::Test { const invalidation::ObjectId id4; }; -TYPED_TEST_CASE_P(InvalidationFrontendTest); +TYPED_TEST_CASE_P(InvalidationServiceTest); // Initialize the invalidator, 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. -TYPED_TEST_P(InvalidationFrontendTest, Basic) { - invalidation::InvalidationFrontend* const invalidator = - this->CreateAndInitializeInvalidationFrontend(); +TYPED_TEST_P(InvalidationServiceTest, Basic) { + invalidation::InvalidationService* const invalidator = + this->CreateAndInitializeInvalidationService(); syncer::FakeInvalidationHandler handler; @@ -166,8 +166,8 @@ TYPED_TEST_P(InvalidationFrontendTest, Basic) { handler.GetInvalidatorState()); this->delegate_.TriggerOnInvalidatorStateChange( - syncer::INVALIDATION_CREDENTIALS_REJECTED); - EXPECT_EQ(syncer::INVALIDATION_CREDENTIALS_REJECTED, + syncer::INVALIDATIONS_ENABLED); + EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); invalidator->UnregisterInvalidationHandler(&handler); @@ -182,9 +182,9 @@ TYPED_TEST_P(InvalidationFrontendTest, Basic) { // dispatch some invalidations and invalidations. Handlers that are registered // should get invalidations, and the ones that have registered IDs should // receive invalidations for those IDs. -TYPED_TEST_P(InvalidationFrontendTest, MultipleHandlers) { - invalidation::InvalidationFrontend* const invalidator = - this->CreateAndInitializeInvalidationFrontend(); +TYPED_TEST_P(InvalidationServiceTest, MultipleHandlers) { + invalidation::InvalidationService* const invalidator = + this->CreateAndInitializeInvalidationService(); syncer::FakeInvalidationHandler handler1; syncer::FakeInvalidationHandler handler2; @@ -270,9 +270,9 @@ TYPED_TEST_P(InvalidationFrontendTest, MultipleHandlers) { // Make sure that passing an empty set to UpdateRegisteredInvalidationIds clears // the corresponding entries for the handler. -TYPED_TEST_P(InvalidationFrontendTest, EmptySetUnregisters) { - invalidation::InvalidationFrontend* const invalidator = - this->CreateAndInitializeInvalidationFrontend(); +TYPED_TEST_P(InvalidationServiceTest, EmptySetUnregisters) { + invalidation::InvalidationService* const invalidator = + this->CreateAndInitializeInvalidationService(); syncer::FakeInvalidationHandler handler1; @@ -329,12 +329,12 @@ TYPED_TEST_P(InvalidationFrontendTest, EmptySetUnregisters) { namespace internal { // A FakeInvalidationHandler that is "bound" to a specific -// InvalidationFrontend. This is for cross-referencing state information with -// the bound InvalidationFrontend. +// InvalidationService. This is for cross-referencing state information with +// the bound InvalidationService. class BoundFakeInvalidationHandler : public syncer::FakeInvalidationHandler { public: explicit BoundFakeInvalidationHandler( - const invalidation::InvalidationFrontend& invalidator); + const invalidation::InvalidationService& invalidator); virtual ~BoundFakeInvalidationHandler(); // Returns the last return value of GetInvalidatorState() on the @@ -347,7 +347,7 @@ class BoundFakeInvalidationHandler : public syncer::FakeInvalidationHandler { syncer::InvalidatorState state) OVERRIDE; private: - const invalidation::InvalidationFrontend& invalidator_; + const invalidation::InvalidationService& invalidator_; syncer::InvalidatorState last_retrieved_state_; DISALLOW_COPY_AND_ASSIGN(BoundFakeInvalidationHandler); @@ -355,9 +355,9 @@ class BoundFakeInvalidationHandler : public syncer::FakeInvalidationHandler { } // namespace internal -TYPED_TEST_P(InvalidationFrontendTest, GetInvalidatorStateAlwaysCurrent) { - invalidation::InvalidationFrontend* const invalidator = - this->CreateAndInitializeInvalidationFrontend(); +TYPED_TEST_P(InvalidationServiceTest, GetInvalidatorStateAlwaysCurrent) { + invalidation::InvalidationService* const invalidator = + this->CreateAndInitializeInvalidationService(); internal::BoundFakeInvalidationHandler handler(*invalidator); invalidator->RegisterInvalidationHandler(&handler); @@ -377,8 +377,8 @@ TYPED_TEST_P(InvalidationFrontendTest, GetInvalidatorStateAlwaysCurrent) { invalidator->UnregisterInvalidationHandler(&handler); } -REGISTER_TYPED_TEST_CASE_P(InvalidationFrontendTest, +REGISTER_TYPED_TEST_CASE_P(InvalidationServiceTest, Basic, MultipleHandlers, EmptySetUnregisters, GetInvalidatorStateAlwaysCurrent); -#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_FRONTEND_TEST_TEMPLATE_H_ +#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ diff --git a/chrome/browser/invalidation/p2p_invalidation_service.h b/chrome/browser/invalidation/p2p_invalidation_service.h index b624688..bbb18b9 100644 --- a/chrome/browser/invalidation/p2p_invalidation_service.h +++ b/chrome/browser/invalidation/p2p_invalidation_service.h @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/threading/non_thread_safe.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "sync/notifier/object_id_invalidation_map.h" @@ -23,8 +23,7 @@ namespace invalidation { // only in tests, where we're unable to connect to a real invalidations server. class P2PInvalidationService : public base::NonThreadSafe, - public BrowserContextKeyedService, - public InvalidationFrontend { + public InvalidationService { public: explicit P2PInvalidationService(Profile* profile); virtual ~P2PInvalidationService(); @@ -32,7 +31,7 @@ class P2PInvalidationService // Overrides BrowserContextKeyedService method. virtual void Shutdown() OVERRIDE; - // InvalidationFrontend implementation. + // InvalidationService implementation. // It is an error to have registered handlers when Shutdown() is called. virtual void RegisterInvalidationHandler( syncer::InvalidationHandler* handler) OVERRIDE; @@ -45,7 +44,7 @@ class P2PInvalidationService const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) OVERRIDE; virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - virtual std::string GetInvalidatorClientId() const; + virtual std::string GetInvalidatorClientId() const OVERRIDE; void UpdateCredentials(const std::string& username, const std::string& password); diff --git a/chrome/browser/invalidation/ticl_invalidation_service.cc b/chrome/browser/invalidation/ticl_invalidation_service.cc index bfee8f0..11a9759 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service.cc +++ b/chrome/browser/invalidation/ticl_invalidation_service.cc @@ -6,9 +6,11 @@ #include "base/command_line.h" #include "chrome/browser/invalidation/invalidation_service_util.h" +#include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/profile_oauth2_token_service.h" +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/signin_manager.h" -#include "chrome/browser/signin/token_service.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_service.h" #include "google_apis/gaia/gaia_constants.h" @@ -16,15 +18,52 @@ #include "sync/notifier/invalidator_state.h" #include "sync/notifier/non_blocking_invalidator.h" +static const char* kOAuth2Scopes[] = { + GaiaConstants::kGoogleTalkOAuth2Scope +}; + +static const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { + // Number of initial errors (in sequence) to ignore before applying + // exponential back-off rules. + 0, + + // Initial delay for exponential back-off in ms. + 2000, + + // Factor by which the waiting time will be multiplied. + 2, + + // Fuzzing percentage. ex: 10% will spread requests randomly + // between 90%-100% of the calculated time. + 0.2, // 20% + + // Maximum amount of time we are willing to delay our request in ms. + // TODO(pavely): crbug.com/246686 ProfileSyncService should retry + // RequestAccessToken on connection state change after backoff + 1000 * 3600 * 4, // 4 hours. + + // Time to keep an entry from being discarded even when it + // has no significant state, -1 to never discard. + -1, + + // Don't use initial delay unless the last request was an error. + false, +}; + namespace invalidation { -TiclInvalidationService::TiclInvalidationService(SigninManagerBase* signin, - TokenService* token_service, - Profile* profile) - : profile_(profile), - signin_manager_(signin), - token_service_(token_service), - invalidator_registrar_(new syncer::InvalidatorRegistrar()) { } +TiclInvalidationService::TiclInvalidationService( + SigninManagerBase* signin, + TokenService* token_service, + OAuth2TokenService* oauth2_token_service, + Profile* profile) + : profile_(profile), + signin_manager_(signin), + token_service_(token_service), + oauth2_token_service_(oauth2_token_service), + invalidator_registrar_(new syncer::InvalidatorRegistrar()), + request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) { +} TiclInvalidationService::~TiclInvalidationService() { DCHECK(CalledOnValidThread()); @@ -41,20 +80,24 @@ void TiclInvalidationService::Init() { } if (IsReadyToStart()) { - Start(); + StartInvalidator(); } notification_registrar_.Add(this, + chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, + content::Source<Profile>(profile_)); + notification_registrar_.Add(this, chrome::NOTIFICATION_TOKEN_AVAILABLE, content::Source<TokenService>(token_service_)); notification_registrar_.Add(this, - chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, - content::Source<Profile>(profile_)); + chrome::NOTIFICATION_TOKENS_CLEARED, + content::Source<TokenService>(token_service_)); } void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) { - // Here we perform the equivalent of Init() and Start(), but with some minor - // changes to account for the fact that we're injecting the invalidator. + // Here we perform the equivalent of Init() and StartInvalidator(), but with + // some minor changes to account for the fact that we're injecting the + // invalidator. invalidator_.reset(invalidator); invalidator_->RegisterHandler(this); @@ -129,16 +172,15 @@ void TiclInvalidationService::Observe( switch (type) { case chrome::NOTIFICATION_TOKEN_AVAILABLE: { - const TokenService::TokenAvailableDetails& token_details = - *(content::Details<const TokenService::TokenAvailableDetails>( - details).ptr()); - if (token_details.service() == GaiaConstants::kSyncService) { - DCHECK(IsReadyToStart()); - if (!IsStarted()) { - Start(); - } else { - UpdateToken(); - } + if (!IsStarted() && IsReadyToStart()) { + StartInvalidator(); + } + break; + } + case chrome::NOTIFICATION_TOKENS_CLEARED: { + access_token_.clear(); + if (IsStarted()) { + UpdateInvalidatorCredentials(); } break; } @@ -152,6 +194,68 @@ void TiclInvalidationService::Observe( } } +void TiclInvalidationService::RequestAccessToken() { + // Only one active request at a time. + if (access_token_request_ != NULL) + return; + request_access_token_retry_timer_.Stop(); + OAuth2TokenService::ScopeSet oauth2_scopes; + for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) + oauth2_scopes.insert(kOAuth2Scopes[i]); + // Invalidate previous token, otherwise token service will return the same + // token again. + oauth2_token_service_->InvalidateToken(oauth2_scopes, access_token_); + access_token_.clear(); + access_token_request_ = + oauth2_token_service_->StartRequest(oauth2_scopes, this); +} + +void TiclInvalidationService::OnGetTokenSuccess( + const OAuth2TokenService::Request* request, + const std::string& access_token, + const base::Time& expiration_time) { + DCHECK_EQ(access_token_request_, request); + access_token_request_.reset(); + // Reset backoff time after successful response. + request_access_token_backoff_.Reset(); + access_token_ = access_token; + if (!IsStarted() && IsReadyToStart()) { + StartInvalidator(); + } else { + UpdateInvalidatorCredentials(); + } +} + +void TiclInvalidationService::OnGetTokenFailure( + const OAuth2TokenService::Request* request, + const GoogleServiceAuthError& error) { + DCHECK_EQ(access_token_request_, request); + DCHECK_NE(error.state(), GoogleServiceAuthError::NONE); + access_token_request_.reset(); + switch (error.state()) { + case GoogleServiceAuthError::CONNECTION_FAILED: + case GoogleServiceAuthError::SERVICE_UNAVAILABLE: { + // Transient error. Retry after some time. + request_access_token_backoff_.InformOfRequest(false); + request_access_token_retry_timer_.Start( + FROM_HERE, + request_access_token_backoff_.GetTimeUntilRelease(), + base::Bind(&TiclInvalidationService::RequestAccessToken, + base::Unretained(this))); + break; + } + case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: { + // This is a real auth error. + invalidator_registrar_->UpdateInvalidatorState( + syncer::INVALIDATION_CREDENTIALS_REJECTED); + break; + } + default: { + // We have no way to notify the user of this. Do nothing. + } + } +} + void TiclInvalidationService::OnInvalidatorStateChange( syncer::InvalidatorState state) { invalidator_registrar_->UpdateInvalidatorState(state); @@ -172,19 +276,25 @@ void TiclInvalidationService::Shutdown() { } bool TiclInvalidationService::IsReadyToStart() { + if (ManagedUserService::ProfileIsManaged(profile_)) { + DVLOG(2) << "Not starting TiclInvalidationService: User is managed."; + return false; + } + if (signin_manager_->GetAuthenticatedUsername().empty()) { - DVLOG(2) << "Not starting TiclInvalidationService: user is not signed in."; + DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in."; return false; } - if (!token_service_) { + if (!oauth2_token_service_) { DVLOG(2) << "Not starting TiclInvalidationService: TokenService unavailable."; return false; } - if (!token_service_->HasTokenForService(GaiaConstants::kSyncService)) { - DVLOG(2) << "Not starting TiclInvalidationService: Sync token unavailable."; + if (!oauth2_token_service_->RefreshTokenIsAvailable()) { + DVLOG(2) + << "Not starting TiclInvalidationServce: Waiting for refresh token."; return false; } @@ -195,15 +305,24 @@ bool TiclInvalidationService::IsStarted() { return invalidator_.get() != NULL; } -void TiclInvalidationService::Start() { +void TiclInvalidationService::StartInvalidator() { DCHECK(CalledOnValidThread()); DCHECK(!invalidator_); DCHECK(invalidator_storage_); DCHECK(!invalidator_storage_->GetInvalidatorClientId().empty()); + if (access_token_.empty()) { + DVLOG(1) + << "TiclInvalidationService: " + << "Deferring start until we have an access token."; + RequestAccessToken(); + return; + } + notifier::NotifierOptions options = ParseNotifierOptions(*CommandLine::ForCurrentProcess()); options.request_context_getter = profile_->GetRequestContext(); + options.auth_mechanism = "X-OAUTH2"; invalidator_.reset(new syncer::NonBlockingInvalidator( options, invalidator_storage_->GetInvalidatorClientId(), @@ -213,7 +332,7 @@ void TiclInvalidationService::Start() { invalidator_storage_->AsWeakPtr()), content::GetUserAgent(GURL()))); - UpdateToken(); + UpdateInvalidatorCredentials(); invalidator_->RegisterHandler(this); invalidator_->UpdateRegisteredIds( @@ -221,16 +340,14 @@ void TiclInvalidationService::Start() { invalidator_registrar_->GetAllRegisteredIds()); } -void TiclInvalidationService::UpdateToken() { +void TiclInvalidationService::UpdateInvalidatorCredentials() { std::string email = signin_manager_->GetAuthenticatedUsername(); - DCHECK(!email.empty()) << "Expected user to be signed in."; - DCHECK(token_service_->HasTokenForService(GaiaConstants::kSyncService)); - std::string sync_token = token_service_->GetTokenForService( - GaiaConstants::kSyncService); + DCHECK(!email.empty()) << "Expected user to be signed in."; + DCHECK(!access_token_.empty()); DVLOG(2) << "UpdateCredentials: " << email; - invalidator_->UpdateCredentials(email, sync_token); + invalidator_->UpdateCredentials(email, access_token_); } void TiclInvalidationService::StopInvalidator() { @@ -240,7 +357,11 @@ void TiclInvalidationService::StopInvalidator() { } void TiclInvalidationService::Logout() { - StopInvalidator(); + request_access_token_retry_timer_.Stop(); + + if (IsStarted()) { + StopInvalidator(); + } // This service always expects to have a valid invalidator storage. // So we must not only clear the old one, but also start a new one. diff --git a/chrome/browser/invalidation/ticl_invalidation_service.h b/chrome/browser/invalidation/ticl_invalidation_service.h index dde6606..0a14dd8 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service.h +++ b/chrome/browser/invalidation/ticl_invalidation_service.h @@ -7,42 +7,50 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" +#include "base/timer/timer.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "chrome/browser/invalidation/invalidator_storage.h" -#include "chrome/browser/signin/signin_global_error.h" +#include "chrome/browser/signin/oauth2_token_service.h" +#include "chrome/browser/signin/token_service.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "net/base/backoff_entry.h" #include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidator_registrar.h" class Profile; class SigninManagerBase; -class TokenService; namespace syncer { class Invalidator; } +// TODO: Remove this dependency. See crbug.com/243482. +namespace extensions { +class PushMessagingApiTest; +} + namespace invalidation { // This InvalidationService wraps the C++ Invalidation Client (TICL) library. // It provides invalidations for desktop platforms (Win, Mac, Linux). class TiclInvalidationService : public base::NonThreadSafe, - public BrowserContextKeyedService, - public InvalidationFrontend, + public InvalidationService, public content::NotificationObserver, + public OAuth2TokenService::Consumer, public syncer::InvalidationHandler { public: TiclInvalidationService(SigninManagerBase* signin, TokenService* token_service, + OAuth2TokenService* oauth2_token_service, Profile* profile); virtual ~TiclInvalidationService(); void Init(); - // InvalidationFrontend implementation. + // InvalidationService implementation. // It is an error to have registered handlers when Shutdown() is called. virtual void RegisterInvalidationHandler( syncer::InvalidationHandler* handler) OVERRIDE; @@ -55,13 +63,24 @@ class TiclInvalidationService const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) OVERRIDE; virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - virtual std::string GetInvalidatorClientId() const; + virtual std::string GetInvalidatorClientId() const OVERRIDE; // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + void RequestAccessToken(); + + // OAuth2TokenService::Consumer implementation + virtual void OnGetTokenSuccess( + const OAuth2TokenService::Request* request, + const std::string& access_token, + const base::Time& expiration_time) OVERRIDE; + virtual void OnGetTokenFailure( + const OAuth2TokenService::Request* request, + const GoogleServiceAuthError& error) OVERRIDE; + // syncer::InvalidationHandler implementation. virtual void OnInvalidatorStateChange( syncer::InvalidatorState state) OVERRIDE; @@ -76,19 +95,21 @@ class TiclInvalidationService void InitForTest(syncer::Invalidator* invalidator); friend class TiclInvalidationServiceTestDelegate; + friend class extensions::PushMessagingApiTest; private: bool IsReadyToStart(); bool IsStarted(); - void Start(); - void UpdateToken(); + void StartInvalidator(); + void UpdateInvalidatorCredentials(); void StopInvalidator(); void Logout(); Profile *const profile_; SigninManagerBase *const signin_manager_; TokenService *const token_service_; + OAuth2TokenService *const oauth2_token_service_; scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; scoped_ptr<InvalidatorStorage> invalidator_storage_; @@ -96,9 +117,19 @@ class TiclInvalidationService content::NotificationRegistrar notification_registrar_; + // TiclInvalidationService needs to remember access token in order to + // invalidate it with OAuth2TokenService. + std::string access_token_; + + // TiclInvalidationService needs to hold reference to access_token_request_ + // for the duration of request in order to receive callbacks. + scoped_ptr<OAuth2TokenService::Request> access_token_request_; + base::OneShotTimer<TiclInvalidationService> request_access_token_retry_timer_; + net::BackoffEntry request_access_token_backoff_; + DISALLOW_COPY_AND_ASSIGN(TiclInvalidationService); }; -} +} // namespace invalidation #endif // CHROME_BROWSER_INVALIDATION_TICL_INVALIDATION_SERVICE_H_ diff --git a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc index 225dc0a..314e8a7 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc +++ b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc @@ -4,8 +4,8 @@ #include "chrome/browser/invalidation/ticl_invalidation_service.h" -#include "chrome/browser/invalidation/invalidation_frontend_test_template.h" #include "chrome/browser/invalidation/invalidation_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service_test_template.h" #include "chrome/test/base/testing_profile.h" #include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/fake_invalidator.h" @@ -19,22 +19,22 @@ class TiclInvalidationServiceTestDelegate { TiclInvalidationServiceTestDelegate() { } ~TiclInvalidationServiceTestDelegate() { - DestroyInvalidationFrontend(); + DestroyInvalidationService(); } - void CreateInvalidationFrontend() { + void CreateInvalidationService() { fake_invalidator_ = new syncer::FakeInvalidator(); profile_.reset(new TestingProfile()); invalidation_service_.reset( - new TiclInvalidationService(NULL, NULL, profile_.get())); + new TiclInvalidationService(NULL, NULL, NULL, profile_.get())); invalidation_service_->InitForTest(fake_invalidator_); } - InvalidationFrontend* GetInvalidationFrontend() { + InvalidationService* GetInvalidationService() { return invalidation_service_.get(); } - void DestroyInvalidationFrontend() { + void DestroyInvalidationService() { invalidation_service_->Shutdown(); } @@ -53,7 +53,7 @@ class TiclInvalidationServiceTestDelegate { }; INSTANTIATE_TYPED_TEST_CASE_P( - TiclInvalidationServiceTest, InvalidationFrontendTest, + TiclInvalidationServiceTest, InvalidationServiceTest, TiclInvalidationServiceTestDelegate); } // namespace invalidation diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 3ab53e4..d70c205 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -33,7 +33,6 @@ #include "chrome/browser/gpu/gl_string_manager.h" #include "chrome/browser/gpu/gpu_mode_manager.h" #include "chrome/browser/intranet_redirect_detector.h" -#include "chrome/browser/invalidation/invalidator_storage.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/media/media_stream_devices_controller.h" @@ -303,7 +302,6 @@ void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry) { HostContentSettingsMap::RegisterUserPrefs(registry); IncognitoModePrefs::RegisterUserPrefs(registry); InstantUI::RegisterUserPrefs(registry); - invalidation::InvalidatorStorage::RegisterUserPrefs(registry); MediaCaptureDevicesDispatcher::RegisterUserPrefs(registry); MediaStreamDevicesController::RegisterUserPrefs(registry); NetPrefObserver::RegisterUserPrefs(registry); diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc index 030b5b2..e5ca157 100644 --- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc +++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc @@ -63,6 +63,8 @@ #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/shortcuts_backend_factory.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" +#include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/plugins/plugin_prefs_factory.h" @@ -258,6 +260,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() { GlobalErrorServiceFactory::GetInstance(); GoogleURLTrackerFactory::GetInstance(); HistoryServiceFactory::GetInstance(); + invalidation::InvalidationServiceFactory::GetInstance(); #if defined(ENABLE_MANAGED_USERS) ManagedUserServiceFactory::GetInstance(); #endif diff --git a/chrome/browser/sync/glue/android_invalidator_bridge.cc b/chrome/browser/sync/glue/android_invalidator_bridge.cc deleted file mode 100644 index 31cd87e..0000000 --- a/chrome/browser/sync/glue/android_invalidator_bridge.cc +++ /dev/null @@ -1,219 +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 "chrome/browser/sync/glue/android_invalidator_bridge.h" - -#include "base/bind.h" -#include "base/location.h" -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/common/chrome_notification_types.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" -#include "sync/internal_api/public/base/model_type.h" -#include "sync/notifier/invalidation_handler.h" -#include "sync/notifier/invalidator_registrar.h" - -using content::BrowserThread; - -namespace browser_sync { - -class AndroidInvalidatorBridge::Core - : public base::RefCountedThreadSafe<Core> { - public: - // Created on UI thread. - explicit Core( - const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner); - - // All member functions below must be called on the sync task runner. - - void InitializeOnSyncThread(); - void CleanupOnSyncThread(); - - void RegisterHandler(syncer::InvalidationHandler* handler); - void UpdateRegisteredIds(syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids); - void UnregisterHandler(syncer::InvalidationHandler* handler); - - void EmitInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map); - - bool IsHandlerRegisteredForTest(syncer::InvalidationHandler* handler) const; - syncer::ObjectIdSet GetRegisteredIdsForTest( - syncer::InvalidationHandler* handler) const; - - private: - friend class base::RefCountedThreadSafe<Core>; - - // Destroyed on the UI thread or on |sync_task_runner_|. - ~Core(); - - const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; - - // Used only on |sync_task_runner_|. - scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; -}; - -AndroidInvalidatorBridge::Core::Core( - const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) - : sync_task_runner_(sync_task_runner) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(sync_task_runner_.get()); -} - -AndroidInvalidatorBridge::Core::~Core() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || - sync_task_runner_->RunsTasksOnCurrentThread()); - DCHECK(!invalidator_registrar_.get()); -} - -void AndroidInvalidatorBridge::Core::InitializeOnSyncThread() { - invalidator_registrar_.reset(new syncer::InvalidatorRegistrar()); -} - -void AndroidInvalidatorBridge::Core::CleanupOnSyncThread() { - invalidator_registrar_.reset(); -} - -void AndroidInvalidatorBridge::Core::RegisterHandler( - syncer::InvalidationHandler* handler) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - invalidator_registrar_->RegisterHandler(handler); -} - -void AndroidInvalidatorBridge::Core::UpdateRegisteredIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - invalidator_registrar_->UpdateRegisteredIds(handler, ids); -} - -void AndroidInvalidatorBridge::Core::UnregisterHandler( - syncer::InvalidationHandler* handler) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - invalidator_registrar_->UnregisterHandler(handler); -} - -void AndroidInvalidatorBridge::Core::EmitInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - const syncer::ObjectIdInvalidationMap& effective_invalidation_map = - invalidation_map.empty() ? - ObjectIdSetToInvalidationMap( - invalidator_registrar_->GetAllRegisteredIds(), std::string()) : - invalidation_map; - - invalidator_registrar_->DispatchInvalidationsToHandlers( - effective_invalidation_map); -} - -bool AndroidInvalidatorBridge::Core::IsHandlerRegisteredForTest( - syncer::InvalidationHandler* handler) const { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - return invalidator_registrar_->IsHandlerRegisteredForTest(handler); -} - -syncer::ObjectIdSet -AndroidInvalidatorBridge::Core::GetRegisteredIdsForTest( - syncer::InvalidationHandler* handler) const { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - return invalidator_registrar_->GetRegisteredIds(handler); -} - -AndroidInvalidatorBridge::AndroidInvalidatorBridge( - const Profile* profile, - const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) - : sync_task_runner_(sync_task_runner), - core_(new Core(sync_task_runner_)) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(profile); - registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE, - content::Source<Profile>(profile)); - - if (!sync_task_runner_->PostTask( - FROM_HERE, base::Bind(&Core::InitializeOnSyncThread, core_))) { - NOTREACHED(); - } -} - -AndroidInvalidatorBridge::~AndroidInvalidatorBridge() {} - -void AndroidInvalidatorBridge::StopForShutdown() { - if (!sync_task_runner_->PostTask( - FROM_HERE, base::Bind(&Core::CleanupOnSyncThread, core_))) { - NOTREACHED(); - } -} - -void AndroidInvalidatorBridge::RegisterHandler( - syncer::InvalidationHandler* handler) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - core_->RegisterHandler(handler); -} - -void AndroidInvalidatorBridge::UpdateRegisteredIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - core_->UpdateRegisteredIds(handler, ids); -} - -void AndroidInvalidatorBridge::UnregisterHandler( - syncer::InvalidationHandler* handler) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - core_->UnregisterHandler(handler); -} - -void AndroidInvalidatorBridge::Acknowledge( - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { - // Do nothing. -} - -syncer::InvalidatorState AndroidInvalidatorBridge::GetInvalidatorState() const { - return syncer::INVALIDATIONS_ENABLED; -} - -void AndroidInvalidatorBridge::UpdateCredentials( - const std::string& email, const std::string& token) { } - -void AndroidInvalidatorBridge::SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { } - -bool AndroidInvalidatorBridge::IsHandlerRegisteredForTest( - syncer::InvalidationHandler* handler) const { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - return core_->IsHandlerRegisteredForTest(handler); -} - -syncer::ObjectIdSet AndroidInvalidatorBridge::GetRegisteredIdsForTest( - syncer::InvalidationHandler* handler) const { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - return core_->GetRegisteredIdsForTest(handler); -} - -void AndroidInvalidatorBridge::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_REMOTE); - - // TODO(akalin): Use ObjectIdInvalidationMap here instead. We'll have to - // make sure all emitters of the relevant notifications also use - // ObjectIdInvalidationMap. - content::Details<const syncer::ModelTypeInvalidationMap> - state_details(details); - const syncer::ModelTypeInvalidationMap& invalidation_map = - *(state_details.ptr()); - if (!sync_task_runner_->PostTask( - FROM_HERE, - base::Bind(&Core::EmitInvalidation, - core_, - ModelTypeInvalidationMapToObjectIdInvalidationMap( - invalidation_map)))) { - NOTREACHED(); - } -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/android_invalidator_bridge.h b/chrome/browser/sync/glue/android_invalidator_bridge.h deleted file mode 100644 index ec1baae..0000000 --- a/chrome/browser/sync/glue/android_invalidator_bridge.h +++ /dev/null @@ -1,85 +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_ANDROID_INVALIDATOR_BRIDGE_H_ -#define CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_H_ - -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/sequenced_task_runner.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "sync/notifier/invalidator.h" - -class Profile; - -namespace syncer { -class InvalidationHandler; -} // namespace - -namespace browser_sync { - -// A bridge that converts Chrome events on the UI thread to sync -// notifications on the sync task runner. -// -// Listens to NOTIFICATION_SYNC_REFRESH_REMOTE (on the UI thread) and triggers -// each observer's OnIncomingNotification method on these notifications (on the -// sync task runner). Android clients receive invalidations through this -// mechanism exclusively, hence the name. -class AndroidInvalidatorBridge - : public content::NotificationObserver, syncer::Invalidator { - public: - // Must be created and destroyed on the UI thread. - AndroidInvalidatorBridge( - const Profile* profile, - const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner); - virtual ~AndroidInvalidatorBridge(); - - // Must be called on the UI thread while the sync task runner is still - // around. No other member functions on the sync thread may be called after - // this is called. - void StopForShutdown(); - - // Invalidator implementation. Must be called on the sync task runner. - 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 Acknowledge(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; - virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - - // The following members of the Invalidator interface are not applicable to - // this invalidator and are implemented as no-ops. - virtual void UpdateCredentials( - const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; - - bool IsHandlerRegisteredForTest( - syncer::InvalidationHandler* handler) const; - syncer::ObjectIdSet GetRegisteredIdsForTest( - syncer::InvalidationHandler* handler) const; - - // NotificationObserver implementation. Called on UI thread. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - private: - // Inner class to hold all the bits used on |sync_task_runner_|. - class Core; - - const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; - - // Created on the UI thread, used only on |sync_task_runner_|. - const scoped_refptr<Core> core_; - - // Used only on the UI thread. - content::NotificationRegistrar registrar_; -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_H_ diff --git a/chrome/browser/sync/glue/android_invalidator_bridge_proxy.cc b/chrome/browser/sync/glue/android_invalidator_bridge_proxy.cc deleted file mode 100644 index 8ed4053..0000000 --- a/chrome/browser/sync/glue/android_invalidator_bridge_proxy.cc +++ /dev/null @@ -1,59 +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 "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" - -#include "chrome/browser/sync/glue/android_invalidator_bridge.h" - -using std::string; -using syncer::InvalidatorState; - -namespace browser_sync { - -AndroidInvalidatorBridgeProxy::AndroidInvalidatorBridgeProxy( - AndroidInvalidatorBridge* bridge) - : bridge_(bridge) { - DCHECK(bridge_); -} - -AndroidInvalidatorBridgeProxy::~AndroidInvalidatorBridgeProxy() { -} - -void AndroidInvalidatorBridgeProxy::RegisterHandler( - syncer::InvalidationHandler* handler) { - bridge_->RegisterHandler(handler); -} - -void AndroidInvalidatorBridgeProxy::UpdateRegisteredIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) { - bridge_->UpdateRegisteredIds(handler, ids); -} - -InvalidatorState AndroidInvalidatorBridgeProxy::GetInvalidatorState() const { - return bridge_->GetInvalidatorState(); -} - -void AndroidInvalidatorBridgeProxy::UnregisterHandler( - syncer::InvalidationHandler* handler) { - bridge_->UnregisterHandler(handler); -} - -void AndroidInvalidatorBridgeProxy::Acknowledge( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) { - bridge_->Acknowledge(id, ack_handle); -} - -void AndroidInvalidatorBridgeProxy::UpdateCredentials( - const string& email, const string& token) { - bridge_->UpdateCredentials(email, token); -} - -void AndroidInvalidatorBridgeProxy::SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - bridge_->SendInvalidation(invalidation_map); -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/android_invalidator_bridge_proxy.h b/chrome/browser/sync/glue/android_invalidator_bridge_proxy.h deleted file mode 100644 index 98c623e..0000000 --- a/chrome/browser/sync/glue/android_invalidator_bridge_proxy.h +++ /dev/null @@ -1,50 +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_ANDROID_INVALIDATOR_BRIDGE_PROXY_H_ -#define CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_PROXY_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "sync/notifier/invalidator.h" - -namespace browser_sync { - -class AndroidInvalidatorBridge; - -// This class implements the Invalidator interface by wrapping (but not taking -// ownership of) an AndroidInvalidatorBridge. This is useful because the -// SyncManager currently expects to take ownership of its invalidator, but it is -// not prepared to take ownership of the UI-thread-owned -// AndroidInvalidatorBridge. So we use this class to wrap the -// AndroidInvalidator and allow the SyncManager to own it instead. -class AndroidInvalidatorBridgeProxy : public syncer::Invalidator { - public: - // Does not take ownership of |bridge|. - explicit AndroidInvalidatorBridgeProxy(AndroidInvalidatorBridge* bridge); - virtual ~AndroidInvalidatorBridgeProxy(); - - // Invalidator implementation. Passes through all calls 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 Acknowledge(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; - virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - virtual void UpdateCredentials( - const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; - - private: - // The notification bridge that we forward to but don't own. - AndroidInvalidatorBridge* const bridge_; - - DISALLOW_COPY_AND_ASSIGN(AndroidInvalidatorBridgeProxy); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_PROXY_H_ diff --git a/chrome/browser/sync/glue/dummy_invalidator.cc b/chrome/browser/sync/glue/dummy_invalidator.cc deleted file mode 100644 index 4ed0689..0000000 --- a/chrome/browser/sync/glue/dummy_invalidator.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2013 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 "chrome/browser/sync/glue/dummy_invalidator.h" - -DummyInvalidator::DummyInvalidator() {} -DummyInvalidator::~DummyInvalidator() {} - -void DummyInvalidator::RegisterHandler(syncer::InvalidationHandler* handler) {} - -void DummyInvalidator::UpdateRegisteredIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) {} - -void DummyInvalidator::UnregisterHandler( - syncer::InvalidationHandler* handler) {} - -void DummyInvalidator::Acknowledge(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) {} - -syncer::InvalidatorState DummyInvalidator::GetInvalidatorState() const { - return syncer::TRANSIENT_INVALIDATION_ERROR; -} - -void DummyInvalidator::UpdateCredentials( - const std::string& email, const std::string& token) {} - -void DummyInvalidator::SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) {} diff --git a/chrome/browser/sync/glue/dummy_invalidator.h b/chrome/browser/sync/glue/dummy_invalidator.h deleted file mode 100644 index 19c4fca..0000000 --- a/chrome/browser/sync/glue/dummy_invalidator.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2013 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_DUMMY_INVALIDATOR_H_ -#define CHROME_BROWSER_SYNC_GLUE_DUMMY_INVALIDATOR_H_ - -#include "sync/notifier/invalidator.h" - -// A fake invalidator that does nothing, and stays in a "transient" error state. -// This is useful for cases where we know that invalidations won't work, but -// still want to keep Sync running without them -class DummyInvalidator : public syncer::Invalidator { - public: - DummyInvalidator(); - virtual ~DummyInvalidator(); - - 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 Acknowledge(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; - virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - virtual void UpdateCredentials( - const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(DummyInvalidator); -}; - -#endif // CHROME_BROWSER_SYNC_GLUE_DUMMY_INVALIDATOR_H_ diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index eab6322c..f39091d 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "build/build_config.h" - #include "chrome/browser/sync/glue/sync_backend_host.h" #include <algorithm> @@ -21,17 +19,15 @@ #include "base/timer/timer.h" #include "base/tracked_objects.h" #include "build/build_config.h" -#include "chrome/browser/invalidation/invalidator_storage.h" +#include "chrome/browser/invalidation/invalidation_service.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/net/network_time_tracker.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/token_service.h" #include "chrome/browser/signin/token_service_factory.h" -#include "chrome/browser/sync/glue/android_invalidator_bridge.h" -#include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/chrome_encryptor.h" #include "chrome/browser/sync/glue/device_info.h" -#include "chrome/browser/sync/glue/dummy_invalidator.h" #include "chrome/browser/sync/glue/sync_backend_registrar.h" #include "chrome/browser/sync/glue/synced_device_tracker.h" #include "chrome/browser/sync/sync_prefs.h" @@ -57,7 +53,6 @@ #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/invalidator.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/sync.pb.h" #include "sync/util/nigori.h" @@ -107,8 +102,7 @@ struct DoConfigureSyncerTypes { class SyncBackendHost::Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, public syncer::SyncEncryptionHandler::Observer, - public syncer::SyncManager::Observer, - public syncer::InvalidationHandler { + public syncer::SyncManager::Observer { public: Core(const std::string& name, const base::FilePath& sync_data_folder_path, @@ -149,11 +143,12 @@ class SyncBackendHost::Core virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, base::Time passphrase_time) OVERRIDE; - // syncer::InvalidationHandler implementation. - virtual void OnInvalidatorStateChange( - syncer::InvalidatorState state) OVERRIDE; - virtual void OnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; + // Forwards an invalidation state change to the sync manager. + void DoOnInvalidatorStateChange(syncer::InvalidatorState state); + + // Forwards an invalidation to the sync manager. + void DoOnIncomingInvalidation( + syncer::ObjectIdInvalidationMap invalidation_map); // Note: // @@ -170,15 +165,6 @@ class SyncBackendHost::Core // SyncBackendHost::UpdateCredentials. void DoUpdateCredentials(const syncer::SyncCredentials& credentials); - // Called to update the given registered ids on behalf of - // SyncBackendHost::UpdateRegisteredInvalidationIds. - void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); - - // Called to acknowledge an invalidation on behalf of - // SyncBackendHost::AcknowledgeInvalidation. - void DoAcknowledgeInvalidation(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle); - // Called to tell the syncapi to start syncing (generally after // initialization and authentication). void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); @@ -309,69 +295,13 @@ class SyncBackendHost::Core // The top-level syncapi entry point. Lives on the sync thread. scoped_ptr<syncer::SyncManager> sync_manager_; - // Whether or not we registered with |sync_manager_| as an invalidation - // handler. Necessary since we may end up trying to unregister before we - // register in tests (in synchronous initialization mode). - // - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). - bool registered_as_invalidation_handler_; - DISALLOW_COPY_AND_ASSIGN(Core); }; -namespace { - -// Parses the given command line for notifier options. -notifier::NotifierOptions ParseNotifierOptions( - const CommandLine& command_line, - const scoped_refptr<net::URLRequestContextGetter>& - request_context_getter) { - notifier::NotifierOptions notifier_options; - notifier_options.request_context_getter = request_context_getter; - if (!command_line.HasSwitch(switches::kSyncDisableOAuth2Token)) - notifier_options.auth_mechanism = "X-OAUTH2"; - - if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { - notifier_options.xmpp_host_port = - net::HostPortPair::FromString( - command_line.GetSwitchValueASCII( - switches::kSyncNotificationHostPort)); - DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() - << " for test sync notification server."; - } - - notifier_options.try_ssltcp_first = - command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); - DVLOG_IF(1, notifier_options.try_ssltcp_first) - << "Trying SSL/TCP port before XMPP port for notifications."; - - notifier_options.invalidate_xmpp_login = - command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); - DVLOG_IF(1, notifier_options.invalidate_xmpp_login) - << "Invalidating sync XMPP login."; - - notifier_options.allow_insecure_connection = - command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); - DVLOG_IF(1, notifier_options.allow_insecure_connection) - << "Allowing insecure XMPP connections."; - - if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { - const std::string notification_method_str( - command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); - notifier_options.notification_method = - notifier::StringToNotificationMethod(notification_method_str); - } - - return notifier_options; -} - -} // namespace - SyncBackendHost::SyncBackendHost( const std::string& name, Profile* profile, - const base::WeakPtr<SyncPrefs>& sync_prefs, - const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage) + const base::WeakPtr<SyncPrefs>& sync_prefs) : weak_ptr_factory_(this), sync_thread_("Chrome_SyncThread"), frontend_loop_(base::MessageLoop::current()), @@ -381,13 +311,10 @@ SyncBackendHost::SyncBackendHost( weak_ptr_factory_.GetWeakPtr())), initialization_state_(NOT_ATTEMPTED), sync_prefs_(sync_prefs), - invalidator_factory_( - ParseNotifierOptions(*CommandLine::ForCurrentProcess(), - profile_->GetRequestContext()), - content::GetUserAgent(GURL()), - invalidator_storage), frontend_(NULL), - cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { + cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), + invalidator_( + invalidation::InvalidationServiceFactory::GetForProfile(profile)) { } SyncBackendHost::SyncBackendHost(Profile* profile) @@ -397,18 +324,12 @@ SyncBackendHost::SyncBackendHost(Profile* profile) profile_(profile), name_("Unknown"), initialization_state_(NOT_ATTEMPTED), - invalidator_factory_( - ParseNotifierOptions(*CommandLine::ForCurrentProcess(), - profile_->GetRequestContext()), - content::GetUserAgent(GURL()), - base::WeakPtr<syncer::InvalidationStateTracker>()), frontend_(NULL), cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { } SyncBackendHost::~SyncBackendHost() { DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; - DCHECK(!android_invalidator_bridge_.get()); DCHECK(!registrar_.get()); } @@ -440,10 +361,6 @@ void SyncBackendHost::Initialize( if (!sync_thread_.Start()) return; - android_invalidator_bridge_.reset( - new AndroidInvalidatorBridge( - profile_, sync_thread_.message_loop_proxy())); - frontend_ = frontend; DCHECK(frontend); @@ -466,11 +383,7 @@ void SyncBackendHost::Initialize( InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; } - bool create_invalidator = true; -#if defined(ENABLE_MANAGED_USERS) - if (ManagedUserService::ProfileIsManaged(profile_)) - create_invalidator = false; -#endif + invalidator_->RegisterInvalidationHandler(this); initialization_state_ = CREATING_SYNC_MANAGER; InitCore(DoInitializeOptions( @@ -485,8 +398,7 @@ void SyncBackendHost::Initialize( make_scoped_refptr(profile_->GetRequestContext()), NetworkTimeTracker::BuildNotifierUpdateCallback()), credentials, - android_invalidator_bridge_.get(), - &invalidator_factory_, + invalidator_->GetInvalidatorClientId(), sync_manager_factory, delete_sync_data_folder, sync_prefs_->GetEncryptionBootstrapToken(), @@ -494,8 +406,7 @@ void SyncBackendHost::Initialize( new InternalComponentsFactoryImpl(factory_switches), unrecoverable_error_handler, report_unrecoverable_error_function, - !cl->HasSwitch(switches::kSyncDisableOAuth2Token), - create_invalidator)); + !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); } void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { @@ -505,24 +416,6 @@ void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { credentials)); } -void SyncBackendHost::UpdateRegisteredInvalidationIds( - const syncer::ObjectIdSet& ids) { - DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); - DCHECK(sync_thread_.IsRunning()); - sync_thread_.message_loop()->PostTask(FROM_HERE, - base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, - core_.get(), ids)); -} - -void SyncBackendHost::AcknowledgeInvalidation( - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { - DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); - DCHECK(sync_thread_.IsRunning()); - sync_thread_.message_loop()->PostTask(FROM_HERE, - base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, - core_.get(), id, ack_handle)); -} - void SyncBackendHost::StartSyncingWithServer() { SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; @@ -666,14 +559,17 @@ void SyncBackendHost::Shutdown(bool sync_disabled) { // StopSyncingForShutdown() (which nulls out |frontend_|) should be // called first. DCHECK(!frontend_); + + if (sync_disabled) + invalidator_->UpdateRegisteredInvalidationIds(this, syncer::ObjectIdSet()); + invalidator_->UnregisterInvalidationHandler(this); + invalidator_ = NULL; + // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. if (sync_thread_.IsRunning()) { sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), sync_disabled)); - - if (android_invalidator_bridge_) - android_invalidator_bridge_->StopForShutdown(); } // Stop will return once the thread exits, which will be after DoShutdown @@ -699,7 +595,6 @@ void SyncBackendHost::Shutdown(bool sync_disabled) { registrar_.reset(); js_backend_.Reset(); - android_invalidator_bridge_.reset(); core_ = NULL; // Releases reference to core_. } @@ -910,13 +805,18 @@ void SyncBackendHost::RequestConfigureSyncer( } void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( + const syncer::ModelTypeSet enabled_types, const syncer::ModelTypeSet succeeded_configuration_types, const syncer::ModelTypeSet failed_configuration_types, const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& ready_task) { if (!frontend_) return; - DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); + + invalidator_->UpdateRegisteredInvalidationIds( + this, + ModelTypeSetToObjectIdSet(enabled_types)); + if (!ready_task.is_null()) ready_task.Run(succeeded_configuration_types, failed_configuration_types); } @@ -947,6 +847,10 @@ void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : syncer::CONFIGURE_REASON_NEW_CLIENT); + // Fake a state change to initialize the SyncManager's cached invalidator + // state. + OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); + // Kick off the next step in SyncBackendHost initialization by downloading // any necessary control types. sync_thread_.message_loop()->PostTask( @@ -983,8 +887,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( const GURL& service_url, MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, const syncer::SyncCredentials& credentials, - AndroidInvalidatorBridge* android_invalidator_bridge, - syncer::InvalidatorFactory* invalidator_factory, + const std::string& invalidator_client_id, syncer::SyncManagerFactory* sync_manager_factory, bool delete_sync_data_folder, const std::string& restored_key_for_bootstrapping, @@ -993,8 +896,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, syncer::ReportUnrecoverableErrorFunction report_unrecoverable_error_function, - bool use_oauth2_token, - bool create_invalidator) + bool use_oauth2_token) : sync_loop(sync_loop), registrar(registrar), routing_info(routing_info), @@ -1004,8 +906,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( service_url(service_url), make_http_bridge_factory_fn(make_http_bridge_factory_fn), credentials(credentials), - android_invalidator_bridge(android_invalidator_bridge), - invalidator_factory(invalidator_factory), + invalidator_client_id(invalidator_client_id), sync_manager_factory(sync_manager_factory), delete_sync_data_folder(delete_sync_data_folder), restored_key_for_bootstrapping(restored_key_for_bootstrapping), @@ -1015,8 +916,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( unrecoverable_error_handler(unrecoverable_error_handler), report_unrecoverable_error_function( report_unrecoverable_error_function), - use_oauth2_token(use_oauth2_token), - create_invalidator(create_invalidator) { + use_oauth2_token(use_oauth2_token) { } SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} @@ -1028,8 +928,7 @@ SyncBackendHost::Core::Core(const std::string& name, sync_data_folder_path_(sync_data_folder_path), host_(backend), sync_loop_(NULL), - registrar_(NULL), - registered_as_invalidation_handler_(false) { + registrar_(NULL) { DCHECK(backend.get()); } @@ -1228,24 +1127,16 @@ void SyncBackendHost::Core::OnActionableError( sync_error); } -void SyncBackendHost::Core::OnInvalidatorStateChange( +void SyncBackendHost::Core::DoOnInvalidatorStateChange( syncer::InvalidatorState state) { - if (!sync_loop_) - return; DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - host_.Call(FROM_HERE, - &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, - state); + sync_manager_->OnInvalidatorStateChange(state); } -void SyncBackendHost::Core::OnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - if (!sync_loop_) - return; +void SyncBackendHost::Core::DoOnIncomingInvalidation( + syncer::ObjectIdInvalidationMap invalidation_map) { DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - host_.Call(FROM_HERE, - &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, - invalidation_map); + sync_manager_->OnIncomingInvalidation(invalidation_map); } void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { @@ -1271,17 +1162,6 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); sync_manager_->AddObserver(this); - scoped_ptr<syncer::Invalidator> invalidator; - if (options.create_invalidator) { -#if defined(OS_ANDROID) - invalidator.reset( - new AndroidInvalidatorBridgeProxy(options.android_invalidator_bridge)); -#else - invalidator.reset(options.invalidator_factory->CreateInvalidator()); -#endif - } else { - invalidator.reset(new DummyInvalidator()); - } sync_manager_->Init(sync_data_folder_path_, options.event_handler, options.service_url.host() + options.service_url.path(), @@ -1292,8 +1172,7 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { options.extensions_activity_monitor, options.registrar /* as SyncManager::ChangeDelegate */, options.credentials, - invalidator.Pass(), - options.invalidator_factory->GetInvalidatorClientId(), + options.invalidator_client_id, options.restored_key_for_bootstrapping, options.restored_keystore_key_for_bootstrapping, scoped_ptr<InternalComponentsFactory>( @@ -1308,9 +1187,6 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { // // TODO(akalin): Fix this behavior (see http://crbug.com/140354). if (sync_manager_) { - sync_manager_->RegisterInvalidationHandler(this); - registered_as_invalidation_handler_ = true; - // Now check the command line to see if we need to simulate an // unrecoverable error for testing purpose. Note the error is thrown // only if the initialization succeeded. Also it makes sense to use this @@ -1336,31 +1212,6 @@ void SyncBackendHost::Core::DoUpdateCredentials( } } -void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( - const syncer::ObjectIdSet& ids) { - DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - // |sync_manager_| may end up being NULL here in tests (in - // synchronous initialization mode) since this is called during - // shutdown. - // - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). - if (sync_manager_) { - sync_manager_->UpdateRegisteredInvalidationIds(this, ids); - } -} - -void SyncBackendHost::Core::DoAcknowledgeInvalidation( - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { - DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - // |sync_manager_| may end up being NULL here in tests (in - // synchronous initialization mode). - // - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). - if (sync_manager_) { - sync_manager_->AcknowledgeInvalidation(id, ack_handle); - } -} - void SyncBackendHost::Core::DoStartSyncing( const syncer::ModelSafeRoutingInfo& routing_info) { DCHECK_EQ(base::MessageLoop::current(), sync_loop_); @@ -1470,10 +1321,6 @@ void SyncBackendHost::Core::DoDestroySyncManager() { DCHECK_EQ(base::MessageLoop::current(), sync_loop_); if (sync_manager_) { save_changes_timer_.reset(); - if (registered_as_invalidation_handler_) { - sync_manager_->UnregisterInvalidationHandler(this); - registered_as_invalidation_handler_ = false; - } sync_manager_->RemoveObserver(this); sync_manager_->ShutdownOnSyncThread(); sync_manager_.reset(); @@ -1515,7 +1362,6 @@ void SyncBackendHost::Core::DoFinishConfigureDataTypes( registrar_->GetModelSafeRoutingInfo(&routing_info); syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); enabled_types.RemoveAll(syncer::ProxyTypes()); - sync_manager_->UpdateEnabledTypes(enabled_types); const syncer::ModelTypeSet failed_configuration_types = Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); @@ -1523,7 +1369,9 @@ void SyncBackendHost::Core::DoFinishConfigureDataTypes( Difference(types_to_config, failed_configuration_types); host_.Call(FROM_HERE, &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, - succeeded_configuration_types, failed_configuration_types, + enabled_types, + succeeded_configuration_types, + failed_configuration_types, ready_task); } @@ -1653,20 +1501,30 @@ void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( frontend_->OnActionableError(sync_error); } -void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( - syncer::InvalidatorState state) { - if (!frontend_) - return; - DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); - frontend_->OnInvalidatorStateChange(state); +void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) { + sync_thread_.message_loop()->PostTask( + FROM_HERE, + base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange, + core_.get(), + state)); } -void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( +void SyncBackendHost::OnIncomingInvalidation( const syncer::ObjectIdInvalidationMap& invalidation_map) { - if (!frontend_) - return; - DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); - frontend_->OnIncomingInvalidation(invalidation_map); + // TODO(dcheng): Acknowledge immediately for now. Fix this once the + // invalidator doesn't repeatedly ping for unacknowledged invaliations, since + // it conflicts with the sync scheduler's internal backoff algorithm. + // See http://crbug.com/124149 for more information. + for (syncer::ObjectIdInvalidationMap::const_iterator it = + invalidation_map.begin(); it != invalidation_map.end(); ++it) { + invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle); + } + + sync_thread_.message_loop()->PostTask( + FROM_HERE, + base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation, + core_.get(), + invalidation_map)); } bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index dbc9ab6..11a0d59 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -14,6 +14,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/threading/thread.h" +#include "chrome/browser/invalidation/invalidation_service.h" #include "chrome/browser/sync/glue/backend_data_type_configurer.h" #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h" #include "content/public/browser/notification_observer.h" @@ -30,7 +31,6 @@ #include "sync/internal_api/public/util/unrecoverable_error_handler.h" #include "sync/internal_api/public/util/weak_handle.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" @@ -44,14 +44,10 @@ namespace syncer { class SyncManagerFactory; } -namespace invalidation { -class InvalidatorStorage; -} - namespace browser_sync { -class AndroidInvalidatorBridge; class ChangeProcessor; +class InvalidatorStorage; class SyncBackendRegistrar; class SyncPrefs; class SyncedDeviceTracker; @@ -62,7 +58,7 @@ struct Experiments; // activity. // NOTE: All methods will be invoked by a SyncBackendHost on the same thread // used to create that SyncBackendHost. -class SyncFrontend : public syncer::InvalidationHandler { +class SyncFrontend { public: SyncFrontend() {} @@ -153,7 +149,8 @@ class SyncFrontend : public syncer::InvalidationHandler { // that the SyncFrontend is only accessed on the UI loop. class SyncBackendHost : public BackendDataTypeConfigurer, - public content::NotificationObserver { + public content::NotificationObserver, + public syncer::InvalidationHandler { public: typedef syncer::SyncStatus Status; @@ -164,10 +161,7 @@ class SyncBackendHost SyncBackendHost( const std::string& name, Profile* profile, - const base::WeakPtr<SyncPrefs>& sync_prefs, - // TODO(tim): Temporary, remove when bug 124137 finished. - const base::WeakPtr<invalidation::InvalidatorStorage>& - invalidator_storage); + const base::WeakPtr<SyncPrefs>& sync_prefs); // For testing. // TODO(skrul): Extract an interface so this is not needed. @@ -194,14 +188,6 @@ class SyncBackendHost // Called on |frontend_loop| to update SyncCredentials. virtual void UpdateCredentials(const syncer::SyncCredentials& credentials); - // Registers the underlying frontend for the given IDs to the underlying - // notifier. This lasts until StopSyncingForShutdown() is called. - void UpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); - - // Forwards an invalidation acknowledgement to the underlying notifier. - void AcknowledgeInvalidation(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle); - // This starts the SyncerThread running a Syncer object to communicate with // sync servers. Until this is called, no changes will leave or enter this // browser from the cloud / sync servers. @@ -325,8 +311,7 @@ class SyncBackendHost const GURL& service_url, MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, const syncer::SyncCredentials& credentials, - AndroidInvalidatorBridge* android_invalidator_bridge, - syncer::InvalidatorFactory* invalidator_factory, + const std::string& invalidator_client_id, syncer::SyncManagerFactory* sync_manager_factory, bool delete_sync_data_folder, const std::string& restored_key_for_bootstrapping, @@ -335,8 +320,7 @@ class SyncBackendHost syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, syncer::ReportUnrecoverableErrorFunction report_unrecoverable_error_function, - bool use_oauth2_token, - bool create_invalidator); + bool use_oauth2_token); ~DoInitializeOptions(); base::MessageLoop* sync_loop; @@ -349,8 +333,7 @@ class SyncBackendHost // Overridden by tests. MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; syncer::SyncCredentials credentials; - AndroidInvalidatorBridge* const android_invalidator_bridge; - syncer::InvalidatorFactory* const invalidator_factory; + const std::string invalidator_client_id; syncer::SyncManagerFactory* const sync_manager_factory; std::string lsid; bool delete_sync_data_folder; @@ -361,7 +344,6 @@ class SyncBackendHost syncer::ReportUnrecoverableErrorFunction report_unrecoverable_error_function; bool use_oauth2_token; - bool create_invalidator; }; // Allows tests to perform alternate core initialization work. @@ -383,6 +365,7 @@ class SyncBackendHost // Called when the syncer has finished performing a configuration. void FinishConfigureDataTypesOnFrontendLoop( + const syncer::ModelTypeSet enabled_types, const syncer::ModelTypeSet succeeded_configuration_types, const syncer::ModelTypeSet failed_configuration_types, const base::Callback<void(syncer::ModelTypeSet, @@ -515,6 +498,12 @@ class SyncBackendHost const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // InvalidationHandler implementation. + virtual void OnInvalidatorStateChange( + syncer::InvalidatorState state) OVERRIDE; + virtual void OnIncomingInvalidation( + const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; + // Handles stopping the core's SyncManager, accounting for whether // initialization is done yet. void StopSyncManagerForShutdown(const base::Closure& closure); @@ -542,10 +531,6 @@ class SyncBackendHost const base::WeakPtr<SyncPrefs> sync_prefs_; - scoped_ptr<AndroidInvalidatorBridge> android_invalidator_bridge_; - - syncer::InvalidatorFactory invalidator_factory_; - ChromeExtensionsActivityMonitor extensions_activity_monitor_; scoped_ptr<SyncBackendRegistrar> registrar_; @@ -583,6 +568,8 @@ class SyncBackendHost syncer::WeakHandle<syncer::JsBackend> js_backend_; syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; + invalidation::InvalidationService* invalidator_; + DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); }; diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc index 423a491..d694bc0 100644 --- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc +++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc @@ -146,13 +146,10 @@ class SyncBackendHostTest : public testing::Test { profile_.reset(new TestingProfile()); profile_->CreateRequestContext(); sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs())); - invalidator_storage_.reset(new invalidation::InvalidatorStorage( - profile_->GetPrefs())); backend_.reset(new SyncBackendHost( profile_->GetDebugName(), profile_.get(), - sync_prefs_->AsWeakPtr(), - invalidator_storage_->AsWeakPtr())); + sync_prefs_->AsWeakPtr())); credentials_.email = "user@example.com"; credentials_.sync_token = "sync_token"; @@ -178,7 +175,6 @@ class SyncBackendHostTest : public testing::Test { } backend_.reset(); sync_prefs_.reset(); - invalidator_storage_.reset(); profile_.reset(); // Pump messages posted by the sync thread (which may end up // posting on the IO thread). @@ -266,7 +262,6 @@ class SyncBackendHostTest : public testing::Test { syncer::TestUnrecoverableErrorHandler handler_; scoped_ptr<TestingProfile> profile_; scoped_ptr<SyncPrefs> sync_prefs_; - scoped_ptr<invalidation::InvalidatorStorage> invalidator_storage_; scoped_ptr<SyncBackendHost> backend_; FakeSyncManager* fake_manager_; FakeSyncManagerFactory fake_manager_factory_; @@ -594,76 +589,6 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { enabled_types_).Empty()); } -// Register for some IDs and trigger an invalidation. This should -// propagate all the way to the frontend. -TEST_F(SyncBackendHostTest, Invalidate) { - InitializeBackend(true); - - syncer::ObjectIdSet ids; - ids.insert(invalidation::ObjectId(1, "id1")); - ids.insert(invalidation::ObjectId(2, "id2")); - const syncer::ObjectIdInvalidationMap& invalidation_map = - syncer::ObjectIdSetToInvalidationMap(ids, "payload"); - - EXPECT_CALL( - mock_frontend_, - OnIncomingInvalidation(invalidation_map)) - .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); - - backend_->UpdateRegisteredInvalidationIds(ids); - fake_manager_->Invalidate(invalidation_map); - ui_loop_.PostDelayedTask( - FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); - ui_loop_.Run(); -} - -// Register for some IDs and update the invalidator state. This -// should propagate all the way to the frontend. -TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { - InitializeBackend(true); - - EXPECT_CALL(mock_frontend_, - OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED)) - .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); - - syncer::ObjectIdSet ids; - ids.insert(invalidation::ObjectId(3, "id3")); - backend_->UpdateRegisteredInvalidationIds(ids); - fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); - ui_loop_.PostDelayedTask( - FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); - ui_loop_.Run(); -} - -// Call StopSyncingForShutdown() on the backend and fire some invalidations -// before calling Shutdown(). Then start up and shut down the backend again. -// Those notifications shouldn't propagate to the frontend. -TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) { - InitializeBackend(true); - - syncer::ObjectIdSet ids; - ids.insert(invalidation::ObjectId(5, "id5")); - backend_->UpdateRegisteredInvalidationIds(ids); - - backend_->StopSyncingForShutdown(); - - // Should not trigger anything. - fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); - fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); - const syncer::ObjectIdInvalidationMap& invalidation_map = - syncer::ObjectIdSetToInvalidationMap(ids, "payload"); - fake_manager_->Invalidate(invalidation_map); - - // Make sure the above calls take effect before we continue. - fake_manager_->WaitForSyncThread(); - - backend_->Shutdown(false); - backend_.reset(); - - TearDown(); - SetUp(); -} - // Ensure the device info tracker is initialized properly on startup. TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 2ff7f5c..e9857e5 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -66,6 +66,7 @@ #include "google_apis/gaia/gaia_constants.h" #include "grit/generated_resources.h" #include "net/cookies/cookie_monster.h" +#include "net/url_request/url_request_context_getter.h" #include "sync/api/sync_error.h" #include "sync/internal_api/public/configure_reason.h" #include "sync/internal_api/public/sync_encryption_handler.h" @@ -73,8 +74,6 @@ #include "sync/internal_api/public/util/sync_string_conversions.h" #include "sync/js/js_arg_list.h" #include "sync/js/js_event_details.h" -#include "sync/notifier/invalidator_registrar.h" -#include "sync/notifier/invalidator_state.h" #include "sync/util/cryptographer.h" #include "ui/base/l10n/l10n_util.h" @@ -114,8 +113,6 @@ static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. static const char* kOAuth2Scopes[] = { GaiaConstants::kChromeSyncOAuth2Scope, - // GoogleTalk scope is needed for notifications. - GaiaConstants::kGoogleTalkOAuth2Scope }; static const char* kManagedOAuth2Scopes[] = { @@ -170,7 +167,6 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, profile_(profile), // |profile| may be NULL in unit tests. sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), - invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), sync_service_url_(kDevServerUrl), data_type_requested_sync_startup_(false), is_first_time_sync_configure_(false), @@ -187,7 +183,6 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, auto_start_enabled_(start_behavior == AUTO_START), configure_status_(DataTypeManager::UNKNOWN), setup_in_progress_(false), - invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR), request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) { // By default, dev, canary, and unbranded Chromium users will go to the // development servers. Development servers have more features than standard @@ -240,9 +235,6 @@ bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { } void ProfileSyncService::Initialize() { - DCHECK(!invalidator_registrar_.get()); - invalidator_registrar_.reset(new syncer::InvalidatorRegistrar()); - InitSettings(); // We clear this here (vs Shutdown) because we want to remember that an error @@ -507,8 +499,7 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) { void ProfileSyncService::CreateBackend() { backend_.reset( new SyncBackendHost(profile_->GetDebugName(), - profile_, sync_prefs_.AsWeakPtr(), - invalidator_storage_.AsWeakPtr())); + profile_, sync_prefs_.AsWeakPtr())); } bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { @@ -634,60 +625,6 @@ void ProfileSyncService::StartUpSlowBackendComponents() { // we'll want to start from a fresh SyncDB, so delete any old one that might // be there. InitializeBackend(!HasSyncSetupCompleted()); - - // |backend_| may end up being NULL here in tests (in synchronous - // initialization mode). - // - // TODO(akalin): Fix this horribly non-intuitive behavior (see - // http://crbug.com/140354). - if (backend_) { - backend_->UpdateRegisteredInvalidationIds( - invalidator_registrar_->GetAllRegisteredIds()); - for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin(); - it != ack_replay_queue_.end(); ++it) { - backend_->AcknowledgeInvalidation(it->first, it->second); - } - ack_replay_queue_.clear(); - } -} - -void ProfileSyncService::RegisterInvalidationHandler( - syncer::InvalidationHandler* handler) { - invalidator_registrar_->RegisterHandler(handler); -} - -void ProfileSyncService::UpdateRegisteredInvalidationIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) { - invalidator_registrar_->UpdateRegisteredIds(handler, ids); - - // If |backend_| is NULL, its registered IDs will be updated when - // it's created and initialized. - if (backend_) { - backend_->UpdateRegisteredInvalidationIds( - invalidator_registrar_->GetAllRegisteredIds()); - } -} - -void ProfileSyncService::UnregisterInvalidationHandler( - syncer::InvalidationHandler* handler) { - invalidator_registrar_->UnregisterHandler(handler); -} - -void ProfileSyncService::AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) { - if (backend_) { - backend_->AcknowledgeInvalidation(id, ack_handle); - } else { - // If |backend_| is NULL, save the acknowledgements to replay when - // it's created and initialized. - ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); - } -} - -syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { - return invalidator_registrar_->GetInvalidatorState(); } void ProfileSyncService::OnGetTokenSuccess( @@ -751,23 +688,7 @@ void ProfileSyncService::OnGetTokenFailure( } } -void ProfileSyncService::EmitInvalidationForTest( - const invalidation::ObjectId& id, - const std::string& payload) { - syncer::ObjectIdSet notify_ids; - notify_ids.insert(id); - - const syncer::ObjectIdInvalidationMap& invalidation_map = - ObjectIdSetToInvalidationMap(notify_ids, payload); - OnIncomingInvalidation(invalidation_map); -} - void ProfileSyncService::Shutdown() { - DCHECK(invalidator_registrar_.get()); - // Reset |invalidator_registrar_| first so that ShutdownImpl cannot - // use it. - invalidator_registrar_.reset(); - if (signin_) signin_->signin_global_error()->RemoveProvider(this); @@ -822,9 +743,6 @@ void ProfileSyncService::ShutdownImpl(bool sync_disabled) { expect_sync_configuration_aborted_ = false; is_auth_in_progress_ = false; backend_initialized_ = false; - // NULL if we're called from Shutdown(). - if (invalidator_registrar_) - UpdateInvalidatorRegistrarState(); cached_passphrase_.clear(); encryption_pending_ = false; encrypt_everything_ = false; @@ -849,7 +767,6 @@ void ProfileSyncService::DisableForUser() { // Clear prefs (including SyncSetupHasCompleted) before shutting down so // PSS clients don't think we're set up while we're shutting down. sync_prefs_.ClearPreferences(); - invalidator_storage_.Clear(); ClearUnrecoverableError(); ShutdownImpl(true); } @@ -871,6 +788,11 @@ void ProfileSyncService::NotifyObservers() { FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); // TODO(akalin): Make an Observer subclass that listens and does the // event routing. + sync_js_controller_.HandleJsEvent("onServiceStateChanged", JsEventDetails()); +} + +void ProfileSyncService::NotifySyncCycleCompleted() { + FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted()); sync_js_controller_.HandleJsEvent( "onServiceStateChanged", JsEventDetails()); } @@ -954,17 +876,6 @@ void ProfileSyncService::DisableBrokenDatatype( weak_factory_.GetWeakPtr())); } -void ProfileSyncService::OnInvalidatorStateChange( - syncer::InvalidatorState state) { - invalidator_state_ = state; - UpdateInvalidatorRegistrarState(); -} - -void ProfileSyncService::OnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map); -} - void ProfileSyncService::OnBackendInitialized( const syncer::WeakHandle<syncer::JsBackend>& js_backend, const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& @@ -1008,7 +919,6 @@ void ProfileSyncService::OnBackendInitialized( } backend_initialized_ = true; - UpdateInvalidatorRegistrarState(); sync_js_controller_.AttachJsBackend(js_backend); debug_info_listener_ = debug_info_listener; @@ -1057,7 +967,7 @@ void ProfileSyncService::OnSyncCycleCompleted() { GetSessionModelAssociator()->AsWeakPtr())); } DVLOG(2) << "Notifying observers sync cycle completed"; - NotifyObservers(); + NotifySyncCycleCompleted(); } void ProfileSyncService::OnExperimentsChanged( @@ -1153,10 +1063,10 @@ AuthError ConnectionStatusToAuthError( void ProfileSyncService::OnConnectionStatusChange( syncer::ConnectionStatus status) { if (use_oauth2_token_ && status == syncer::CONNECTION_AUTH_ERROR) { - // Sync or Tango server returned error indicating that access token is - // invalid. It could be either expired or access is revoked. Let's request - // another access token and if access is revoked then request for token will - // fail with corresponding error. + // Sync server returned error indicating that access token is invalid. It + // could be either expired or access is revoked. Let's request another + // access token and if access is revoked then request for token will fail + // with corresponding error. RequestAccessToken(); } else { const GoogleServiceAuthError auth_error = @@ -2181,17 +2091,6 @@ void ProfileSyncService::OnInternalUnrecoverableError( OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); } -void ProfileSyncService::UpdateInvalidatorRegistrarState() { - const syncer::InvalidatorState effective_state = - backend_initialized_ ? - invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR; - DVLOG(1) << "New invalidator state: " - << syncer::InvalidatorStateToString(invalidator_state_) - << ", effective state: " - << syncer::InvalidatorStateToString(effective_state); - invalidator_registrar_->UpdateInvalidatorState(effective_state); -} - std::string ProfileSyncService::GetEffectiveUsername() { #if defined(ENABLE_MANAGED_USERS) if (ManagedUserService::ProfileIsManaged(profile_)) { diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index c583fcb..6e9a0e7 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -19,8 +19,6 @@ #include "base/strings/string16.h" #include "base/time/time.h" #include "base/timer/timer.h" -#include "chrome/browser/invalidation/invalidation_frontend.h" -#include "chrome/browser/invalidation/invalidator_storage.h" #include "chrome/browser/signin/oauth2_token_service.h" #include "chrome/browser/signin/signin_global_error.h" #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" @@ -65,7 +63,6 @@ namespace sessions { class SyncSessionSnapshot; } namespace syncer { class BaseTransaction; -class InvalidatorRegistrar; struct SyncCredentials; struct UserShare; } @@ -165,7 +162,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, public syncer::UnrecoverableErrorHandler, public content::NotificationObserver, public BrowserContextKeyedService, - public invalidation::InvalidationFrontend, public browser_sync::DataTypeEncryptionHandler, public OAuth2TokenService::Consumer { public: @@ -288,12 +284,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // Disables sync for user. Use ShowLoginDialog to enable. virtual void DisableForUser(); - // syncer::InvalidationHandler implementation (via SyncFrontend). - virtual void OnInvalidatorStateChange( - syncer::InvalidatorState state) OVERRIDE; - virtual void OnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; - // SyncFrontend implementation. virtual void OnBackendInitialized( const syncer::WeakHandle<syncer::JsBackend>& js_backend, @@ -600,21 +590,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // The set of currently enabled sync experiments. const syncer::Experiments& current_experiments() const; - // InvalidationFrontend implementation. It is an error to have - // registered handlers when Shutdown() is called. - virtual void RegisterInvalidationHandler( - syncer::InvalidationHandler* handler) OVERRIDE; - virtual void UpdateRegisteredInvalidationIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterInvalidationHandler( - syncer::InvalidationHandler* handler) OVERRIDE; - virtual void AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; - - virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; - // OAuth2TokenService::Consumer implementation virtual void OnGetTokenSuccess( const OAuth2TokenService::Request* request, @@ -628,11 +603,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // once (before this object is destroyed). virtual void Shutdown() OVERRIDE; - // Simulate an incoming notification for the given id and payload. - void EmitInvalidationForTest( - const invalidation::ObjectId& id, - const std::string& payload); - // Called when a datatype (SyncableService) has a need for sync to start // ASAP, presumably because a local change event has occurred but we're // still in deferred start mode, meaning the SyncableService hasn't been @@ -703,8 +673,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, ERROR_REASON_ACTIONABLE_ERROR, ERROR_REASON_LIMIT }; - typedef std::vector<std::pair<invalidation::ObjectId, - syncer::AckHandle> > AckHandleReplayQueue; friend class ProfileSyncServicePasswordTest; friend class SyncTest; friend class TestProfileSyncService; @@ -751,6 +719,7 @@ class ProfileSyncService : public ProfileSyncServiceBase, void UpdateLastSyncedTime(); void NotifyObservers(); + void NotifySyncCycleCompleted(); void ClearStaleErrors(); @@ -800,11 +769,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, bool delete_sync_database, UnrecoverableErrorReason reason); - // Must be called every time |backend_initialized_| or - // |invalidator_state_| is changed (but only if - // |invalidator_registrar_| is not NULL). - void UpdateInvalidatorRegistrarState(); - // Returns the username (in form of an email address) that should be used in // the credentials. std::string GetEffectiveUsername(); @@ -819,9 +783,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // preferences. browser_sync::SyncPrefs sync_prefs_; - // TODO(tim): Move this to InvalidationService, once it exists. Bug 124137. - invalidation::InvalidatorStorage invalidator_storage_; - // TODO(ncarter): Put this in a profile, once there is UI for it. // This specifies where to find the sync server. GURL sync_service_url_; @@ -942,18 +903,6 @@ class ProfileSyncService : public ProfileSyncServiceBase, // Factory the backend will use to build the SyncManager. syncer::SyncManagerFactory sync_manager_factory_; - // Holds the current invalidator state as updated by - // OnInvalidatorStateChange(). Note that this is different from the - // state known by |invalidator_registrar_| (See - // UpdateInvalidatorState()). - syncer::InvalidatorState invalidator_state_; - - // Dispatches invalidations to handlers. Set in Initialize() and - // unset in Shutdown(). - scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; - // Queues any acknowledgements received while the backend is uninitialized. - AckHandleReplayQueue ack_replay_queue_; - // Sync's internal debug info listener. Used to record datatype configuration // and association information. syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 33f5727..9868af7 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -565,7 +565,7 @@ class ProfileSyncServiceAutofillTest AbstractAutofillFactory* factory = GetFactory(type); SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_.get()); - signin->SetAuthenticatedUsername("test_user"); + signin->SetAuthenticatedUsername("test_user@gmail.com"); sync_service_ = static_cast<TestProfileSyncService*>( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), &TestProfileSyncService::BuildAutoStartAsyncInit)); diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc index f43c988..d41da39 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc @@ -12,6 +12,7 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -64,6 +65,7 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory() DependsOn(HistoryServiceFactory::GetInstance()); DependsOn(BookmarkModelFactory::GetInstance()); DependsOn(AboutSigninInternalsFactory::GetInstance()); + DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); // The following have not been converted to BrowserContextKeyedServices yet, // and for now they are explicitly destroyed after the diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index ee77cb7..47b7434 100644 --- a/chrome/browser/sync/profile_sync_service_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -21,6 +21,7 @@ #include "base/memory/ref_counted.h" #include "base/message_loop.h" #include "base/prefs/pref_service.h" +#include "chrome/browser/invalidation/p2p_invalidation_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/signin_manager_base.h" #include "chrome/browser/signin/token_service.h" @@ -38,6 +39,7 @@ #include "sync/internal_api/public/util/sync_string_conversions.h" using syncer::sessions::SyncSessionSnapshot; +using invalidation::P2PInvalidationService; // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. // The amount of time for which we wait for a live sync operation to complete. @@ -106,14 +108,36 @@ bool StateChangeTimeoutEvent::Abort() { return !did_timeout_; } +// static +ProfileSyncServiceHarness* ProfileSyncServiceHarness::Create( + Profile* profile, + const std::string& username, + const std::string& password) { + return new ProfileSyncServiceHarness(profile, username, password, NULL); +} + +// static +ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateForIntegrationTest( + Profile* profile, + const std::string& username, + const std::string& password, + P2PInvalidationService* p2p_invalidation_service) { + return new ProfileSyncServiceHarness(profile, + username, + password, + p2p_invalidation_service); +} + ProfileSyncServiceHarness::ProfileSyncServiceHarness( Profile* profile, const std::string& username, - const std::string& password) + const std::string& password, + P2PInvalidationService* p2p_invalidation_service) : waiting_for_encryption_type_(syncer::UNSPECIFIED), wait_state_(INITIAL_WAIT_STATE), profile_(profile), service_(NULL), + p2p_invalidation_service_(p2p_invalidation_service), progress_marker_partner_(NULL), username_(username), password_(password), @@ -133,17 +157,6 @@ ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { service_->RemoveObserver(this); } -// static -ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( - Profile* profile) { - ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance(); - if (!f->HasProfileSyncService(profile)) { - NOTREACHED() << "Profile has never signed into sync."; - return NULL; - } - return new ProfileSyncServiceHarness(profile, std::string(), std::string()); -} - void ProfileSyncServiceHarness::SetCredentials(const std::string& username, const std::string& password) { username_ = username; @@ -482,6 +495,21 @@ void ProfileSyncServiceHarness::OnStateChanged() { RunStateChangeMachine(); } +void ProfileSyncServiceHarness::OnSyncCycleCompleted() { + // Integration tests still use p2p notifications. + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); + bool is_notifiable_commit = + (snap.model_neutral_state().num_successful_commits > 0); + if (is_notifiable_commit && p2p_invalidation_service_) { + const syncer::ObjectIdInvalidationMap& invalidation_map = + ModelTypeInvalidationMapToObjectIdInvalidationMap( + snap.source().types); + p2p_invalidation_service_->SendInvalidation(invalidation_map); + } + + OnStateChanged(); +} + void ProfileSyncServiceHarness::OnMigrationStateChange() { // Update migration state. if (HasPendingBackendMigration()) { diff --git a/chrome/browser/sync/profile_sync_service_harness.h b/chrome/browser/sync/profile_sync_service_harness.h index 42594ba..a43e8a6 100644 --- a/chrome/browser/sync/profile_sync_service_harness.h +++ b/chrome/browser/sync/profile_sync_service_harness.h @@ -18,6 +18,10 @@ class Profile; +namespace invalidation { +class P2PInvalidationService; +} + namespace browser_sync { namespace sessions { class SyncSessionSnapshot; @@ -33,16 +37,18 @@ class ProfileSyncServiceHarness : public ProfileSyncServiceObserver, public browser_sync::MigrationObserver { public: - ProfileSyncServiceHarness(Profile* profile, - const std::string& username, - const std::string& password); + static ProfileSyncServiceHarness* Create( + Profile* profile, + const std::string& username, + const std::string& password); - virtual ~ProfileSyncServiceHarness(); + static ProfileSyncServiceHarness* CreateForIntegrationTest( + Profile* profile, + const std::string& username, + const std::string& password, + invalidation::P2PInvalidationService* invalidation_service); - // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a - // profile that is assumed to have been signed into sync in the past. Caller - // takes ownership. - static ProfileSyncServiceHarness* CreateAndAttach(Profile* profile); + virtual ~ProfileSyncServiceHarness(); // Sets the GAIA credentials with which to sign in to sync. void SetCredentials(const std::string& username, const std::string& password); @@ -62,6 +68,7 @@ class ProfileSyncServiceHarness // ProfileSyncServiceObserver implementation. virtual void OnStateChanged() OVERRIDE; + virtual void OnSyncCycleCompleted() OVERRIDE; // MigrationObserver implementation. virtual void OnMigrationStateChange() OVERRIDE; @@ -270,6 +277,12 @@ class ProfileSyncServiceHarness NUMBER_OF_STATES, }; + ProfileSyncServiceHarness( + Profile* profile, + const std::string& username, + const std::string& password, + invalidation::P2PInvalidationService* invalidation_service); + // Listen to migration events if the migrator has been initialized // and we're not already listening. Returns true if we started // listening. @@ -334,6 +347,9 @@ class ProfileSyncServiceHarness // ProfileSyncService object associated with |profile_|. ProfileSyncService* service_; + // P2PInvalidationService associated with |profile_|. + invalidation::P2PInvalidationService* p2p_invalidation_service_; + // The harness of the client whose update progress marker we're expecting // eventually match. ProfileSyncServiceHarness* progress_marker_partner_; diff --git a/chrome/browser/sync/profile_sync_service_observer.cc b/chrome/browser/sync/profile_sync_service_observer.cc new file mode 100644 index 0000000..9a8bde7 --- /dev/null +++ b/chrome/browser/sync/profile_sync_service_observer.cc @@ -0,0 +1,9 @@ +// Copyright 2013 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 "chrome/browser/sync/profile_sync_service_observer.h" + +void ProfileSyncServiceObserver::OnSyncCycleCompleted() { + OnStateChanged(); +} diff --git a/chrome/browser/sync/profile_sync_service_observer.h b/chrome/browser/sync/profile_sync_service_observer.h index de8c997..9916c5d 100644 --- a/chrome/browser/sync/profile_sync_service_observer.h +++ b/chrome/browser/sync/profile_sync_service_observer.h @@ -16,6 +16,11 @@ class ProfileSyncServiceObserver { // - The sync servers are unavailable at this time. // - Credentials are now in flight for authentication. virtual void OnStateChanged() = 0; + + // If a client wishes to handle sync cycle completed events in a special way, + // they can use this function. By default, it re-routes to OnStateChanged(). + virtual void OnSyncCycleCompleted(); + protected: virtual ~ProfileSyncServiceObserver() { } }; diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index 235f7b7..22686b4 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -13,6 +13,7 @@ #include "base/synchronization/waitable_event.h" #include "base/test/test_timeouts.h" #include "base/time/time.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/password_manager/mock_password_store.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store_factory.h" @@ -155,6 +156,8 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { AbstractProfileSyncServiceTest::SetUp(); profile_.reset(new ProfileMock); profile_->CreateRequestContext(); + invalidation::InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); password_store_ = static_cast<MockPasswordStore*>( PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), MockPasswordStore::Build).get()); @@ -187,7 +190,7 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { if (!sync_service_) { SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_.get()); - signin->SetAuthenticatedUsername("test_user"); + signin->SetAuthenticatedUsername("test_user@gmail.com"); token_service_ = static_cast<TokenService*>( TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), BuildTokenService)); diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc index 66bc938..076a7fb 100644 --- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc @@ -13,6 +13,7 @@ #include "base/location.h" #include "base/stl_util.h" #include "base/strings/string_piece.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/prefs/pref_model_associator.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/signin/signin_manager.h" @@ -124,6 +125,8 @@ class ProfileSyncServicePreferenceTest AbstractProfileSyncServiceTest::SetUp(); profile_.reset(new TestingProfile()); profile_->CreateRequestContext(); + invalidation::InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); prefs_ = profile_->GetTestingPrefService(); prefs_->registry()->RegisterStringPref( diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc index 3344f74..36a5116 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -16,6 +16,7 @@ #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/token_service_factory.h" @@ -205,6 +206,8 @@ class ProfileSyncServiceSessionTest // Don't want the profile to create a real ProfileSyncService. ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, NULL); + invalidation::InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); return profile; } diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc index 2bb87ab..be60db9 100644 --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc @@ -168,7 +168,7 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "test_user"); + "test_user@gmail.com"); signin->Initialize(profile, NULL); EXPECT_FALSE(signin->GetAuthenticatedUsername().empty()); return new TestProfileSyncService( @@ -216,9 +216,9 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { // Simulate successful signin as test_user. profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "test_user"); - sync_->signin()->SetAuthenticatedUsername("test_user"); - GoogleServiceSigninSuccessDetails details("test_user", ""); + "test_user@gmail.com"); + sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); + GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); content::NotificationService::current()->Notify( chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, content::Source<Profile>(profile_.get()), @@ -263,9 +263,9 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { // Simulate successful signin as test_user. profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "test_user"); - sync_->signin()->SetAuthenticatedUsername("test_user"); - GoogleServiceSigninSuccessDetails details("test_user", ""); + "test_user@gmail.com"); + sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); + GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); content::NotificationService::current()->Notify( chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, content::Source<Profile>(profile_.get()), @@ -284,7 +284,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { // TODO(pavely): Reenable test once android is switched to oauth2. TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, - "test_user"); + "test_user@gmail.com"); SigninManagerFactory::GetForProfile( profile_.get())->Initialize(profile_.get(), NULL); CreateSyncService(); @@ -313,7 +313,8 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { sync_->SetSetupInProgress(true); // Simulate successful signin. - GoogleServiceSigninSuccessDetails details("test_user", std::string()); + GoogleServiceSigninSuccessDetails details("test_user@gmail.com", + std::string()); content::NotificationService::current()->Notify( chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, content::Source<Profile>(profile_.get()), @@ -367,7 +368,8 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { TEST_F(ProfileSyncServiceStartupTest, StartNormal) { // Pre load the tokens - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -400,7 +402,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { } // Pre load the tokens - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -429,7 +432,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); // Pre load the tokens - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -451,7 +455,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { // Service should not be started by Initialize() since it's managed. - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -468,7 +473,8 @@ TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { } TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -499,7 +505,8 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { } TEST_F(ProfileSyncServiceStartupTest, StartFailure) { - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); @@ -532,7 +539,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartFailure) { TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { // Pre load the tokens - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, + "test_user@gmail.com"); SigninManagerFactory::GetForProfile(profile_.get())->Initialize( profile_.get(), NULL); CreateSyncService(); diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index ad3dfb5..8c71be7 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_types.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/token_service_factory.h" @@ -175,6 +176,8 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { AbstractProfileSyncServiceTest::SetUp(); profile_.reset(new ProfileMock); profile_->CreateRequestContext(); + invalidation::InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); history_backend_ = new HistoryBackendMock(); history_service_ = static_cast<HistoryServiceMock*>( HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index 3280634..6e7bbe7 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/values.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/token_service.h" @@ -26,10 +27,6 @@ #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_invalidation_handler.h" -#include "sync/notifier/invalidator.h" -#include "sync/notifier/invalidator_test_template.h" -#include "sync/notifier/object_id_invalidation_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -64,6 +61,8 @@ class ProfileSyncServiceTestHarness { io_thread_.StartIOThread(); profile.reset(new TestingProfile()); profile->CreateRequestContext(); + invalidation::InvalidationServiceFactory::GetInstance()-> + SetBuildOnlyFakeInvalidatorsForTest(true); } void TearDown() { @@ -357,7 +356,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) { StrictMock<syncer::MockJsReplyHandler> reply_handler; ListValue arg_list1; - arg_list1.Append(Value::CreateStringValue("TRANSIENT_INVALIDATION_ERROR")); + arg_list1.Append(Value::CreateStringValue("INVALIDATIONS_ENABLED")); syncer::JsArgList args1(&arg_list1); EXPECT_CALL(reply_handler, HandleJsReply("getNotificationState", HasArgs(args1))); @@ -381,7 +380,7 @@ TEST_F(ProfileSyncServiceTest, StrictMock<syncer::MockJsReplyHandler> reply_handler; ListValue arg_list1; - arg_list1.Append(Value::CreateStringValue("TRANSIENT_INVALIDATION_ERROR")); + arg_list1.Append(Value::CreateStringValue("INVALIDATIONS_ENABLED")); syncer::JsArgList args1(&arg_list1); EXPECT_CALL(reply_handler, HandleJsReply("getNotificationState", HasArgs(args1))); @@ -467,178 +466,5 @@ TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) { EXPECT_FALSE(harness_.service->sync_initialized()); } -// Register a handler with the ProfileSyncService, and disable and -// reenable sync. The handler should get notified of the state -// changes. -// Flaky on all platforms. http://crbug.com/154491 -TEST_F(ProfileSyncServiceTest, DISABLED_DisableInvalidationsOnStop) { - harness_.StartSyncServiceAndSetInitialSyncEnded( - true, true, true, true, syncer::STORAGE_IN_MEMORY); - - syncer::FakeInvalidationHandler handler; - harness_.service->RegisterInvalidationHandler(&handler); - - SyncBackendHostForProfileSyncTest* const backend = - harness_.service->GetBackendForTest(); - - backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); - EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); - - harness_.service->StopAndSuppress(); - EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, - handler.GetInvalidatorState()); - - harness_.service->UnsuppressAndStart(); - EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); - - harness_.service->UnregisterInvalidationHandler(&handler); -} - -// Register for some IDs with the ProfileSyncService, restart sync, -// and trigger some invalidation messages. They should still be -// received by the handler. -TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { - harness_.StartSyncService(); - - syncer::ObjectIdSet ids; - ids.insert(invalidation::ObjectId(3, "id3")); - const syncer::ObjectIdInvalidationMap& states = - syncer::ObjectIdSetToInvalidationMap(ids, "payload"); - - syncer::FakeInvalidationHandler handler; - - harness_.service->RegisterInvalidationHandler(&handler); - harness_.service->UpdateRegisteredInvalidationIds(&handler, ids); - - harness_.service->StopAndSuppress(); - harness_.service->UnsuppressAndStart(); - - SyncBackendHostForProfileSyncTest* const backend = - harness_.service->GetBackendForTest(); - - backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); - EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); - - backend->EmitOnIncomingInvalidation(states); - EXPECT_THAT(states, Eq(handler.GetLastInvalidationMap())); - - backend->EmitOnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); - EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, - handler.GetInvalidatorState()); - - harness_.service->UnregisterInvalidationHandler(&handler); -} - -// Thin Invalidator wrapper around ProfileSyncService. -class ProfileSyncServiceInvalidator : public syncer::Invalidator { - public: - explicit ProfileSyncServiceInvalidator(ProfileSyncService* service) - : service_(service) {} - - virtual ~ProfileSyncServiceInvalidator() {} - - // Invalidator implementation. - virtual void RegisterHandler(syncer::InvalidationHandler* handler) OVERRIDE { - service_->RegisterInvalidationHandler(handler); - } - - virtual void UpdateRegisteredIds(syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) OVERRIDE { - service_->UpdateRegisteredInvalidationIds(handler, ids); - } - - virtual void UnregisterHandler( - syncer::InvalidationHandler* handler) OVERRIDE { - service_->UnregisterInvalidationHandler(handler); - } - - virtual void Acknowledge(const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE { - // Do nothing. - } - - virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE { - return service_->GetInvalidatorState(); - } - - virtual void UpdateCredentials( - const std::string& email, const std::string& token) OVERRIDE { - // Do nothing. - } - - virtual void SendInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE { - // Do nothing. - } - - private: - ProfileSyncService* const service_; - - DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceInvalidator); -}; - } // namespace - - -// ProfileSyncServiceInvalidatorTestDelegate has to be visible from -// the syncer namespace (where InvalidatorTest lives). -class ProfileSyncServiceInvalidatorTestDelegate { - public: - ProfileSyncServiceInvalidatorTestDelegate() {} - - ~ProfileSyncServiceInvalidatorTestDelegate() { - DestroyInvalidator(); - } - - void CreateInvalidator( - const std::string& invalidation_client_id, - const std::string& initial_state, - const base::WeakPtr<syncer::InvalidationStateTracker>& - invalidation_state_tracker) { - DCHECK(!invalidator_.get()); - harness_.SetUp(); - harness_.StartSyncService(); - invalidator_.reset( - new ProfileSyncServiceInvalidator(harness_.service.get())); - } - - ProfileSyncServiceInvalidator* GetInvalidator() { - return invalidator_.get(); - } - - void DestroyInvalidator() { - invalidator_.reset(); - harness_.TearDown(); - } - - void WaitForInvalidator() { - // Do nothing. - } - - void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) { - harness_.service->GetBackendForTest()->EmitOnInvalidatorStateChange(state); - } - - void TriggerOnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - harness_.service->GetBackendForTest()->EmitOnIncomingInvalidation( - invalidation_map); - } - - private: - ProfileSyncServiceTestHarness harness_; - scoped_ptr<ProfileSyncServiceInvalidator> invalidator_; -}; - } // namespace browser_sync - -namespace syncer { -namespace { - -// ProfileSyncService should behave just like an invalidator. -INSTANTIATE_TYPED_TEST_CASE_P( - ProfileSyncServiceInvalidatorTest, InvalidatorTest, - ::browser_sync::ProfileSyncServiceInvalidatorTestDelegate); - -} // namespace -} // namespace syncer diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 8db1baa..c45ea1e 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -21,6 +21,8 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/invalidation/invalidation_service_factory.h" +#include "chrome/browser/invalidation/p2p_invalidation_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -60,6 +62,7 @@ #include "sync/protocol/sync.pb.h" using content::BrowserThread; +using invalidation::InvalidationServiceFactory; namespace switches { const char kPasswordFileForTest[] = "password-file-for-test"; @@ -196,11 +199,6 @@ void SyncTest::SetUpCommandLine(CommandLine* cl) { } void SyncTest::AddTestSwitches(CommandLine* cl) { - // TODO(rsimha): Until we implement a fake Tango server against which tests - // can run, we need to set the --sync-notification-method to "p2p". - if (!cl->HasSwitch(switches::kSyncNotificationMethod)) - cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); - // Disable non-essential access of external network resources. if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) cl->AppendSwitch(switches::kDisableBackgroundNetworking); @@ -306,14 +304,22 @@ void SyncTest::InitializeInstance(int index) { EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser " << index << "."; + invalidation::P2PInvalidationService* p2p_invalidation_service = + InvalidationServiceFactory::GetInstance()-> + BuildAndUseP2PInvalidationServiceForTest(GetProfile(index)); + p2p_invalidation_service->UpdateCredentials(username_, password_); + // Make sure the ProfileSyncService has been created before creating the // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to // already exist. ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); - clients_[index] = new ProfileSyncServiceHarness(GetProfile(index), - username_, - password_); + clients_[index] = + ProfileSyncServiceHarness::CreateForIntegrationTest( + GetProfile(index), + username_, + password_, + p2p_invalidation_service); EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " << index << "."; diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc index 11bb5e3..dac67f2 100644 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -36,7 +36,6 @@ namespace browser_sync { SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( Profile* profile, const base::WeakPtr<SyncPrefs>& sync_prefs, - const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage, syncer::TestIdFactory& id_factory, base::Closure& callback, bool set_initial_sync_ended_on_init, @@ -44,7 +43,7 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( bool fail_initial_download, syncer::StorageOption storage_option) : browser_sync::SyncBackendHost( - profile->GetDebugName(), profile, sync_prefs, invalidator_storage), + profile->GetDebugName(), profile, sync_prefs), weak_ptr_factory_(this), id_factory_(id_factory), callback_(callback), @@ -116,8 +115,13 @@ void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer( if (fail_initial_download_) failed_configuration_types = to_download; + // The first parameter there should be the set of enabled types. That's not + // something we have access to from this strange test harness. We'll just + // send back the list of newly configured types instead and hope it doesn't + // break anything. FinishConfigureDataTypesOnFrontendLoop( syncer::Difference(to_download, failed_configuration_types), + syncer::Difference(to_download, failed_configuration_types), failed_configuration_types, ready_task); } @@ -179,16 +183,6 @@ void SyncBackendHostForProfileSyncTest } } -void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( - syncer::InvalidatorState state) { - frontend()->OnInvalidatorStateChange(state); -} - -void SyncBackendHostForProfileSyncTest::EmitOnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - frontend()->OnIncomingInvalidation(invalidation_map); -} - void SyncBackendHostForProfileSyncTest::ContinueInitialization( const syncer::WeakHandle<syncer::JsBackend>& js_backend, const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& @@ -311,7 +305,6 @@ void TestProfileSyncService::CreateBackend() { backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( profile(), sync_prefs_.AsWeakPtr(), - invalidator_storage_.AsWeakPtr(), id_factory_, callback_, set_initial_sync_ended_on_init_, diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index 989d2ab..41d2687 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -46,8 +46,6 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { SyncBackendHostForProfileSyncTest( Profile* profile, const base::WeakPtr<SyncPrefs>& sync_prefs, - const base::WeakPtr<invalidation::InvalidatorStorage>& - invalidator_storage, syncer::TestIdFactory& id_factory, base::Closure& callback, bool set_initial_sync_ended_on_init, @@ -81,10 +79,6 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { static void SetHistoryServiceExpectations(ProfileMock* profile); - void EmitOnInvalidatorStateChange(syncer::InvalidatorState state); - void EmitOnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map); - protected: virtual void InitCore(const DoInitializeOptions& options) OVERRIDE; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 77a838e..e289d69 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -909,7 +909,9 @@ 'browser/internal_auth.h', 'browser/intranet_redirect_detector.cc', 'browser/intranet_redirect_detector.h', - 'browser/invalidation/invalidation_frontend.h', + 'browser/invalidation/fake_invalidation_service.cc', + 'browser/invalidation/fake_invalidation_service.h', + 'browser/invalidation/invalidation_service.h', 'browser/invalidation/invalidation_service_android.cc', 'browser/invalidation/invalidation_service_android.h', 'browser/invalidation/invalidation_service_factory.cc', @@ -1991,10 +1993,6 @@ 'browser/sync/backend_migrator.h', 'browser/sync/backend_unrecoverable_error_handler.cc', 'browser/sync/backend_unrecoverable_error_handler.h', - 'browser/sync/glue/android_invalidator_bridge.cc', - 'browser/sync/glue/android_invalidator_bridge.h', - 'browser/sync/glue/android_invalidator_bridge_proxy.cc', - 'browser/sync/glue/android_invalidator_bridge_proxy.h', 'browser/sync/glue/autofill_data_type_controller.cc', 'browser/sync/glue/autofill_data_type_controller.h', 'browser/sync/glue/autofill_profile_data_type_controller.cc', @@ -2029,8 +2027,6 @@ 'browser/sync/glue/data_type_manager_observer.h', 'browser/sync/glue/device_info.cc', 'browser/sync/glue/device_info.h', - 'browser/sync/glue/dummy_invalidator.cc', - 'browser/sync/glue/dummy_invalidator.h', 'browser/sync/glue/extension_data_type_controller.cc', 'browser/sync/glue/extension_data_type_controller.h', 'browser/sync/glue/extension_setting_data_type_controller.cc', @@ -2120,6 +2116,7 @@ 'browser/sync/profile_sync_service_harness.cc', 'browser/sync/profile_sync_service_harness.h', 'browser/sync/profile_sync_service_model_type_selection_android.h', + 'browser/sync/profile_sync_service_observer.cc', 'browser/sync/profile_sync_service_observer.h', 'browser/sync/retry_verifier.cc', 'browser/sync/retry_verifier.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 0aacc8e..fad061b 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -937,9 +937,9 @@ 'browser/importer/safari_importer_unittest.mm', 'browser/importer/toolbar_importer_unittest.cc', 'browser/internal_auth_unittest.cc', - 'browser/invalidation/invalidation_frontend_test_template.cc', - 'browser/invalidation/invalidation_frontend_test_template.h', 'browser/invalidation/invalidation_service_android_unittest.cc', + 'browser/invalidation/invalidation_service_test_template.cc', + 'browser/invalidation/invalidation_service_test_template.h', 'browser/invalidation/invalidator_storage_unittest.cc', 'browser/invalidation/ticl_invalidation_service_unittest.cc', 'browser/language_usage_metrics_unittest.cc', @@ -1199,8 +1199,6 @@ 'browser/sync/abstract_profile_sync_service_test.cc', 'browser/sync/abstract_profile_sync_service_test.h', 'browser/sync/backend_migrator_unittest.cc', - 'browser/sync/glue/android_invalidator_bridge_proxy_unittest.cc', - 'browser/sync/glue/android_invalidator_bridge_unittest.cc', 'browser/sync/glue/autofill_data_type_controller_unittest.cc', 'browser/sync/glue/bookmark_data_type_controller_unittest.cc', 'browser/sync/glue/browser_thread_model_worker_unittest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 3533889..c83bf76 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1337,9 +1337,6 @@ const char kSyncKeystoreEncryption[] = "sync-keystore-encryption"; const char kSyncShortInitialRetryOverride[] = "sync-short-initial-retry-override"; -// Overrides the default notification method for sync. -const char kSyncNotificationMethod[] = "sync-notification-method"; - // Overrides the default host:port used for sync notifications. const char kSyncNotificationHostPort[] = "sync-notification-host-port"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index d6ab6ac..fde899e 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -354,7 +354,6 @@ extern const char kSyncAllowInsecureXmppConnection[]; extern const char kSyncInvalidateXmppLogin[]; extern const char kSyncKeystoreEncryption[]; extern const char kSyncShortInitialRetryOverride[]; -extern const char kSyncNotificationMethod[]; extern const char kSyncNotificationHostPort[]; extern const char kSyncServiceURL[]; extern const char kSyncTabFavicons[]; diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h index b3f03b0..bc6a137 100644 --- a/sync/internal_api/public/sync_manager.h +++ b/sync/internal_api/public/sync_manager.h @@ -23,7 +23,7 @@ #include "sync/internal_api/public/sync_encryption_handler.h" #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" #include "sync/internal_api/public/util/weak_handle.h" -#include "sync/notifier/invalidation_util.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/protocol/sync_protocol_error.h" namespace sync_pb { @@ -39,8 +39,6 @@ struct Experiments; class ExtensionsActivityMonitor; class HttpPostProviderFactory; class InternalComponentsFactory; -class InvalidationHandler; -class Invalidator; class JsBackend; class JsEventHandler; class SyncEncryptionHandler; @@ -75,7 +73,7 @@ struct SyncCredentials { // // Unless stated otherwise, all methods of SyncManager should be called on the // same thread. -class SYNC_EXPORT SyncManager { +class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { public: // An interface the embedding application implements to be notified // on change events. Note that these methods may be called on *any* @@ -315,7 +313,6 @@ class SYNC_EXPORT SyncManager { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -344,27 +341,6 @@ class SYNC_EXPORT SyncManager { // Update tokens that we're using in Sync. Email must stay the same. virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; - // Called when the user disables or enables a sync type. - virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) = 0; - - // Forwards to the underlying invalidator (see comments in invalidator.h). - virtual void RegisterInvalidationHandler( - InvalidationHandler* handler) = 0; - - // Forwards to the underlying notifier (see comments in invalidator.h). - virtual void UpdateRegisteredInvalidationIds( - InvalidationHandler* handler, - const ObjectIdSet& ids) = 0; - - // Forwards to the underlying notifier (see comments in invalidator.h). - virtual void UnregisterInvalidationHandler( - InvalidationHandler* handler) = 0; - - // Forwards to the underlying notifier (see comments in invalidator.h). - virtual void AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) = 0; - // Put the syncer in normal mode ready to perform nudges and polls. virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) = 0; @@ -392,6 +368,13 @@ class SYNC_EXPORT SyncManager { const base::Closure& ready_task, const base::Closure& retry_task) = 0; + // Inform the syncer of a change in the invalidator's state. + virtual void OnInvalidatorStateChange(InvalidatorState state) = 0; + + // Inform the syncer that its cached information about a type is obsolete. + virtual void OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) = 0; + // Adds a listener to be notified of sync events. // NOTE: It is OK (in fact, it's probably a good idea) to call this before // having received OnInitializationCompleted. diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h index ba38ac6..ed69a52 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -62,10 +62,11 @@ class FakeSyncManager : public SyncManager { ConfigureReason GetAndResetConfigureReason(); // Posts a method to invalidate the given IDs on the sync thread. - void Invalidate(const ObjectIdInvalidationMap& invalidation_map); + virtual void OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // Posts a method to update the invalidator state on the sync thread. - void UpdateInvalidatorState(InvalidatorState state); + virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; // Block until the sync thread has finished processing any pending messages. void WaitForSyncThread(); @@ -84,7 +85,6 @@ class FakeSyncManager : public SyncManager { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -100,17 +100,6 @@ class FakeSyncManager : public SyncManager { ModelTypeSet types) OVERRIDE; virtual bool PurgePartiallySyncedTypes() OVERRIDE; virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; - virtual void UpdateEnabledTypes(ModelTypeSet types) OVERRIDE; - virtual void RegisterInvalidationHandler( - InvalidationHandler* handler) OVERRIDE; - virtual void UpdateRegisteredInvalidationIds( - InvalidationHandler* handler, - const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterInvalidationHandler( - InvalidationHandler* handler) OVERRIDE; - virtual void AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -136,10 +125,6 @@ class FakeSyncManager : public SyncManager { virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; private: - void InvalidateOnSyncThread( - const ObjectIdInvalidationMap& invalidation_map); - void UpdateInvalidatorStateOnSyncThread(InvalidatorState state); - scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; ObserverList<SyncManager::Observer> observers_; diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index 68f68f8..7b0e549 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -349,7 +349,6 @@ void SyncManagerImpl::Init( ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -369,9 +368,6 @@ void SyncManagerImpl::Init( change_delegate_ = change_delegate; - invalidator_ = invalidator.Pass(); - invalidator_->RegisterHandler(this); - AddObserver(&js_sync_manager_observer_); SetJsEventHandler(event_handler); @@ -609,49 +605,11 @@ void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { if (!connection_manager_->SetAuthToken(credentials.sync_token)) return; // Auth token is known to be invalid, so exit early. - invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); scheduler_->OnCredentialsUpdated(); // TODO(zea): pass the credential age to the debug info event listener. } -void SyncManagerImpl::UpdateEnabledTypes(ModelTypeSet enabled_types) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(initialized_); - invalidator_->UpdateRegisteredIds( - this, - ModelTypeSetToObjectIdSet(enabled_types)); -} - -void SyncManagerImpl::RegisterInvalidationHandler( - InvalidationHandler* handler) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(initialized_); - invalidator_->RegisterHandler(handler); -} - -void SyncManagerImpl::UpdateRegisteredInvalidationIds( - InvalidationHandler* handler, - const ObjectIdSet& ids) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(initialized_); - invalidator_->UpdateRegisteredIds(handler, ids); -} - -void SyncManagerImpl::UnregisterInvalidationHandler( - InvalidationHandler* handler) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(initialized_); - invalidator_->UnregisterHandler(handler); -} - -void SyncManagerImpl::AcknowledgeInvalidation( - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(initialized_); - invalidator_->Acknowledge(id, ack_handle); -} - void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { DCHECK(thread_checker_.CalledOnValidThread()); observers_.AddObserver(observer); @@ -690,15 +648,10 @@ void SyncManagerImpl::ShutdownOnSyncThread() { RemoveObserver(&debug_info_event_listener_); - // |invalidator_| and |connection_manager_| may end up being NULL here in - // tests (in synchronous initialization mode). + // |connection_manager_| may end up being NULL here in tests (in synchronous + // initialization mode). // // TODO(akalin): Fix this behavior. - - if (invalidator_) - invalidator_->UnregisterHandler(this); - invalidator_.reset(); - if (connection_manager_) connection_manager_->RemoveListener(this); connection_manager_.reset(); @@ -988,20 +941,6 @@ void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { DVLOG(1) << "Sending OnSyncCycleCompleted"; FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnSyncCycleCompleted(event.snapshot)); - - // This is here for tests, which are still using p2p notifications. - bool is_notifiable_commit = - (event.snapshot.model_neutral_state().num_successful_commits > 0); - if (is_notifiable_commit) { - if (invalidator_) { - const ObjectIdInvalidationMap& invalidation_map = - ModelTypeInvalidationMapToObjectIdInvalidationMap( - event.snapshot.source().types); - invalidator_->SendInvalidation(invalidation_map); - } else { - DVLOG(1) << "Not sending invalidation: invalidator_ is NULL"; - } - } } if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { @@ -1224,6 +1163,8 @@ void SyncManagerImpl::UpdateNotificationInfo( } void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { + DCHECK(thread_checker_.CalledOnValidThread()); + const std::string& state_str = InvalidatorStateToString(state); invalidator_state_ = state; DVLOG(1) << "Invalidator state changed to: " << state_str; @@ -1232,12 +1173,6 @@ void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { allstatus_.SetNotificationsEnabled(notifications_enabled); scheduler_->SetNotificationsEnabled(notifications_enabled); - if (invalidator_state_ == syncer::INVALIDATION_CREDENTIALS_REJECTED) { - // If the invalidator's credentials were rejected, that means that - // our sync credentials are also bad, so invalidate those. - connection_manager_->OnInvalidationCredentialsRejected(); - } - if (js_event_handler_.IsInitialized()) { base::DictionaryValue details; details.SetString("state", state_str); @@ -1252,15 +1187,6 @@ void SyncManagerImpl::OnIncomingInvalidation( const ObjectIdInvalidationMap& invalidation_map) { DCHECK(thread_checker_.CalledOnValidThread()); - // TODO(dcheng): Acknowledge immediately for now. Fix this once the - // invalidator doesn't repeatedly ping for unacknowledged invaliations, since - // it conflicts with the sync scheduler's internal backoff algorithm. - // See http://crbug.com/124149 for more information. - for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); - it != invalidation_map.end(); ++it) { - invalidator_->Acknowledge(it->first, it->second.ack_handle); - } - const ModelTypeInvalidationMap& type_invalidation_map = ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); if (type_invalidation_map.empty()) { diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index c12eea7..153df81 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -51,7 +51,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : public SyncManager, public net::NetworkChangeNotifier::IPAddressObserver, public net::NetworkChangeNotifier::ConnectionTypeObserver, - public InvalidationHandler, public JsBackend, public SyncEngineEventListener, public ServerConnectionEventListener, @@ -74,7 +73,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -90,17 +88,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : ModelTypeSet types) OVERRIDE; virtual bool PurgePartiallySyncedTypes() OVERRIDE; virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; - virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) OVERRIDE; - virtual void RegisterInvalidationHandler( - InvalidationHandler* handler) OVERRIDE; - virtual void UpdateRegisteredInvalidationIds( - InvalidationHandler* handler, - const ObjectIdSet& ids) OVERRIDE; - virtual void UnregisterInvalidationHandler( - InvalidationHandler* handler) OVERRIDE; - virtual void AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -112,6 +99,9 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : const ModelSafeRoutingInfo& new_routing_info, const base::Closure& ready_task, const base::Closure& retry_task) OVERRIDE; + virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; + virtual void OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; virtual SyncStatus GetDetailedStatus() const OVERRIDE; @@ -177,11 +167,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : syncable::BaseTransaction* trans, std::vector<int64>* entries_changed) OVERRIDE; - // InvalidationHandler implementation. - virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; - virtual void OnIncomingInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; - // Handle explicit requests to fetch updates for the given types. virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; @@ -336,9 +321,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : // Start()ed. scoped_ptr<SyncScheduler> scheduler_; - // 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. AllStatus allstatus_; diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index a1ddd7f..2085ec3 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -46,7 +46,6 @@ #include "sync/js/js_reply_handler.h" #include "sync/js/js_test_util.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" @@ -789,14 +788,12 @@ class SyncManagerTest : public testing::Test, }; SyncManagerTest() - : fake_invalidator_(NULL), - sync_manager_("Test sync manager") { + : sync_manager_("Test sync manager") { switches_.encryption_method = InternalComponentsFactory::ENCRYPTION_KEYSTORE; } virtual ~SyncManagerTest() { - EXPECT_FALSE(fake_invalidator_); } // Test implementation. @@ -807,8 +804,6 @@ class SyncManagerTest : public testing::Test, credentials.email = "foo@bar.com"; credentials.sync_token = "sometoken"; - fake_invalidator_ = new FakeInvalidator(); - sync_manager_.AddObserver(&manager_observer_); EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). WillOnce(SaveArg<0>(&js_backend_)); @@ -831,7 +826,6 @@ class SyncManagerTest : public testing::Test, &extensions_activity_monitor_, this, credentials, - scoped_ptr<Invalidator>(fake_invalidator_), "fake_invalidator_client_id", std::string(), std::string(), // bootstrap tokens @@ -851,17 +845,11 @@ class SyncManagerTest : public testing::Test, sync_manager_.GetUserShare(), i->first); } PumpLoop(); - - 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_invalidator_| anymore because |fake_invalidator_| is now - // destroyed. - fake_invalidator_ = NULL; PumpLoop(); } @@ -1027,7 +1015,6 @@ class SyncManagerTest : public testing::Test, protected: FakeEncryptor encryptor_; TestUnrecoverableErrorHandler handler_; - FakeInvalidator* fake_invalidator_; SyncManagerImpl sync_manager_; WeakHandle<JsBackend> js_backend_; StrictMock<SyncManagerObserverMock> manager_observer_; @@ -1035,29 +1022,6 @@ class SyncManagerTest : public testing::Test, InternalComponentsFactory::Switches switches_; }; -TEST_F(SyncManagerTest, UpdateEnabledTypes) { - ModelSafeRoutingInfo routes; - GetModelSafeRoutingInfo(&routes); - const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); - sync_manager_.UpdateEnabledTypes(enabled_types); - EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), - fake_invalidator_->GetRegisteredIds(&sync_manager_)); -} - -TEST_F(SyncManagerTest, RegisterInvalidationHandler) { - 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_handler, ids); - EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler)); - - sync_manager_.UnregisterInvalidationHandler(&fake_handler); - EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); -} - TEST_F(SyncManagerTest, ProcessJsMessage) { const JsArgList kNoArgs; @@ -1362,14 +1326,6 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) { base::DictionaryValue auth_error_details; auth_error_details.SetString("status", "CONNECTION_AUTH_ERROR"); - EXPECT_CALL(manager_observer_, - OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); - - EXPECT_CALL( - event_handler, - HandleJsEvent("onConnectionStatusChange", - HasDetailsAsDictionary(auth_error_details))); - EXPECT_CALL(event_handler, HandleJsEvent("onNotificationStateChange", HasDetailsAsDictionary(enabled_details))); @@ -1410,22 +1366,6 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) { PumpLoop(); } -// Simulate the invalidator's credentials being rejected. That should -// also clear the sync token. -TEST_F(SyncManagerTest, OnInvalidatorStateChangeCredentialsRejected) { - EXPECT_CALL(manager_observer_, - OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); - - EXPECT_FALSE(sync_manager_.GetHasInvalidAuthTokenForTest()); - - SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED); - - EXPECT_TRUE(sync_manager_.GetHasInvalidAuthTokenForTest()); - - // Should trigger the replies. - PumpLoop(); -} - TEST_F(SyncManagerTest, OnIncomingNotification) { StrictMock<MockJsEventHandler> event_handler; diff --git a/sync/internal_api/test/fake_sync_manager.cc b/sync/internal_api/test/fake_sync_manager.cc index 3a9beca..7a6d6a4 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -61,25 +61,6 @@ ConfigureReason FakeSyncManager::GetAndResetConfigureReason() { return reason; } -void FakeSyncManager::Invalidate( - const ObjectIdInvalidationMap& invalidation_map) { - if (!sync_task_runner_->PostTask( - FROM_HERE, - base::Bind(&FakeSyncManager::InvalidateOnSyncThread, - base::Unretained(this), invalidation_map))) { - NOTREACHED(); - } -} - -void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { - if (!sync_task_runner_->PostTask( - FROM_HERE, - base::Bind(&FakeSyncManager::UpdateInvalidatorStateOnSyncThread, - base::Unretained(this), state))) { - NOTREACHED(); - } -} - void FakeSyncManager::WaitForSyncThread() { // Post a task to |sync_task_runner_| and block until it runs. base::RunLoop run_loop; @@ -103,7 +84,6 @@ void FakeSyncManager::Init( ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, - scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -161,31 +141,6 @@ void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { NOTIMPLEMENTED(); } -void FakeSyncManager::UpdateEnabledTypes(ModelTypeSet types) { - enabled_types_ = types; -} - -void FakeSyncManager::RegisterInvalidationHandler( - InvalidationHandler* handler) { - registrar_.RegisterHandler(handler); -} - -void FakeSyncManager::UpdateRegisteredInvalidationIds( - InvalidationHandler* handler, - const ObjectIdSet& ids) { - registrar_.UpdateRegisteredIds(handler, ids); -} - -void FakeSyncManager::UnregisterInvalidationHandler( - InvalidationHandler* handler) { - registrar_.UnregisterHandler(handler); -} - -void FakeSyncManager::AcknowledgeInvalidation(const invalidation::ObjectId& id, - const AckHandle& ack_handle) { - // Do nothing. -} - void FakeSyncManager::StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) { // Do nothing. @@ -201,7 +156,7 @@ void FakeSyncManager::ConfigureSyncer( const base::Closure& ready_task, const base::Closure& retry_task) { last_configure_reason_ = reason; - ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); + enabled_types_ = GetRoutingInfoTypes(new_routing_info); ModelTypeSet success_types = to_download; success_types.RemoveAll(configure_fail_types_); @@ -291,20 +246,17 @@ void FakeSyncManager::RefreshTypes(ModelTypeSet types) { last_refresh_request_types_ = types; } -void FakeSyncManager::InvalidateOnSyncThread( - const ObjectIdInvalidationMap& invalidation_map) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - registrar_.DispatchInvalidationsToHandlers(invalidation_map); -} - -void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( - InvalidatorState state) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - registrar_.UpdateInvalidatorState(state); +void FakeSyncManager::OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) { + // Do nothing. } ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { return last_refresh_request_types_; } +void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { + // Do nothing. +} + } // namespace syncer diff --git a/sync/notifier/fake_invalidator.cc b/sync/notifier/fake_invalidator.cc index 088d239..0b217f7 100644 --- a/sync/notifier/fake_invalidator.cc +++ b/sync/notifier/fake_invalidator.cc @@ -27,11 +27,6 @@ const std::string& FakeInvalidator::GetCredentialsToken() const { return token_; } -const ObjectIdInvalidationMap& -FakeInvalidator::GetLastSentInvalidationMap() const { - return last_sent_invalidation_map_; -} - void FakeInvalidator::EmitOnInvalidatorStateChange(InvalidatorState state) { registrar_.UpdateInvalidatorState(state); } @@ -69,9 +64,4 @@ void FakeInvalidator::UpdateCredentials( token_ = token; } -void FakeInvalidator::SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) { - last_sent_invalidation_map_ = invalidation_map; -} - } // namespace syncer diff --git a/sync/notifier/fake_invalidator.h b/sync/notifier/fake_invalidator.h index 87380d0..7913694 100644 --- a/sync/notifier/fake_invalidator.h +++ b/sync/notifier/fake_invalidator.h @@ -39,15 +39,12 @@ class FakeInvalidator : public Invalidator { virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; private: InvalidatorRegistrar registrar_; std::string state_; std::string email_; std::string token_; - ObjectIdInvalidationMap last_sent_invalidation_map_; }; } // namespace syncer diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index d097560..e3c79a4 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -79,12 +79,6 @@ void InvalidationNotifier::UpdateCredentials( invalidation_listener_.UpdateCredentials(email, token); } -void InvalidationNotifier::SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) { - DCHECK(CalledOnValidThread()); - // Do nothing. -} - void InvalidationNotifier::OnInvalidate( const ObjectIdInvalidationMap& invalidation_map) { DCHECK(CalledOnValidThread()); diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index 269511f..b7a98f8 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -62,8 +62,6 @@ class SYNC_EXPORT_PRIVATE InvalidationNotifier virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // SyncInvalidationListener::Delegate implementation. virtual void OnInvalidate( diff --git a/sync/notifier/invalidator.h b/sync/notifier/invalidator.h index a0f881e..ccb6922 100644 --- a/sync/notifier/invalidator.h +++ b/sync/notifier/invalidator.h @@ -83,13 +83,6 @@ class SYNC_EXPORT Invalidator { // once. virtual void UpdateCredentials( const std::string& email, const std::string& token) = 0; - - // This is here only to support the old p2p notification implementation, - // which is still used by sync integration tests. - // TODO(akalin): Remove this once we move the integration tests off p2p - // notifications. - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) = 0; }; } // namespace syncer diff --git a/sync/notifier/invalidator_factory.cc b/sync/notifier/invalidator_factory.cc deleted file mode 100644 index f359ce8..0000000 --- a/sync/notifier/invalidator_factory.cc +++ /dev/null @@ -1,107 +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/invalidator_factory.h" - -#include <string> - -#include "base/base64.h" -#include "base/logging.h" -#include "base/rand_util.h" -#include "jingle/notifier/listener/push_client.h" -#include "sync/notifier/invalidator.h" -#include "sync/notifier/non_blocking_invalidator.h" -#include "sync/notifier/p2p_invalidator.h" - -namespace syncer { -namespace { - -Invalidator* CreateDefaultInvalidator( - const notifier::NotifierOptions& notifier_options, - const std::string& invalidator_client_id, - const InvalidationStateMap& initial_invalidation_state_map, - const std::string& invalidation_bootstrap_data, - const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, - const std::string& client_info) { - if (notifier_options.notification_method == notifier::NOTIFICATION_P2P) { - // TODO(rlarocque): Ideally, the notification target would be - // 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 P2PInvalidator( - notifier::PushClient::CreateDefault(notifier_options), - invalidator_client_id, - NOTIFY_ALL); - } - - return new NonBlockingInvalidator( - notifier_options, invalidator_client_id, initial_invalidation_state_map, - invalidation_bootstrap_data, invalidation_state_tracker, client_info); -} - -std::string GenerateInvalidatorClientId() { - // Generate a GUID with 128 bits worth of base64-encoded randomness. - // This format is similar to that of sync's cache_guid. - const int kGuidBytes = 128 / 8; - std::string guid; - base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid); - return guid; -} - -} // namespace - -// TODO(akalin): Remove the dependency on jingle if OS_ANDROID is defined. -InvalidatorFactory::InvalidatorFactory( - const notifier::NotifierOptions& notifier_options, - const std::string& client_info, - const base::WeakPtr<InvalidationStateTracker>& - invalidation_state_tracker) - : notifier_options_(notifier_options), - client_info_(client_info) { - if (!invalidation_state_tracker.get()) { - return; - } - - // TODO(rlarocque): This is not the most obvious place for client ID - // generation code. We should try to find a better place for it when we - // refactor the invalidator into its own service. - if (invalidation_state_tracker->GetInvalidatorClientId().empty()) { - // This also clears any existing state. We can't reuse old invalidator - // state with the new ID anyway. - invalidation_state_tracker->SetInvalidatorClientId( - GenerateInvalidatorClientId()); - } - - initial_invalidation_state_map_ = - invalidation_state_tracker->GetAllInvalidationStates(); - invalidator_client_id_ = - invalidation_state_tracker->GetInvalidatorClientId(); - invalidation_bootstrap_data_ = invalidation_state_tracker->GetBootstrapData(); - invalidation_state_tracker_ = WeakHandle<InvalidationStateTracker>( - invalidation_state_tracker); -} - -InvalidatorFactory::~InvalidatorFactory() { -} - -Invalidator* InvalidatorFactory::CreateInvalidator() { -#if defined(OS_ANDROID) - // Android uses AndroidInvalidatorBridge instead. See SyncManager - // initialization code in SyncBackendHost for more information. - return NULL; -#else - return CreateDefaultInvalidator(notifier_options_, - invalidator_client_id_, - initial_invalidation_state_map_, - invalidation_bootstrap_data_, - invalidation_state_tracker_, - client_info_); -#endif -} - -std::string InvalidatorFactory::GetInvalidatorClientId() const { - return invalidator_client_id_; -} - -} // namespace syncer diff --git a/sync/notifier/invalidator_factory.h b/sync/notifier/invalidator_factory.h deleted file mode 100644 index 782850e..0000000 --- a/sync/notifier/invalidator_factory.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 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 SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ -#define SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ - -#include <string> - -#include "base/memory/weak_ptr.h" -#include "jingle/notifier/base/notifier_options.h" -#include "sync/base/sync_export.h" -#include "sync/internal_api/public/util/weak_handle.h" -#include "sync/notifier/invalidation_state_tracker.h" - -namespace syncer { - -class Invalidator; - -// Class to instantiate various implementations of the Invalidator -// interface. -class SYNC_EXPORT InvalidatorFactory { - public: - // |client_info| is a string identifying the client, e.g. a user - // agent string. |invalidation_state_tracker| may be NULL (for - // tests). - InvalidatorFactory( - const notifier::NotifierOptions& notifier_options, - const std::string& client_info, - const base::WeakPtr<InvalidationStateTracker>& - invalidation_state_tracker); - ~InvalidatorFactory(); - - // 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. - Invalidator* CreateInvalidator(); - - // Returns the unique ID that was (or will be) passed to the invalidator. - std::string GetInvalidatorClientId() const; - - private: - const notifier::NotifierOptions notifier_options_; - - // Some of these should be const, but can't be set up in member initializers. - InvalidationStateMap initial_invalidation_state_map_; - const std::string client_info_; - std::string invalidator_client_id_; - std::string invalidation_bootstrap_data_; - WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; -}; - -} // namespace syncer - -#endif // SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ diff --git a/sync/notifier/invalidator_factory_unittest.cc b/sync/notifier/invalidator_factory_unittest.cc deleted file mode 100644 index 31b95fc..0000000 --- a/sync/notifier/invalidator_factory_unittest.cc +++ /dev/null @@ -1,85 +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/invalidator_factory.h" - -#include "base/command_line.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop.h" -#include "base/threading/thread.h" -#include "jingle/notifier/base/notification_method.h" -#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_invalidation_handler.h" -#include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/invalidator.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { -namespace { - -class InvalidatorFactoryTest : public testing::Test { - protected: - - virtual void SetUp() OVERRIDE { - notifier_options_.request_context_getter = - new net::TestURLRequestContextGetter( - message_loop_.message_loop_proxy()); - } - - virtual void TearDown() OVERRIDE { - message_loop_.RunUntilIdle(); - EXPECT_EQ(0, fake_handler_.GetInvalidationCount()); - } - - base::MessageLoop message_loop_; - FakeInvalidationHandler fake_handler_; - notifier::NotifierOptions notifier_options_; - scoped_ptr<InvalidatorFactory> factory_; -}; - -// Test basic creation of a NonBlockingInvalidationNotifier. -TEST_F(InvalidatorFactoryTest, Basic) { - notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; - InvalidatorFactory factory( - notifier_options_, - "test client info", - base::WeakPtr<InvalidationStateTracker>()); - scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); -#if defined(OS_ANDROID) - ASSERT_FALSE(invalidator.get()); -#else - ASSERT_TRUE(invalidator.get()); - ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); - invalidator->RegisterHandler(&fake_handler_); - invalidator->UpdateRegisteredIds(&fake_handler_, ids); - invalidator->UnregisterHandler(&fake_handler_); -#endif -} - -// Test basic creation of a P2PNotifier. -TEST_F(InvalidatorFactoryTest, Basic_P2P) { - notifier_options_.notification_method = notifier::NOTIFICATION_P2P; - InvalidatorFactory factory( - notifier_options_, - "test client info", - base::WeakPtr<InvalidationStateTracker>()); - scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); -#if defined(OS_ANDROID) - ASSERT_FALSE(invalidator.get()); -#else - ASSERT_TRUE(invalidator.get()); - ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); - invalidator->RegisterHandler(&fake_handler_); - invalidator->UpdateRegisteredIds(&fake_handler_, ids); - invalidator->UnregisterHandler(&fake_handler_); -#endif -} - -} // namespace -} // namespace syncer diff --git a/sync/notifier/invalidator_registrar.cc b/sync/notifier/invalidator_registrar.cc index 75db11fc..c2a18f9 100644 --- a/sync/notifier/invalidator_registrar.cc +++ b/sync/notifier/invalidator_registrar.cc @@ -119,7 +119,8 @@ void InvalidatorRegistrar::DispatchInvalidationsToHandlers( void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { DCHECK(thread_checker_.CalledOnValidThread()); - DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); + DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_) + << " -> " << InvalidatorStateToString(state); state_ = state; FOR_EACH_OBSERVER(InvalidationHandler, handlers_, OnInvalidatorStateChange(state)); diff --git a/sync/notifier/invalidator_registrar_unittest.cc b/sync/notifier/invalidator_registrar_unittest.cc index 070c134..ad22247 100644 --- a/sync/notifier/invalidator_registrar_unittest.cc +++ b/sync/notifier/invalidator_registrar_unittest.cc @@ -57,11 +57,6 @@ class RegistrarInvalidator : public Invalidator { // Do nothing. } - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE { - // Do nothing. - } - private: InvalidatorRegistrar registrar_; diff --git a/sync/notifier/non_blocking_invalidator.cc b/sync/notifier/non_blocking_invalidator.cc index 99b5532..2834f28 100644 --- a/sync/notifier/non_blocking_invalidator.cc +++ b/sync/notifier/non_blocking_invalidator.cc @@ -227,13 +227,6 @@ void NonBlockingInvalidator::UpdateCredentials(const std::string& email, } } -void NonBlockingInvalidator::SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) { - DCHECK(parent_task_runner_->BelongsToCurrentThread()); - // InvalidationNotifier doesn't implement SendInvalidation(), so no - // need to forward on the call. -} - void NonBlockingInvalidator::OnInvalidatorStateChange(InvalidatorState state) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.UpdateInvalidatorState(state); diff --git a/sync/notifier/non_blocking_invalidator.h b/sync/notifier/non_blocking_invalidator.h index 9c366fe..f2685c7 100644 --- a/sync/notifier/non_blocking_invalidator.h +++ b/sync/notifier/non_blocking_invalidator.h @@ -57,8 +57,6 @@ class SYNC_EXPORT_PRIVATE NonBlockingInvalidator virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // InvalidationHandler implementation. virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; diff --git a/sync/notifier/p2p_invalidator.h b/sync/notifier/p2p_invalidator.h index a56521e..515b27b 100644 --- a/sync/notifier/p2p_invalidator.h +++ b/sync/notifier/p2p_invalidator.h @@ -16,6 +16,8 @@ #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/threading/thread_checker.h" +#include "jingle/notifier/base/notifier_options.h" +#include "jingle/notifier/listener/push_client.h" #include "jingle/notifier/listener/push_client_observer.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/model_type.h" @@ -108,8 +110,6 @@ class SYNC_EXPORT_PRIVATE P2PInvalidator virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; - virtual void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // PushClientObserver implementation. virtual void OnNotificationsEnabled() OVERRIDE; @@ -118,6 +118,9 @@ class SYNC_EXPORT_PRIVATE P2PInvalidator virtual void OnIncomingNotification( const notifier::Notification& notification) OVERRIDE; + void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map); + void SendNotificationDataForTest( const P2PNotificationData& notification_data); diff --git a/sync/sync_notifier.gypi b/sync/sync_notifier.gypi index 18ef4b9..ba40772 100644 --- a/sync/sync_notifier.gypi +++ b/sync/sync_notifier.gypi @@ -28,8 +28,6 @@ 'notifier/invalidation_state_tracker.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', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index e2f7c9e..3202b74 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -327,9 +327,6 @@ 'include_dirs': [ '..', ], - 'sources': [ - 'notifier/invalidator_factory_unittest.cc', - ], 'conditions': [ ['OS != "android"', { 'sources': [ diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc index 6ce8bde..21a46fd 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -17,6 +17,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/message_loop.h" +#include "base/rand_util.h" #include "base/task_runner.h" #include "base/threading/thread.h" #include "jingle/notifier/base/notification_method.h" @@ -40,8 +41,7 @@ #include "sync/js/js_event_details.h" #include "sync/js/js_event_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/invalidator.h" -#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/non_blocking_invalidator.h" #include "sync/test/fake_encryptor.h" #include "sync/tools/null_invalidation_state_tracker.h" @@ -215,15 +215,14 @@ notifier::NotifierOptions ParseNotifierOptions( LOG_IF(INFO, notifier_options.allow_insecure_connection) << "Allowing insecure XMPP connections."; - if (command_line.HasSwitch(kNotificationMethodSwitch)) { - notifier_options.notification_method = - notifier::StringToNotificationMethod( - command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); - } - return notifier_options; } +void StubNetworkTimeUpdateCallback(const base::Time&, + const base::TimeDelta&, + const base::TimeDelta&) { +} + int SyncClientMain(int argc, char* argv[]) { #if defined(OS_MACOSX) base::mac::ScopedNSAutoreleasePool pool; @@ -250,7 +249,6 @@ int SyncClientMain(int argc, char* argv[]) { if (credentials.email.empty() || credentials.sync_token.empty()) { std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" "[--%s=host:port] [--%s] [--%s]\n" - "[--%s=(server|p2p)]\n\n" "Run chrome and set a breakpoint on\n" "syncer::SyncManagerImpl::UpdateCredentials() " "after logging into\n" @@ -258,8 +256,7 @@ int SyncClientMain(int argc, char* argv[]) { argv[0], kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, kXmppTrySslTcpFirstSwitch, - kXmppAllowInsecureConnectionSwitch, - kNotificationMethodSwitch); + kXmppAllowInsecureConnectionSwitch); return -1; } @@ -272,18 +269,49 @@ int SyncClientMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()); const notifier::NotifierOptions& notifier_options = ParseNotifierOptions(command_line, context_getter); - const char kClientInfo[] = "sync_listen_notifications"; + const char kClientInfo[] = "standalone_sync_client"; + std::string invalidator_id = base::RandBytesAsString(8); NullInvalidationStateTracker null_invalidation_state_tracker; - InvalidatorFactory invalidator_factory( - notifier_options, kClientInfo, - null_invalidation_state_tracker.AsWeakPtr()); + scoped_ptr<Invalidator> invalidator(new NonBlockingInvalidator( + notifier_options, + invalidator_id, + null_invalidation_state_tracker.GetAllInvalidationStates(), + null_invalidation_state_tracker.GetBootstrapData(), + WeakHandle<InvalidationStateTracker>( + null_invalidation_state_tracker.AsWeakPtr()), + kClientInfo)); // Set up database directory for the syncer. base::ScopedTempDir database_dir; CHECK(database_dir.CreateUniqueTempDir()); - // Set up model type parameters. - const ModelTypeSet model_types = ModelTypeSet::All(); + // Developers often add types to ModelTypeSet::All() before the server + // supports them. We need to be explicit about which types we want here. + ModelTypeSet model_types; + model_types.Put(BOOKMARKS); + model_types.Put(PREFERENCES); + model_types.Put(PASSWORDS); + model_types.Put(AUTOFILL); + model_types.Put(THEMES); + model_types.Put(TYPED_URLS); + model_types.Put(EXTENSIONS); + model_types.Put(NIGORI); + model_types.Put(SEARCH_ENGINES); + model_types.Put(SESSIONS); + model_types.Put(APPS); + model_types.Put(AUTOFILL_PROFILE); + model_types.Put(APP_SETTINGS); + model_types.Put(EXTENSION_SETTINGS); + model_types.Put(APP_NOTIFICATIONS); + model_types.Put(HISTORY_DELETE_DIRECTIVES); + model_types.Put(SYNCED_NOTIFICATIONS); + model_types.Put(DEVICE_INFO); + model_types.Put(EXPERIMENTS); + model_types.Put(PRIORITY_PREFERENCES); + model_types.Put(DICTIONARY); + model_types.Put(FAVICON_IMAGES); + model_types.Put(FAVICON_TRACKING); + ModelSafeRoutingInfo routing_info; for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { @@ -307,8 +335,10 @@ int SyncClientMain(int argc, char* argv[]) { const char kUserAgent[] = "sync_client"; // TODO(akalin): Replace this with just the context getter once // HttpPostProviderFactory is removed. - scoped_ptr<HttpPostProviderFactory> post_factory(new HttpBridgeFactory( - context_getter.get(), kUserAgent, NetworkTimeUpdateCallback())); + scoped_ptr<HttpPostProviderFactory> post_factory( + new HttpBridgeFactory(context_getter, + kUserAgent, + base::Bind(&StubNetworkTimeUpdateCallback))); // Used only when committing bookmarks, so it's okay to leave this // as NULL. ExtensionsActivityMonitor* extensions_activity_monitor = NULL; @@ -333,9 +363,7 @@ int SyncClientMain(int argc, char* argv[]) { extensions_activity_monitor, &change_delegate, credentials, - scoped_ptr<Invalidator>( - invalidator_factory.CreateInvalidator()), - invalidator_factory.GetInvalidatorClientId(), + invalidator_id, kRestoredKeyForBootstrapping, kRestoredKeystoreKeyForBootstrapping, scoped_ptr<InternalComponentsFactory>( @@ -345,7 +373,10 @@ int SyncClientMain(int argc, char* argv[]) { &LogUnrecoverableErrorContext, false); // TODO(akalin): Avoid passing in model parameters multiple times by // organizing handling of model types. - sync_manager->UpdateEnabledTypes(model_types); + invalidator->UpdateCredentials(credentials.email, credentials.sync_token); + invalidator->RegisterHandler(sync_manager.get()); + invalidator->UpdateRegisteredIds( + sync_manager.get(), ModelTypeSetToObjectIdSet(model_types)); sync_manager->StartSyncingNormally(routing_info); sync_loop.Run(); diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index dc54886..615d6bd 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -13,6 +13,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" +#include "base/rand_util.h" #include "base/threading/thread.h" #include "jingle/notifier/base/notification_method.h" #include "jingle/notifier/base/notifier_options.h" @@ -27,7 +28,7 @@ #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/invalidator.h" -#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/non_blocking_invalidator.h" #include "sync/tools/null_invalidation_state_tracker.h" #if defined(OS_MACOSX) @@ -134,12 +135,6 @@ notifier::NotifierOptions ParseNotifierOptions( LOG_IF(INFO, notifier_options.allow_insecure_connection) << "Allowing insecure XMPP connections."; - if (command_line.HasSwitch(kNotificationMethodSwitch)) { - notifier_options.notification_method = - notifier::StringToNotificationMethod( - command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); - } - return notifier_options; } @@ -169,15 +164,13 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { if (email.empty() || token.empty()) { std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" "[--%s=host:port] [--%s] [--%s]\n" - "[--%s=(server|p2p)]\n\n" "Run chrome and set a breakpoint on\n" "syncer::SyncManagerImpl::UpdateCredentials() " "after logging into\n" "sync to get the token to pass into this utility.\n", argv[0], kEmailSwitch, kTokenSwitch, kHostPortSwitch, - kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, - kNotificationMethodSwitch); + kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); return -1; } @@ -191,11 +184,16 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; - InvalidatorFactory invalidator_factory( - notifier_options, kClientInfo, - null_invalidation_state_tracker.AsWeakPtr()); scoped_ptr<Invalidator> invalidator( - invalidator_factory.CreateInvalidator()); + new NonBlockingInvalidator( + notifier_options, + base::RandBytesAsString(8), + null_invalidation_state_tracker.GetAllInvalidationStates(), + null_invalidation_state_tracker.GetBootstrapData(), + WeakHandle<InvalidationStateTracker>( + null_invalidation_state_tracker.AsWeakPtr()), + kClientInfo)); + NotificationPrinter notification_printer; invalidator->UpdateCredentials(email, token); diff --git a/sync/tools/testserver/xmppserver.py b/sync/tools/testserver/xmppserver.py index 0b32933..3f7c7d05 100644 --- a/sync/tools/testserver/xmppserver.py +++ b/sync/tools/testserver/xmppserver.py @@ -575,6 +575,14 @@ class XmppServer(asyncore.dispatcher): def SetAuthenticated(self, auth_valid): self._authenticated = auth_valid + # We check authentication only when establishing new connections. We close + # all existing connections here to make sure previously connected clients + # pick up on the change. It's a hack, but it works well enough for our + # purposes. + if not self._authenticated: + for connection in self._handshake_done_connections: + connection.close() + def GetAuthenticated(self): return self._authenticated |