| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 void P2PNotifier::SendNotification( | 207 void P2PNotifier::SendNotification( |
| 208 syncable::ModelTypeSet changed_types) { | 208 syncable::ModelTypeSet changed_types) { |
| 209 DCHECK(non_thread_safe_.CalledOnValidThread()); | 209 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 210 const P2PNotificationData notification_data( | 210 const P2PNotificationData notification_data( |
| 211 unique_id_, send_notification_target_, changed_types); | 211 unique_id_, send_notification_target_, changed_types); |
| 212 SendNotificationData(notification_data); | 212 SendNotificationData(notification_data); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void P2PNotifier::OnNotificationStateChange(bool notifications_enabled) { | 215 void P2PNotifier::OnNotificationsEnabled() { |
| 216 DCHECK(non_thread_safe_.CalledOnValidThread()); | 216 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 217 bool disabled_to_enabled = notifications_enabled && !notifications_enabled_; | 217 bool just_turned_on = (notifications_enabled_ == false); |
| 218 notifications_enabled_ = notifications_enabled; | 218 notifications_enabled_ = true; |
| 219 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, | 219 FOR_EACH_OBSERVER( |
| 220 OnNotificationStateChange(notifications_enabled_)); | 220 SyncNotifierObserver, observer_list_, |
| 221 if (disabled_to_enabled) { | 221 OnNotificationsEnabled()); |
| 222 if (just_turned_on) { |
| 222 const P2PNotificationData notification_data( | 223 const P2PNotificationData notification_data( |
| 223 unique_id_, NOTIFY_SELF, enabled_types_); | 224 unique_id_, NOTIFY_SELF, enabled_types_); |
| 224 SendNotificationData(notification_data); | 225 SendNotificationData(notification_data); |
| 225 } | 226 } |
| 226 } | 227 } |
| 227 | 228 |
| 229 void P2PNotifier::OnNotificationsDisabled( |
| 230 notifier::NotificationsDisabledReason reason) { |
| 231 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 232 FOR_EACH_OBSERVER( |
| 233 SyncNotifierObserver, observer_list_, |
| 234 OnNotificationsDisabled(FromNotifierReason(reason))); |
| 235 } |
| 236 |
| 228 void P2PNotifier::OnIncomingNotification( | 237 void P2PNotifier::OnIncomingNotification( |
| 229 const notifier::Notification& notification) { | 238 const notifier::Notification& notification) { |
| 230 DCHECK(non_thread_safe_.CalledOnValidThread()); | 239 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 231 DVLOG(1) << "Received notification " << notification.ToString(); | 240 DVLOG(1) << "Received notification " << notification.ToString(); |
| 232 if (!logged_in_) { | 241 if (!logged_in_) { |
| 233 DVLOG(1) << "Not logged in yet -- not emitting notification"; | 242 DVLOG(1) << "Not logged in yet -- not emitting notification"; |
| 234 return; | 243 return; |
| 235 } | 244 } |
| 236 if (!notifications_enabled_) { | 245 if (!notifications_enabled_) { |
| 237 DVLOG(1) << "Notifications not enabled -- not emitting notification"; | 246 DVLOG(1) << "Notifications not on -- not emitting notification"; |
| 238 return; | 247 return; |
| 239 } | 248 } |
| 240 if (notification.channel != kSyncP2PNotificationChannel) { | 249 if (notification.channel != kSyncP2PNotificationChannel) { |
| 241 LOG(WARNING) << "Notification from unexpected source " | 250 LOG(WARNING) << "Notification from unexpected source " |
| 242 << notification.channel; | 251 << notification.channel; |
| 243 } | 252 } |
| 244 P2PNotificationData notification_data; | 253 P2PNotificationData notification_data; |
| 245 if (!notification_data.ResetFromString(notification.data)) { | 254 if (!notification_data.ResetFromString(notification.data)) { |
| 246 LOG(WARNING) << "Could not parse notification data from " | 255 LOG(WARNING) << "Could not parse notification data from " |
| 247 << notification.data; | 256 << notification.data; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 274 const P2PNotificationData& notification_data) { | 283 const P2PNotificationData& notification_data) { |
| 275 DCHECK(non_thread_safe_.CalledOnValidThread()); | 284 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 276 notifier::Notification notification; | 285 notifier::Notification notification; |
| 277 notification.channel = kSyncP2PNotificationChannel; | 286 notification.channel = kSyncP2PNotificationChannel; |
| 278 notification.data = notification_data.ToString(); | 287 notification.data = notification_data.ToString(); |
| 279 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 288 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 280 push_client_->SendNotification(notification); | 289 push_client_->SendNotification(notification); |
| 281 } | 290 } |
| 282 | 291 |
| 283 } // namespace sync_notifier | 292 } // namespace sync_notifier |
| OLD | NEW |