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_notifier.h" | 5 #include "sync/notifier/p2p_notifier.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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 LOG(WARNING) << "Could not parse notification data from " | 253 LOG(WARNING) << "Could not parse notification data from " |
254 << notification.data; | 254 << notification.data; |
255 notification_data = | 255 notification_data = |
256 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); | 256 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); |
257 } | 257 } |
258 if (!notification_data.IsTargeted(unique_id_)) { | 258 if (!notification_data.IsTargeted(unique_id_)) { |
259 DVLOG(1) << "Not a target of the notification -- " | 259 DVLOG(1) << "Not a target of the notification -- " |
260 << "not emitting notification"; | 260 << "not emitting notification"; |
261 return; | 261 return; |
262 } | 262 } |
263 if (notification_data.GetChangedTypes().Empty()) { | 263 const ModelTypeSet types_to_notify = |
264 DVLOG(1) << "No changed types -- not emitting notification"; | 264 Intersection(enabled_types_, notification_data.GetChangedTypes()); |
| 265 if (types_to_notify.Empty()) { |
| 266 DVLOG(1) << "No enabled and changed types -- not emitting notification"; |
265 return; | 267 return; |
266 } | 268 } |
267 const ModelTypePayloadMap& type_payloads = | 269 const ModelTypePayloadMap& type_payloads = |
268 ModelTypePayloadMapFromEnumSet( | 270 ModelTypePayloadMapFromEnumSet(types_to_notify, std::string()); |
269 notification_data.GetChangedTypes(), std::string()); | |
270 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, | 271 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, |
271 OnIncomingNotification(type_payloads, REMOTE_NOTIFICATION)); | 272 OnIncomingNotification(type_payloads, REMOTE_NOTIFICATION)); |
272 } | 273 } |
273 | 274 |
274 void P2PNotifier::SendNotificationDataForTest( | 275 void P2PNotifier::SendNotificationDataForTest( |
275 const P2PNotificationData& notification_data) { | 276 const P2PNotificationData& notification_data) { |
276 DCHECK(thread_checker_.CalledOnValidThread()); | 277 DCHECK(thread_checker_.CalledOnValidThread()); |
277 SendNotificationData(notification_data); | 278 SendNotificationData(notification_data); |
278 } | 279 } |
279 | 280 |
280 void P2PNotifier::SendNotificationData( | 281 void P2PNotifier::SendNotificationData( |
281 const P2PNotificationData& notification_data) { | 282 const P2PNotificationData& notification_data) { |
282 DCHECK(thread_checker_.CalledOnValidThread()); | 283 DCHECK(thread_checker_.CalledOnValidThread()); |
283 notifier::Notification notification; | 284 notifier::Notification notification; |
284 notification.channel = kSyncP2PNotificationChannel; | 285 notification.channel = kSyncP2PNotificationChannel; |
285 notification.data = notification_data.ToString(); | 286 notification.data = notification_data.ToString(); |
286 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 287 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
287 push_client_->SendNotification(notification); | 288 push_client_->SendNotification(notification); |
288 } | 289 } |
289 | 290 |
290 } // namespace syncer | 291 } // namespace syncer |
OLD | NEW |