OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/notifier/p2p_notifier.h" | 5 #include "chrome/browser/sync/notifier/p2p_notifier.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 8 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
9 #include "chrome/browser/sync/protocol/service_constants.h" | 9 #include "chrome/browser/sync/protocol/service_constants.h" |
10 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 10 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 enabled_types_ = types; | 87 enabled_types_ = types; |
88 MaybeEmitNotification(); | 88 MaybeEmitNotification(); |
89 } | 89 } |
90 | 90 |
91 void P2PNotifier::SendNotification() { | 91 void P2PNotifier::SendNotification() { |
92 CheckOrSetValidThread(); | 92 CheckOrSetValidThread(); |
93 VLOG(1) << "Sending XMPP notification..."; | 93 VLOG(1) << "Sending XMPP notification..."; |
94 notifier::Notification notification; | 94 notifier::Notification notification; |
95 notification.channel = kSyncNotificationChannel; | 95 notification.channel = kSyncNotificationChannel; |
96 notification.data = kSyncNotificationData; | 96 notification.data = kSyncNotificationData; |
97 bool success = talk_mediator_->SendNotification(notification); | 97 talk_mediator_->SendNotification(notification); |
98 if (success) { | |
99 VLOG(1) << "Sent XMPP notification"; | |
100 } else { | |
101 VLOG(1) << "Could not send XMPP notification"; | |
102 } | |
103 } | 98 } |
104 | 99 |
105 void P2PNotifier::OnNotificationStateChange(bool notifications_enabled) { | 100 void P2PNotifier::OnNotificationStateChange(bool notifications_enabled) { |
106 CheckOrSetValidThread(); | 101 CheckOrSetValidThread(); |
107 notifications_enabled_ = notifications_enabled; | 102 notifications_enabled_ = notifications_enabled; |
108 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, | 103 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, |
109 OnNotificationStateChange(notifications_enabled_)); | 104 OnNotificationStateChange(notifications_enabled_)); |
110 MaybeEmitNotification(); | 105 MaybeEmitNotification(); |
111 } | 106 } |
112 | 107 |
113 void P2PNotifier::OnIncomingNotification( | 108 void P2PNotifier::OnIncomingNotification( |
114 const notifier::Notification& notification) { | 109 const notifier::Notification& notification) { |
115 CheckOrSetValidThread(); | 110 CheckOrSetValidThread(); |
116 VLOG(1) << "Sync received P2P notification."; | 111 VLOG(1) << "Sync received P2P notification."; |
117 if (notification.channel != kSyncNotificationChannel) { | 112 if (notification.channel != kSyncNotificationChannel) { |
118 LOG(WARNING) << "Notification fron unexpected source: " | 113 LOG(WARNING) << "Notification from unexpected source: " |
119 << notification.channel; | 114 << notification.channel; |
120 } | 115 } |
121 MaybeEmitNotification(); | 116 MaybeEmitNotification(); |
122 } | 117 } |
123 | 118 |
124 void P2PNotifier::OnOutgoingNotification() {} | 119 void P2PNotifier::OnOutgoingNotification() {} |
125 | 120 |
126 void P2PNotifier::MaybeEmitNotification() { | 121 void P2PNotifier::MaybeEmitNotification() { |
127 if (!logged_in_) { | 122 if (!logged_in_) { |
128 VLOG(1) << "Not logged in yet -- not emitting notification"; | 123 VLOG(1) << "Not logged in yet -- not emitting notification"; |
(...skipping 17 matching lines...) Expand all Loading... |
146 void P2PNotifier::CheckOrSetValidThread() { | 141 void P2PNotifier::CheckOrSetValidThread() { |
147 if (method_message_loop_proxy_) { | 142 if (method_message_loop_proxy_) { |
148 DCHECK(method_message_loop_proxy_->BelongsToCurrentThread()); | 143 DCHECK(method_message_loop_proxy_->BelongsToCurrentThread()); |
149 } else { | 144 } else { |
150 method_message_loop_proxy_ = | 145 method_message_loop_proxy_ = |
151 base::MessageLoopProxy::CreateForCurrentThread(); | 146 base::MessageLoopProxy::CreateForCurrentThread(); |
152 } | 147 } |
153 } | 148 } |
154 | 149 |
155 } // namespace sync_notifier | 150 } // namespace sync_notifier |
OLD | NEW |