| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/notifier/p2p_invalidator.h" | 5 #include "sync/notifier/p2p_invalidator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ObjectIdSet new_ids; | 166 ObjectIdSet new_ids; |
| 167 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); | 167 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); |
| 168 std::set_difference(ids.begin(), ids.end(), | 168 std::set_difference(ids.begin(), ids.end(), |
| 169 old_ids.begin(), old_ids.end(), | 169 old_ids.begin(), old_ids.end(), |
| 170 std::inserter(new_ids, new_ids.end()), | 170 std::inserter(new_ids, new_ids.end()), |
| 171 ObjectIdLessThan()); | 171 ObjectIdLessThan()); |
| 172 registrar_.UpdateRegisteredIds(handler, ids); | 172 registrar_.UpdateRegisteredIds(handler, ids); |
| 173 const P2PNotificationData notification_data( | 173 const P2PNotificationData notification_data( |
| 174 invalidator_client_id_, | 174 invalidator_client_id_, |
| 175 NOTIFY_SELF, | 175 NOTIFY_SELF, |
| 176 ObjectIdSetToInvalidationMap(new_ids, std::string())); | 176 ObjectIdSetToInvalidationMap(new_ids, |
| 177 Invalidation::kUnknownVersion, |
| 178 std::string())); |
| 177 SendNotificationData(notification_data); | 179 SendNotificationData(notification_data); |
| 178 } | 180 } |
| 179 | 181 |
| 180 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { | 182 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { |
| 181 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
| 182 registrar_.UnregisterHandler(handler); | 184 registrar_.UnregisterHandler(handler); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void P2PInvalidator::Acknowledge(const invalidation::ObjectId& id, | 187 void P2PInvalidator::Acknowledge(const invalidation::ObjectId& id, |
| 186 const AckHandle& ack_handle) { | 188 const AckHandle& ack_handle) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 void P2PInvalidator::OnNotificationsEnabled() { | 223 void P2PInvalidator::OnNotificationsEnabled() { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 224 DCHECK(thread_checker_.CalledOnValidThread()); |
| 223 bool just_turned_on = (notifications_enabled_ == false); | 225 bool just_turned_on = (notifications_enabled_ == false); |
| 224 notifications_enabled_ = true; | 226 notifications_enabled_ = true; |
| 225 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED); | 227 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED); |
| 226 if (just_turned_on) { | 228 if (just_turned_on) { |
| 227 const P2PNotificationData notification_data( | 229 const P2PNotificationData notification_data( |
| 228 invalidator_client_id_, | 230 invalidator_client_id_, |
| 229 NOTIFY_SELF, | 231 NOTIFY_SELF, |
| 230 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), | 232 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), |
| 233 Invalidation::kUnknownVersion, |
| 231 std::string())); | 234 std::string())); |
| 232 SendNotificationData(notification_data); | 235 SendNotificationData(notification_data); |
| 233 } | 236 } |
| 234 } | 237 } |
| 235 | 238 |
| 236 void P2PInvalidator::OnNotificationsDisabled( | 239 void P2PInvalidator::OnNotificationsDisabled( |
| 237 notifier::NotificationsDisabledReason reason) { | 240 notifier::NotificationsDisabledReason reason) { |
| 238 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 239 registrar_.UpdateInvalidatorState(FromNotifierReason(reason)); | 242 registrar_.UpdateInvalidatorState(FromNotifierReason(reason)); |
| 240 } | 243 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 256 << notification.channel; | 259 << notification.channel; |
| 257 } | 260 } |
| 258 P2PNotificationData notification_data; | 261 P2PNotificationData notification_data; |
| 259 if (!notification_data.ResetFromString(notification.data)) { | 262 if (!notification_data.ResetFromString(notification.data)) { |
| 260 LOG(WARNING) << "Could not parse notification data from " | 263 LOG(WARNING) << "Could not parse notification data from " |
| 261 << notification.data; | 264 << notification.data; |
| 262 notification_data = P2PNotificationData( | 265 notification_data = P2PNotificationData( |
| 263 invalidator_client_id_, | 266 invalidator_client_id_, |
| 264 NOTIFY_ALL, | 267 NOTIFY_ALL, |
| 265 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), | 268 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), |
| 269 Invalidation::kUnknownVersion, |
| 266 std::string())); | 270 std::string())); |
| 267 } | 271 } |
| 268 if (!notification_data.IsTargeted(invalidator_client_id_)) { | 272 if (!notification_data.IsTargeted(invalidator_client_id_)) { |
| 269 DVLOG(1) << "Not a target of the notification -- " | 273 DVLOG(1) << "Not a target of the notification -- " |
| 270 << "not emitting notification"; | 274 << "not emitting notification"; |
| 271 return; | 275 return; |
| 272 } | 276 } |
| 273 registrar_.DispatchInvalidationsToHandlers( | 277 registrar_.DispatchInvalidationsToHandlers( |
| 274 notification_data.GetIdInvalidationMap()); | 278 notification_data.GetIdInvalidationMap()); |
| 275 } | 279 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 289 return; | 293 return; |
| 290 } | 294 } |
| 291 notifier::Notification notification; | 295 notifier::Notification notification; |
| 292 notification.channel = kSyncP2PNotificationChannel; | 296 notification.channel = kSyncP2PNotificationChannel; |
| 293 notification.data = notification_data.ToString(); | 297 notification.data = notification_data.ToString(); |
| 294 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 298 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 295 push_client_->SendNotification(notification); | 299 push_client_->SendNotification(notification); |
| 296 } | 300 } |
| 297 | 301 |
| 298 } // namespace syncer | 302 } // namespace syncer |
| OLD | NEW |