summaryrefslogtreecommitdiffstats
path: root/sync/notifier
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-29 01:45:09 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-29 01:45:09 +0000
commitdbbec3a0133edaff11b16c6bc3fd73aac8ab4e31 (patch)
tree20b4a2df530ac7c83bcc5e7d460137e97846685e /sync/notifier
parentc146a323f91c8376afe55c93c6a31df0075be62b (diff)
downloadchromium_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
Diffstat (limited to 'sync/notifier')
-rw-r--r--sync/notifier/fake_invalidator.cc10
-rw-r--r--sync/notifier/fake_invalidator.h3
-rw-r--r--sync/notifier/invalidation_notifier.cc6
-rw-r--r--sync/notifier/invalidation_notifier.h2
-rw-r--r--sync/notifier/invalidator.h7
-rw-r--r--sync/notifier/invalidator_factory.cc107
-rw-r--r--sync/notifier/invalidator_factory.h55
-rw-r--r--sync/notifier/invalidator_factory_unittest.cc85
-rw-r--r--sync/notifier/invalidator_registrar.cc3
-rw-r--r--sync/notifier/invalidator_registrar_unittest.cc5
-rw-r--r--sync/notifier/non_blocking_invalidator.cc7
-rw-r--r--sync/notifier/non_blocking_invalidator.h2
-rw-r--r--sync/notifier/p2p_invalidator.h7
13 files changed, 7 insertions, 292 deletions
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);