Index: sync/notifier/p2p_notifier.cc |
diff --git a/sync/notifier/p2p_notifier.cc b/sync/notifier/p2p_notifier.cc |
index 2eae2465b9a828028bb3c54e8cdfc928c2f553b4..5a63c4ce7c6202573d4a442e923417420237a643 100644 |
--- a/sync/notifier/p2p_notifier.cc |
+++ b/sync/notifier/p2p_notifier.cc |
@@ -144,7 +144,7 @@ P2PNotifier::P2PNotifier(scoped_ptr<notifier::PushClient> push_client, |
P2PNotificationTarget send_notification_target) |
: push_client_(push_client.Pass()), |
logged_in_(false), |
- notifications_enabled_(false), |
+ state_(NOTIFICATIONS_OFF), |
send_notification_target_(send_notification_target) { |
DCHECK(send_notification_target_ == NOTIFY_OTHERS || |
send_notification_target_ == NOTIFY_ALL); |
@@ -212,13 +212,18 @@ void P2PNotifier::SendNotification( |
SendNotificationData(notification_data); |
} |
-void P2PNotifier::OnNotificationStateChange(bool notifications_enabled) { |
+void P2PNotifier::OnPushClientStateChange( |
+ notifier::PushClientState push_client_state) { |
DCHECK(non_thread_safe_.CalledOnValidThread()); |
- bool disabled_to_enabled = notifications_enabled && !notifications_enabled_; |
- notifications_enabled_ = notifications_enabled; |
- FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, |
- OnNotificationStateChange(notifications_enabled_)); |
- if (disabled_to_enabled) { |
+ SyncNotifierState state = |
+ PushClientStateToSyncNotifierState(push_client_state); |
+ bool just_turned_on = |
rlarocque
2012/06/14 20:01:07
This protects against spurious notifications, righ
akalin
2012/06/16 01:06:55
I think it's okay to be defensive here since it co
|
+ (state_ != NOTIFICATIONS_ON) && (state == NOTIFICATIONS_ON); |
+ state_ = state; |
+ FOR_EACH_OBSERVER( |
+ SyncNotifierObserver, observer_list_, |
+ OnSyncNotifierStateChange(state_)); |
+ if (just_turned_on) { |
const P2PNotificationData notification_data( |
unique_id_, NOTIFY_SELF, enabled_types_); |
SendNotificationData(notification_data); |
@@ -233,8 +238,8 @@ void P2PNotifier::OnIncomingNotification( |
DVLOG(1) << "Not logged in yet -- not emitting notification"; |
return; |
} |
- if (!notifications_enabled_) { |
- DVLOG(1) << "Notifications not enabled -- not emitting notification"; |
+ if (state_ != NOTIFICATIONS_ON) { |
+ DVLOG(1) << "Notifications not on -- not emitting notification"; |
return; |
} |
if (notification.channel != kSyncP2PNotificationChannel) { |