diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/sync/notifier/server_notifier_thread.cc | 41 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/model_type.cc | 78 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/model_type.h | 13 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 |
4 files changed, 108 insertions, 25 deletions
diff --git a/chrome/browser/sync/notifier/server_notifier_thread.cc b/chrome/browser/sync/notifier/server_notifier_thread.cc index a6377b8..f52df43 100644 --- a/chrome/browser/sync/notifier/server_notifier_thread.cc +++ b/chrome/browser/sync/notifier/server_notifier_thread.cc @@ -12,6 +12,7 @@ #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/syncable/model_type.h" #include "chrome/common/net/notifier/listener/notification_defines.h" #include "google/cacheinvalidation/invalidation-client-impl.h" #include "talk/xmpp/jid.h" @@ -61,15 +62,13 @@ void ServerNotifierThread::Invalidate( DCHECK_EQ(MessageLoop::current(), worker_message_loop()); CHECK(invalidation::IsCallbackRepeatable(callback)); LOG(INFO) << "Invalidate: " << InvalidationToString(invalidation); - // Signal notification only for the invalidated types. + // TODO(akalin): Signal notification only for the invalidated types. parent_message_loop_->PostTask( FROM_HERE, NewRunnableMethod( this, &ServerNotifierThread::SignalIncomingNotification)); RunAndDeleteClosure(callback); - // A real implementation would respond to the invalidation for the - // given object (e.g., refetch the invalidated object). } void ServerNotifierThread::InvalidateAll( @@ -132,31 +131,23 @@ void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { void ServerNotifierThread::RegisterTypes() { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - // TODO(akalin): This is a giant hack! Make this configurable. Add - // a mapping to/from ModelType. - std::vector<std::string> data_types; - data_types.push_back("AUTOFILL"); - data_types.push_back("BOOKMARK"); - data_types.push_back("EXTENSION"); - data_types.push_back("PASSWORD"); - data_types.push_back("THEME"); - data_types.push_back("TYPED_URL"); - data_types.push_back("PREFERENCE"); - - std::vector<invalidation::ObjectId> object_ids; - - for (std::vector<std::string>::const_iterator it = data_types.begin(); - it != data_types.end(); ++it) { + // TODO(akalin): Make this configurable instead of listening to + // notifications for all possible types. + for (int i = syncable::FIRST_REAL_MODEL_TYPE; + i < syncable::MODEL_TYPE_COUNT; ++i) { + syncable::ModelType model_type = syncable::ModelTypeFromInt(i); + std::string notification_type; + if (!syncable::RealModelTypeToNotificationType( + model_type, ¬ification_type)) { + LOG(ERROR) << "Could not get notification type for model type " + << syncable::ModelTypeToString(model_type); + continue; + } invalidation::ObjectId object_id; - object_id.mutable_name()->set_string_value(*it); + object_id.mutable_name()->set_string_value(notification_type); object_id.set_source(invalidation::ObjectId::CHROME_SYNC); - object_ids.push_back(object_id); - } - - for (std::vector<invalidation::ObjectId>::const_iterator it = - object_ids.begin(); it != object_ids.end(); ++it) { chrome_invalidation_client_->Register( - *it, + object_id, invalidation::NewPermanentCallback( this, &ServerNotifierThread::RegisterCallback)); } diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc index f03373e..4c40498 100644 --- a/chrome/browser/sync/syncable/model_type.cc +++ b/chrome/browser/sync/syncable/model_type.cc @@ -132,4 +132,82 @@ std::string ModelTypeToString(ModelType model_type) { } } +// TODO(akalin): Figure out a better way to do these mappings. + +namespace { +const char kBookmarkNotificationType[] = "BOOKMARK"; +const char kPreferenceNotificationType[] = "PREFERENCE"; +const char kPasswordNotificationType[] = "PASSWORD"; +const char kAutofillNotificationType[] = "AUTOFILL"; +const char kThemeNotificationType[] = "THEME"; +const char kTypedUrlNotificationType[] = "TYPED_URL"; +const char kExtensionNotificationType[] = "EXTENSION"; +const char kNigoriNotificationType[] = "NIGORI"; +} // namespace + +bool RealModelTypeToNotificationType(ModelType model_type, + std::string* notification_type) { + switch (model_type) { + case BOOKMARKS: + *notification_type = kBookmarkNotificationType; + return true; + case PREFERENCES: + *notification_type = kPreferenceNotificationType; + return true; + case PASSWORDS: + *notification_type = kPasswordNotificationType; + return true; + case AUTOFILL: + *notification_type = kAutofillNotificationType; + return true; + case THEMES: + *notification_type = kThemeNotificationType; + return true; + case TYPED_URLS: + *notification_type = kTypedUrlNotificationType; + return true; + case EXTENSIONS: + *notification_type = kExtensionNotificationType; + return true; + case NIGORI: + *notification_type = kNigoriNotificationType; + return true; + default: + break; + } + notification_type->clear(); + return false; +} + +bool NotificationTypeToRealModelType(const std::string& notification_type, + ModelType* model_type) { + if (notification_type == kBookmarkNotificationType) { + *model_type = BOOKMARKS; + return true; + } else if (notification_type == kPreferenceNotificationType) { + *model_type = PREFERENCES; + return true; + } else if (notification_type == kPasswordNotificationType) { + *model_type = PASSWORDS; + return true; + } else if (notification_type == kAutofillNotificationType) { + *model_type = AUTOFILL; + return true; + } else if (notification_type == kThemeNotificationType) { + *model_type = THEMES; + return true; + } else if (notification_type == kTypedUrlNotificationType) { + *model_type = TYPED_URLS; + return true; + } else if (notification_type == kExtensionNotificationType) { + *model_type = EXTENSIONS; + return true; + } else if (notification_type == kNigoriNotificationType) { + *model_type = NIGORI; + return true; + } + *model_type = UNSPECIFIED; + return false; +} + } // namespace syncable diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h index 95d1d65..5c34fb8 100644 --- a/chrome/browser/sync/syncable/model_type.h +++ b/chrome/browser/sync/syncable/model_type.h @@ -86,6 +86,19 @@ ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); std::string ModelTypeToString(ModelType model_type); +// Convert a real model type to a notification type (used for +// subscribing to server-issued notifications). Returns true iff +// |model_type| was a real model type and |notification_type| was +// filled in. +bool RealModelTypeToNotificationType(ModelType model_type, + std::string* notification_type); + +// Converts a notification type to a real model type. Returns true +// iff |notification_type| was the notification type of a real model +// type and |model_type| was filled in. +bool NotificationTypeToRealModelType(const std::string& notification_type, + ModelType* model_type); + } // namespace syncable #endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 0c6726d..238db5c 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1093,6 +1093,7 @@ ], 'dependencies': [ 'notifier', + 'sync', '../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation', ], # This target exports a hard dependency because it depends on |