diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-25 00:29:32 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-25 00:29:32 +0000 |
commit | 389f566a8d88ba4849dc1c2179e00bf64b1d1b39 (patch) | |
tree | ad64c2dbf6b004f43fe3e8a0e7bd539f223a51f4 /chrome/browser/invalidation | |
parent | ccdcf4375d9a79dcea5d92692db30ae199ffff28 (diff) | |
download | chromium_src-389f566a8d88ba4849dc1c2179e00bf64b1d1b39.zip chromium_src-389f566a8d88ba4849dc1c2179e00bf64b1d1b39.tar.gz chromium_src-389f566a8d88ba4849dc1c2179e00bf64b1d1b39.tar.bz2 |
Make use of InvalidationService
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=sky,erg
BUG=124137
Review URL: https://chromiumcodereview.appspot.com/15580002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/invalidation')
13 files changed, 489 insertions, 159 deletions
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..4d724f5 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_TOKEN_AVAILABLE, - content::Source<TokenService>(token_service_)); - notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, content::Source<Profile>(profile_)); + notification_registrar_.Add(this, + chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, + content::Source<TokenService>(token_service_)); + notification_registrar_.Add(this, + 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); @@ -128,17 +171,16 @@ void TiclInvalidationService::Observe( DCHECK(CalledOnValidThread()); 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(); - } + case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { + 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,6 +357,8 @@ void TiclInvalidationService::StopInvalidator() { } void TiclInvalidationService::Logout() { + request_access_token_retry_timer_.Stop(); + StopInvalidator(); // This service always expects to have a valid invalidator storage. diff --git a/chrome/browser/invalidation/ticl_invalidation_service.h b/chrome/browser/invalidation/ticl_invalidation_service.h index dde6606..1f97f4a 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.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 |