| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/invalidation/p2p_invalidator.h" | 5 #include "components/invalidation/p2p_invalidator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 P2PInvalidator::~P2PInvalidator() { | 152 P2PInvalidator::~P2PInvalidator() { |
| 153 DCHECK(thread_checker_.CalledOnValidThread()); | 153 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 push_client_->RemoveObserver(this); | 154 push_client_->RemoveObserver(this); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void P2PInvalidator::RegisterHandler(InvalidationHandler* handler) { | 157 void P2PInvalidator::RegisterHandler(InvalidationHandler* handler) { |
| 158 DCHECK(thread_checker_.CalledOnValidThread()); | 158 DCHECK(thread_checker_.CalledOnValidThread()); |
| 159 registrar_.RegisterHandler(handler); | 159 registrar_.RegisterHandler(handler); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void P2PInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, | 162 bool P2PInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, |
| 163 const ObjectIdSet& ids) { | 163 const ObjectIdSet& ids) { |
| 164 DCHECK(thread_checker_.CalledOnValidThread()); | 164 DCHECK(thread_checker_.CalledOnValidThread()); |
| 165 ObjectIdSet new_ids; | 165 ObjectIdSet new_ids; |
| 166 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); | 166 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); |
| 167 std::set_difference(ids.begin(), ids.end(), | 167 std::set_difference(ids.begin(), ids.end(), |
| 168 old_ids.begin(), old_ids.end(), | 168 old_ids.begin(), old_ids.end(), |
| 169 std::inserter(new_ids, new_ids.end()), | 169 std::inserter(new_ids, new_ids.end()), |
| 170 ObjectIdLessThan()); | 170 ObjectIdLessThan()); |
| 171 registrar_.UpdateRegisteredIds(handler, ids); | 171 if (!registrar_.UpdateRegisteredIds(handler, ids)) |
| 172 return false; |
| 172 const P2PNotificationData notification_data( | 173 const P2PNotificationData notification_data( |
| 173 invalidator_client_id_, | 174 invalidator_client_id_, |
| 174 send_notification_target_, | 175 send_notification_target_, |
| 175 ObjectIdInvalidationMap::InvalidateAll(ids)); | 176 ObjectIdInvalidationMap::InvalidateAll(ids)); |
| 176 SendNotificationData(notification_data); | 177 SendNotificationData(notification_data); |
| 178 return true; |
| 177 } | 179 } |
| 178 | 180 |
| 179 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { | 181 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { |
| 180 DCHECK(thread_checker_.CalledOnValidThread()); | 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 registrar_.UnregisterHandler(handler); | 183 registrar_.UnregisterHandler(handler); |
| 182 } | 184 } |
| 183 | 185 |
| 184 InvalidatorState P2PInvalidator::GetInvalidatorState() const { | 186 InvalidatorState P2PInvalidator::GetInvalidatorState() const { |
| 185 DCHECK(thread_checker_.CalledOnValidThread()); | 187 DCHECK(thread_checker_.CalledOnValidThread()); |
| 186 return registrar_.GetInvalidatorState(); | 188 return registrar_.GetInvalidatorState(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return; | 293 return; |
| 292 } | 294 } |
| 293 notifier::Notification notification; | 295 notifier::Notification notification; |
| 294 notification.channel = kSyncP2PNotificationChannel; | 296 notification.channel = kSyncP2PNotificationChannel; |
| 295 notification.data = notification_data.ToString(); | 297 notification.data = notification_data.ToString(); |
| 296 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 298 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 297 push_client_->SendNotification(notification); | 299 push_client_->SendNotification(notification); |
| 298 } | 300 } |
| 299 | 301 |
| 300 } // namespace syncer | 302 } // namespace syncer |
| OLD | NEW |