Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: sync/notifier/p2p_notifier.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/notifier/p2p_notifier.h ('k') | sync/notifier/p2p_notifier_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return false; 137 return false;
138 } 138 }
139 changed_types_ = syncable::ModelTypeSetFromValue(*changed_types_list); 139 changed_types_ = syncable::ModelTypeSetFromValue(*changed_types_list);
140 return true; 140 return true;
141 } 141 }
142 142
143 P2PNotifier::P2PNotifier(scoped_ptr<notifier::PushClient> push_client, 143 P2PNotifier::P2PNotifier(scoped_ptr<notifier::PushClient> push_client,
144 P2PNotificationTarget send_notification_target) 144 P2PNotificationTarget send_notification_target)
145 : push_client_(push_client.Pass()), 145 : push_client_(push_client.Pass()),
146 logged_in_(false), 146 logged_in_(false),
147 notifications_enabled_(false), 147 state_(NOTIFICATIONS_OFF),
148 send_notification_target_(send_notification_target) { 148 send_notification_target_(send_notification_target) {
149 DCHECK(send_notification_target_ == NOTIFY_OTHERS || 149 DCHECK(send_notification_target_ == NOTIFY_OTHERS ||
150 send_notification_target_ == NOTIFY_ALL); 150 send_notification_target_ == NOTIFY_ALL);
151 push_client_->AddObserver(this); 151 push_client_->AddObserver(this);
152 } 152 }
153 153
154 P2PNotifier::~P2PNotifier() { 154 P2PNotifier::~P2PNotifier() {
155 DCHECK(non_thread_safe_.CalledOnValidThread()); 155 DCHECK(non_thread_safe_.CalledOnValidThread());
156 push_client_->RemoveObserver(this); 156 push_client_->RemoveObserver(this);
157 } 157 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::OnPushClientStateChange(
216 notifier::PushClientState push_client_state) {
216 DCHECK(non_thread_safe_.CalledOnValidThread()); 217 DCHECK(non_thread_safe_.CalledOnValidThread());
217 bool disabled_to_enabled = notifications_enabled && !notifications_enabled_; 218 SyncNotifierState state =
218 notifications_enabled_ = notifications_enabled; 219 PushClientStateToSyncNotifierState(push_client_state);
219 FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, 220 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
220 OnNotificationStateChange(notifications_enabled_)); 221 (state_ != NOTIFICATIONS_ON) && (state == NOTIFICATIONS_ON);
221 if (disabled_to_enabled) { 222 state_ = state;
223 FOR_EACH_OBSERVER(
224 SyncNotifierObserver, observer_list_,
225 OnSyncNotifierStateChange(state_));
226 if (just_turned_on) {
222 const P2PNotificationData notification_data( 227 const P2PNotificationData notification_data(
223 unique_id_, NOTIFY_SELF, enabled_types_); 228 unique_id_, NOTIFY_SELF, enabled_types_);
224 SendNotificationData(notification_data); 229 SendNotificationData(notification_data);
225 } 230 }
226 } 231 }
227 232
228 void P2PNotifier::OnIncomingNotification( 233 void P2PNotifier::OnIncomingNotification(
229 const notifier::Notification& notification) { 234 const notifier::Notification& notification) {
230 DCHECK(non_thread_safe_.CalledOnValidThread()); 235 DCHECK(non_thread_safe_.CalledOnValidThread());
231 DVLOG(1) << "Received notification " << notification.ToString(); 236 DVLOG(1) << "Received notification " << notification.ToString();
232 if (!logged_in_) { 237 if (!logged_in_) {
233 DVLOG(1) << "Not logged in yet -- not emitting notification"; 238 DVLOG(1) << "Not logged in yet -- not emitting notification";
234 return; 239 return;
235 } 240 }
236 if (!notifications_enabled_) { 241 if (state_ != NOTIFICATIONS_ON) {
237 DVLOG(1) << "Notifications not enabled -- not emitting notification"; 242 DVLOG(1) << "Notifications not on -- not emitting notification";
238 return; 243 return;
239 } 244 }
240 if (notification.channel != kSyncP2PNotificationChannel) { 245 if (notification.channel != kSyncP2PNotificationChannel) {
241 LOG(WARNING) << "Notification from unexpected source " 246 LOG(WARNING) << "Notification from unexpected source "
242 << notification.channel; 247 << notification.channel;
243 } 248 }
244 P2PNotificationData notification_data; 249 P2PNotificationData notification_data;
245 if (!notification_data.ResetFromString(notification.data)) { 250 if (!notification_data.ResetFromString(notification.data)) {
246 LOG(WARNING) << "Could not parse notification data from " 251 LOG(WARNING) << "Could not parse notification data from "
247 << notification.data; 252 << notification.data;
(...skipping 26 matching lines...) Expand all
274 const P2PNotificationData& notification_data) { 279 const P2PNotificationData& notification_data) {
275 DCHECK(non_thread_safe_.CalledOnValidThread()); 280 DCHECK(non_thread_safe_.CalledOnValidThread());
276 notifier::Notification notification; 281 notifier::Notification notification;
277 notification.channel = kSyncP2PNotificationChannel; 282 notification.channel = kSyncP2PNotificationChannel;
278 notification.data = notification_data.ToString(); 283 notification.data = notification_data.ToString();
279 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); 284 DVLOG(1) << "Sending XMPP notification: " << notification.ToString();
280 push_client_->SendNotification(notification); 285 push_client_->SendNotification(notification);
281 } 286 }
282 287
283 } // namespace sync_notifier 288 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « sync/notifier/p2p_notifier.h ('k') | sync/notifier/p2p_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698