diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 21:53:54 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 21:53:54 +0000 |
commit | 6a649b71db4df80493abfb125e0a71738d4d9d8a (patch) | |
tree | 81301fc6b88c992f9ec11d6096fb7c6e56829ab8 /chrome/browser/sync/tools | |
parent | 894c4e8a8146bfa89c66d4e4ab629d589fabd9ba (diff) | |
download | chromium_src-6a649b71db4df80493abfb125e0a71738d4d9d8a.zip chromium_src-6a649b71db4df80493abfb125e0a71738d4d9d8a.tar.gz chromium_src-6a649b71db4df80493abfb125e0a71738d4d9d8a.tar.bz2 |
Refactored ChromeInvalidationClient to have its own listener type.
BUG=34647
TEST=manual
Review URL: http://codereview.chromium.org/2817037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/tools')
-rw-r--r-- | chrome/browser/sync/tools/sync_listen_notifications.cc | 102 | ||||
-rw-r--r-- | chrome/browser/sync/tools/sync_tools.gyp | 1 |
2 files changed, 9 insertions, 94 deletions
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc index 5fa6759..7e5df7c 100644 --- a/chrome/browser/sync/tools/sync_listen_notifications.cc +++ b/chrome/browser/sync/tools/sync_listen_notifications.cc @@ -16,7 +16,6 @@ #include "chrome/browser/sync/notifier/cache_invalidation_packet_handler.h" #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" #include "chrome/browser/sync/notifier/chrome_system_resources.h" -#include "chrome/browser/sync/notifier/invalidation_util.h" #include "chrome/browser/sync/sync_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/notifier/base/task_pump.h" @@ -24,7 +23,6 @@ #include "chrome/common/net/notifier/listener/listen_task.h" #include "chrome/common/net/notifier/listener/notification_constants.h" #include "chrome/common/net/notifier/listener/subscribe_task.h" -#include "google/cacheinvalidation/invalidation-client.h" #include "talk/base/cryptstring.h" #include "talk/base/logging.h" #include "talk/base/sigslot.h" @@ -194,49 +192,23 @@ class LegacyNotifierDelegate : public XmppNotificationClient::Delegate { } }; -// The actual listener for sync notifications from the cache -// invalidation service. +// The actual listener for sync notifications. class ChromeInvalidationListener - : public invalidation::InvalidationListener { + : public sync_notifier::ChromeInvalidationClient::Listener { public: ChromeInvalidationListener() {} - virtual void Invalidate(const invalidation::Invalidation& invalidation, - invalidation::Closure* callback) { - CHECK(invalidation::IsCallbackRepeatable(callback)); - LOG(INFO) << "Invalidate: " - << sync_notifier::InvalidationToString(invalidation); - sync_notifier::RunAndDeleteClosure(callback); - // A real implementation would respond to the invalidation for the - // given object (e.g., refetch the invalidated object). + virtual void OnInvalidate(syncable::ModelType model_type) { + LOG(INFO) << "Invalidate: " << syncable::ModelTypeToString(model_type); + // A real implementation would respond to the invalidation. } - virtual void InvalidateAll(invalidation::Closure* callback) { - CHECK(invalidation::IsCallbackRepeatable(callback)); + virtual void OnInvalidateAll() { LOG(INFO) << "InvalidateAll"; - sync_notifier::RunAndDeleteClosure(callback); // A real implementation would loop over the current registered // data types and send notifications for those. } - virtual void AllRegistrationsLost(invalidation::Closure* callback) { - CHECK(invalidation::IsCallbackRepeatable(callback)); - LOG(INFO) << "AllRegistrationsLost"; - sync_notifier::RunAndDeleteClosure(callback); - // A real implementation would try to re-register for all - // registered data types. - } - - virtual void RegistrationLost(const invalidation::ObjectId& object_id, - invalidation::Closure* callback) { - CHECK(invalidation::IsCallbackRepeatable(callback)); - LOG(INFO) << "RegistrationLost: " - << sync_notifier::ObjectIdToString(object_id); - sync_notifier::RunAndDeleteClosure(callback); - // A real implementation would try to re-register for this - // particular data type. - } - private: DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationListener); }; @@ -245,20 +217,7 @@ class ChromeInvalidationListener class CacheInvalidationNotifierDelegate : public XmppNotificationClient::Delegate { public: - CacheInvalidationNotifierDelegate( - MessageLoop* message_loop, - const std::vector<std::string>& data_types) { - if (data_types.empty()) { - LOG(WARNING) << "No data types given"; - } - for (std::vector<std::string>::const_iterator it = data_types.begin(); - it != data_types.end(); ++it) { - invalidation::ObjectId object_id; - object_id.mutable_name()->set_string_value(*it); - object_id.set_source(invalidation::ObjectId::CHROME_SYNC); - object_ids_.push_back(object_id); - } - } + CacheInvalidationNotifierDelegate() {} virtual ~CacheInvalidationNotifierDelegate() {} @@ -272,53 +231,20 @@ class CacheInvalidationNotifierDelegate chrome_invalidation_client_.Start(kAppName, &chrome_invalidation_listener_, xmpp_client); - - for (std::vector<invalidation::ObjectId>::const_iterator it = - object_ids_.begin(); it != object_ids_.end(); ++it) { - chrome_invalidation_client_.Register( - *it, - invalidation::NewPermanentCallback( - this, &CacheInvalidationNotifierDelegate::RegisterCallback)); - } + chrome_invalidation_client_.RegisterTypes(); } virtual void OnLogout() { LOG(INFO) << "Logged out"; - - // TODO(akalin): Figure out the correct place to put this. - for (std::vector<invalidation::ObjectId>::const_iterator it = - object_ids_.begin(); it != object_ids_.end(); ++it) { - chrome_invalidation_client_.Unregister( - *it, - invalidation::NewPermanentCallback( - this, &CacheInvalidationNotifierDelegate::RegisterCallback)); - } - chrome_invalidation_client_.Stop(); } virtual void OnError(buzz::XmppEngine::Error error, int subcode) { LOG(INFO) << "Error: " << error << ", subcode: " << subcode; - - // TODO(akalin): Figure out whether we should unregister here, - // too. chrome_invalidation_client_.Stop(); } private: - void RegisterCallback( - const invalidation::RegistrationUpdateResult& result) { - LOG(INFO) << "Registered: " - << sync_notifier::RegistrationUpdateResultToString(result); - } - - void UnregisterCallback( - const invalidation::RegistrationUpdateResult& result) { - LOG(INFO) << "Unregistered: " - << sync_notifier::RegistrationUpdateResultToString(result); - } - - std::vector<invalidation::ObjectId> object_ids_; ChromeInvalidationListener chrome_invalidation_listener_; sync_notifier::ChromeInvalidationClient chrome_invalidation_client_; }; @@ -396,19 +322,9 @@ int main(int argc, char* argv[]) { talk_base::ThreadManager::SetCurrent(&main_thread); MessageLoopForIO message_loop; - // TODO(akalin): Make this configurable. - // TODO(akalin): Store these constants in a header somewhere (maybe - // browser/sync/protocol). - std::vector<std::string> data_types; - data_types.push_back("AUTOFILL"); - data_types.push_back("BOOKMARK"); - data_types.push_back("THEME"); - data_types.push_back("PREFERENCE"); - // Connect and listen. LegacyNotifierDelegate legacy_notifier_delegate; - CacheInvalidationNotifierDelegate cache_invalidation_notifier_delegate( - &message_loop, data_types); + CacheInvalidationNotifierDelegate cache_invalidation_notifier_delegate; XmppNotificationClient::Delegate* delegate = NULL; if (command_line.HasSwitch(switches::kSyncUseCacheInvalidation)) { delegate = &cache_invalidation_notifier_delegate; diff --git a/chrome/browser/sync/tools/sync_tools.gyp b/chrome/browser/sync/tools/sync_tools.gyp index a1140c08..124f116 100644 --- a/chrome/browser/sync/tools/sync_tools.gyp +++ b/chrome/browser/sync/tools/sync_tools.gyp @@ -23,7 +23,6 @@ '<(DEPTH)/chrome/chrome.gyp:common_constants', '<(DEPTH)/chrome/chrome.gyp:notifier', '<(DEPTH)/chrome/chrome.gyp:sync_notifier', - '<(DEPTH)/third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation', '<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle', ], }, |