[email protected] | 24c9ee5 | 2014-06-02 22:17:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 5 | #include "components/invalidation/p2p_invalidator.h" |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 6 | |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | c014f2b3 | 2013-09-03 23:29:12 | [diff] [blame] | 8 | #include <iterator> |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 9 | |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 10 | #include "base/json/json_reader.h" |
| 11 | #include "base/json/json_writer.h" |
[email protected] | c1c32c8 | 2012-03-15 09:35:42 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 13 | #include "base/values.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 14 | #include "components/invalidation/invalidation_handler.h" |
[email protected] | 51766bf | 2014-07-24 01:13:47 | [diff] [blame] | 15 | #include "components/invalidation/invalidation_util.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 16 | #include "components/invalidation/notifier_reason_util.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 17 | #include "components/invalidation/object_id_invalidation_map.h" |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 18 | #include "jingle/notifier/listener/push_client.h" |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 19 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 20 | namespace syncer { |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 21 | |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 22 | const char kSyncP2PNotificationChannel[] = "http://www.google.com/chrome/sync"; |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 23 | |
[email protected] | d6fdf68 | 2011-08-27 06:53:21 | [diff] [blame] | 24 | namespace { |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 25 | |
| 26 | const char kNotifySelf[] = "notifySelf"; |
| 27 | const char kNotifyOthers[] = "notifyOthers"; |
| 28 | const char kNotifyAll[] = "notifyAll"; |
| 29 | |
| 30 | const char kSenderIdKey[] = "senderId"; |
| 31 | const char kNotificationTypeKey[] = "notificationType"; |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 32 | const char kInvalidationsKey[] = "invalidations"; |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 33 | |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 34 | } // namespace |
| 35 | |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 36 | std::string P2PNotificationTargetToString(P2PNotificationTarget target) { |
| 37 | switch (target) { |
| 38 | case NOTIFY_SELF: |
| 39 | return kNotifySelf; |
| 40 | case NOTIFY_OTHERS: |
| 41 | return kNotifyOthers; |
| 42 | case NOTIFY_ALL: |
| 43 | return kNotifyAll; |
| 44 | default: |
| 45 | NOTREACHED(); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 46 | return std::string(); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | P2PNotificationTarget P2PNotificationTargetFromString( |
| 51 | const std::string& target_str) { |
| 52 | if (target_str == kNotifySelf) { |
| 53 | return NOTIFY_SELF; |
| 54 | } |
| 55 | if (target_str == kNotifyOthers) { |
| 56 | return NOTIFY_OTHERS; |
| 57 | } |
| 58 | if (target_str == kNotifyAll) { |
| 59 | return NOTIFY_ALL; |
| 60 | } |
| 61 | LOG(WARNING) << "Could not parse " << target_str; |
| 62 | return NOTIFY_SELF; |
| 63 | } |
| 64 | |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 65 | P2PNotificationData::P2PNotificationData() |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 66 | : target_(NOTIFY_SELF) {} |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 67 | |
| 68 | P2PNotificationData::P2PNotificationData( |
| 69 | const std::string& sender_id, |
| 70 | P2PNotificationTarget target, |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 71 | const ObjectIdInvalidationMap& invalidation_map) |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 72 | : sender_id_(sender_id), |
| 73 | target_(target), |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 74 | invalidation_map_(invalidation_map) {} |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 75 | |
| 76 | P2PNotificationData::~P2PNotificationData() {} |
| 77 | |
| 78 | bool P2PNotificationData::IsTargeted(const std::string& id) const { |
| 79 | switch (target_) { |
| 80 | case NOTIFY_SELF: |
| 81 | return sender_id_ == id; |
| 82 | case NOTIFY_OTHERS: |
| 83 | return sender_id_ != id; |
| 84 | case NOTIFY_ALL: |
| 85 | return true; |
| 86 | default: |
| 87 | NOTREACHED(); |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
[email protected] | 3e31fa4 | 2012-10-04 03:53:09 | [diff] [blame] | 92 | const ObjectIdInvalidationMap& |
| 93 | P2PNotificationData::GetIdInvalidationMap() const { |
| 94 | return invalidation_map_; |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 97 | bool P2PNotificationData::Equals(const P2PNotificationData& other) const { |
| 98 | return |
| 99 | (sender_id_ == other.sender_id_) && |
| 100 | (target_ == other.target_) && |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 101 | (invalidation_map_ == other.invalidation_map_); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | std::string P2PNotificationData::ToString() const { |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 105 | scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 106 | dict->SetString(kSenderIdKey, sender_id_); |
| 107 | dict->SetString(kNotificationTypeKey, |
| 108 | P2PNotificationTargetToString(target_)); |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 109 | dict->Set(kInvalidationsKey, invalidation_map_.ToValue().release()); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 110 | std::string json; |
[email protected] | 4abb460 | 2012-03-16 01:59:55 | [diff] [blame] | 111 | base::JSONWriter::Write(dict.get(), &json); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 112 | return json; |
| 113 | } |
| 114 | |
| 115 | bool P2PNotificationData::ResetFromString(const std::string& str) { |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 116 | scoped_ptr<base::Value> data_value(base::JSONReader::Read(str)); |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 117 | const base::DictionaryValue* data_dict = NULL; |
| 118 | if (!data_value.get() || !data_value->GetAsDictionary(&data_dict)) { |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 119 | LOG(WARNING) << "Could not parse " << str << " as a dictionary"; |
| 120 | return false; |
| 121 | } |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 122 | if (!data_dict->GetString(kSenderIdKey, &sender_id_)) { |
| 123 | LOG(WARNING) << "Could not find string value for " << kSenderIdKey; |
| 124 | } |
| 125 | std::string target_str; |
| 126 | if (!data_dict->GetString(kNotificationTypeKey, &target_str)) { |
| 127 | LOG(WARNING) << "Could not find string value for " |
| 128 | << kNotificationTypeKey; |
| 129 | } |
| 130 | target_ = P2PNotificationTargetFromString(target_str); |
[email protected] | 3e31fa4 | 2012-10-04 03:53:09 | [diff] [blame] | 131 | const base::ListValue* invalidation_map_list = NULL; |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 132 | if (!data_dict->GetList(kInvalidationsKey, &invalidation_map_list) || |
| 133 | !invalidation_map_.ResetFromValue(*invalidation_map_list)) { |
| 134 | LOG(WARNING) << "Could not parse " << kInvalidationsKey; |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 135 | } |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 136 | return true; |
| 137 | } |
| 138 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 139 | P2PInvalidator::P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 140 | const std::string& invalidator_client_id, |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 141 | P2PNotificationTarget send_notification_target) |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 142 | : push_client_(push_client.Pass()), |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 143 | invalidator_client_id_(invalidator_client_id), |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 144 | logged_in_(false), |
[email protected] | 09fb6e8 | 2011-04-07 00:08:14 | [diff] [blame] | 145 | notifications_enabled_(false), |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 146 | send_notification_target_(send_notification_target) { |
[email protected] | c7b7610da | 2011-09-30 01:49:16 | [diff] [blame] | 147 | DCHECK(send_notification_target_ == NOTIFY_OTHERS || |
| 148 | send_notification_target_ == NOTIFY_ALL); |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 149 | push_client_->AddObserver(this); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 152 | P2PInvalidator::~P2PInvalidator() { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 153 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 154 | push_client_->RemoveObserver(this); |
[email protected] | 09fb6e8 | 2011-04-07 00:08:14 | [diff] [blame] | 155 | } |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 156 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 157 | void P2PInvalidator::RegisterHandler(InvalidationHandler* handler) { |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 158 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 159 | registrar_.RegisterHandler(handler); |
| 160 | } |
| 161 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 162 | void P2PInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 163 | const ObjectIdSet& ids) { |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 164 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 165 | ObjectIdSet new_ids; |
| 166 | const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); |
| 167 | std::set_difference(ids.begin(), ids.end(), |
| 168 | old_ids.begin(), old_ids.end(), |
| 169 | std::inserter(new_ids, new_ids.end()), |
| 170 | ObjectIdLessThan()); |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 171 | registrar_.UpdateRegisteredIds(handler, ids); |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 172 | const P2PNotificationData notification_data( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 173 | invalidator_client_id_, |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 174 | send_notification_target_, |
| 175 | ObjectIdInvalidationMap::InvalidateAll(ids)); |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 176 | SendNotificationData(notification_data); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 179 | void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 180 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 | registrar_.UnregisterHandler(handler); |
| 182 | } |
| 183 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 184 | InvalidatorState P2PInvalidator::GetInvalidatorState() const { |
| 185 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 186 | return registrar_.GetInvalidatorState(); |
| 187 | } |
| 188 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 189 | void P2PInvalidator::UpdateCredentials( |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 190 | const std::string& email, const std::string& token) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 191 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | fc438686 | 2012-05-17 02:11:48 | [diff] [blame] | 192 | notifier::Subscription subscription; |
| 193 | subscription.channel = kSyncP2PNotificationChannel; |
| 194 | // There may be some subtle issues around case sensitivity of the |
| 195 | // from field, but it doesn't matter too much since this is only |
| 196 | // used in p2p mode (which is only used in testing). |
| 197 | subscription.from = email; |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 198 | push_client_->UpdateSubscriptions( |
[email protected] | fc438686 | 2012-05-17 02:11:48 | [diff] [blame] | 199 | notifier::SubscriptionList(1, subscription)); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 200 | // If already logged in, the new credentials will take effect on the |
| 201 | // next reconnection. |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 202 | push_client_->UpdateCredentials(email, token); |
[email protected] | fc438686 | 2012-05-17 02:11:48 | [diff] [blame] | 203 | logged_in_ = true; |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 206 | void P2PInvalidator::RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 207 | base::Callback<void(const base::DictionaryValue&)> callback) const { |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 208 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 | // TODO(mferreria): Make the P2P Invalidator work. |
| 210 | scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 211 | callback.Run(*value); |
| 212 | } |
| 213 | |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 214 | void P2PInvalidator::SendInvalidation(const ObjectIdSet& ids) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 215 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 216 | ObjectIdInvalidationMap invalidation_map = |
| 217 | ObjectIdInvalidationMap::InvalidateAll(ids); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 218 | const P2PNotificationData notification_data( |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 219 | invalidator_client_id_, send_notification_target_, invalidation_map); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 220 | SendNotificationData(notification_data); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 223 | void P2PInvalidator::OnNotificationsEnabled() { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 224 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 225 | bool just_turned_on = (notifications_enabled_ == false); |
| 226 | notifications_enabled_ = true; |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 227 | registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED); |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 228 | if (just_turned_on) { |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 229 | const P2PNotificationData notification_data( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 230 | invalidator_client_id_, |
| 231 | NOTIFY_SELF, |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 232 | ObjectIdInvalidationMap::InvalidateAll( |
| 233 | registrar_.GetAllRegisteredIds())); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 234 | SendNotificationData(notification_data); |
| 235 | } |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 238 | void P2PInvalidator::OnNotificationsDisabled( |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 239 | notifier::NotificationsDisabledReason reason) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 240 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 241 | registrar_.UpdateInvalidatorState(FromNotifierReason(reason)); |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 244 | void P2PInvalidator::OnIncomingNotification( |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 245 | const notifier::Notification& notification) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 246 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 060588c | 2011-11-29 21:38:41 | [diff] [blame] | 247 | DVLOG(1) << "Received notification " << notification.ToString(); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 248 | if (!logged_in_) { |
[email protected] | 060588c | 2011-11-29 21:38:41 | [diff] [blame] | 249 | DVLOG(1) << "Not logged in yet -- not emitting notification"; |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | if (!notifications_enabled_) { |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 253 | DVLOG(1) << "Notifications not on -- not emitting notification"; |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 254 | return; |
| 255 | } |
[email protected] | d6fdf68 | 2011-08-27 06:53:21 | [diff] [blame] | 256 | if (notification.channel != kSyncP2PNotificationChannel) { |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 257 | LOG(WARNING) << "Notification from unexpected source " |
| 258 | << notification.channel; |
| 259 | } |
| 260 | P2PNotificationData notification_data; |
| 261 | if (!notification_data.ResetFromString(notification.data)) { |
| 262 | LOG(WARNING) << "Could not parse notification data from " |
| 263 | << notification.data; |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 264 | notification_data = P2PNotificationData( |
| 265 | invalidator_client_id_, |
| 266 | NOTIFY_ALL, |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 267 | ObjectIdInvalidationMap::InvalidateAll( |
| 268 | registrar_.GetAllRegisteredIds())); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 269 | } |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 270 | if (!notification_data.IsTargeted(invalidator_client_id_)) { |
[email protected] | 060588c | 2011-11-29 21:38:41 | [diff] [blame] | 271 | DVLOG(1) << "Not a target of the notification -- " |
| 272 | << "not emitting notification"; |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 273 | return; |
| 274 | } |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 275 | registrar_.DispatchInvalidationsToHandlers( |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 276 | notification_data.GetIdInvalidationMap()); |
[email protected] | 08dd831 | 2011-03-19 20:09:31 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 279 | void P2PInvalidator::SendNotificationDataForTest( |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 280 | const P2PNotificationData& notification_data) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 281 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 282 | SendNotificationData(notification_data); |
| 283 | } |
| 284 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 285 | void P2PInvalidator::SendNotificationData( |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 286 | const P2PNotificationData& notification_data) { |
[email protected] | 327e52b | 2012-06-25 21:11:36 | [diff] [blame] | 287 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 288 | if (notification_data.GetIdInvalidationMap().Empty()) { |
[email protected] | 33596da | 2012-08-31 23:39:25 | [diff] [blame] | 289 | DVLOG(1) << "Not sending XMPP notification with empty state map: " |
[email protected] | 177bcf2 | 2012-07-26 03:13:46 | [diff] [blame] | 290 | << notification_data.ToString(); |
| 291 | return; |
| 292 | } |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 293 | notifier::Notification notification; |
[email protected] | d6fdf68 | 2011-08-27 06:53:21 | [diff] [blame] | 294 | notification.channel = kSyncP2PNotificationChannel; |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 295 | notification.data = notification_data.ToString(); |
[email protected] | 060588c | 2011-11-29 21:38:41 | [diff] [blame] | 296 | DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
[email protected] | 6618e73f | 2012-05-23 05:20:40 | [diff] [blame] | 297 | push_client_->SendNotification(notification); |
[email protected] | 2f15fd0e | 2011-08-27 05:29:09 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 300 | } // namespace syncer |