summaryrefslogtreecommitdiffstats
path: root/sync/notifier
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 01:47:46 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 01:47:46 +0000
commit1691f004283eca700aa101b784bdec5a8c3b24cb (patch)
tree51686e63df183d4ea60fb38be4400db97fedbf18 /sync/notifier
parent9f9309fbb4f1ff34330a9ba3879011cad09f05e5 (diff)
downloadchromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.zip
chromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.tar.gz
chromium_src-1691f004283eca700aa101b784bdec5a8c3b24cb.tar.bz2
Revert 208315 "Make use of InvalidationService"
> 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 TBR=rlarocque@chromium.org Review URL: https://codereview.chromium.org/17610004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208347 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, 292 insertions, 7 deletions
diff --git a/sync/notifier/fake_invalidator.cc b/sync/notifier/fake_invalidator.cc
index 0b217f7..088d239 100644
--- a/sync/notifier/fake_invalidator.cc
+++ b/sync/notifier/fake_invalidator.cc
@@ -27,6 +27,11 @@ 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);
}
@@ -64,4 +69,9 @@ 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 7913694..87380d0 100644
--- a/sync/notifier/fake_invalidator.h
+++ b/sync/notifier/fake_invalidator.h
@@ -39,12 +39,15 @@ 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 e3c79a4..d097560 100644
--- a/sync/notifier/invalidation_notifier.cc
+++ b/sync/notifier/invalidation_notifier.cc
@@ -79,6 +79,12 @@ 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 b7a98f8..269511f 100644
--- a/sync/notifier/invalidation_notifier.h
+++ b/sync/notifier/invalidation_notifier.h
@@ -62,6 +62,8 @@ 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 ccb6922..a0f881e 100644
--- a/sync/notifier/invalidator.h
+++ b/sync/notifier/invalidator.h
@@ -83,6 +83,13 @@ 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
new file mode 100644
index 0000000..f359ce8
--- /dev/null
+++ b/sync/notifier/invalidator_factory.cc
@@ -0,0 +1,107 @@
+// 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
new file mode 100644
index 0000000..782850e
--- /dev/null
+++ b/sync/notifier/invalidator_factory.h
@@ -0,0 +1,55 @@
+// 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
new file mode 100644
index 0000000..31b95fc
--- /dev/null
+++ b/sync/notifier/invalidator_factory_unittest.cc
@@ -0,0 +1,85 @@
+// 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 c2a18f9..75db11fc 100644
--- a/sync/notifier/invalidator_registrar.cc
+++ b/sync/notifier/invalidator_registrar.cc
@@ -119,8 +119,7 @@ void InvalidatorRegistrar::DispatchInvalidationsToHandlers(
void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) {
DCHECK(thread_checker_.CalledOnValidThread());
- DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_)
- << " -> " << InvalidatorStateToString(state);
+ DVLOG(1) << "New invalidator 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 ad22247..070c134 100644
--- a/sync/notifier/invalidator_registrar_unittest.cc
+++ b/sync/notifier/invalidator_registrar_unittest.cc
@@ -57,6 +57,11 @@ 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 2834f28..99b5532 100644
--- a/sync/notifier/non_blocking_invalidator.cc
+++ b/sync/notifier/non_blocking_invalidator.cc
@@ -227,6 +227,13 @@ 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 f2685c7..9c366fe 100644
--- a/sync/notifier/non_blocking_invalidator.h
+++ b/sync/notifier/non_blocking_invalidator.h
@@ -57,6 +57,8 @@ 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 515b27b..a56521e 100644
--- a/sync/notifier/p2p_invalidator.h
+++ b/sync/notifier/p2p_invalidator.h
@@ -16,8 +16,6 @@
#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"
@@ -110,6 +108,8 @@ 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,9 +118,6 @@ 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);