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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 14 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
15 #include "chrome/browser/sync/protocol/service_constants.h" | 15 #include "chrome/browser/sync/protocol/service_constants.h" |
16 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 16 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
17 | 17 |
18 namespace sync_notifier { | 18 namespace sync_notifier { |
19 | 19 |
| 20 const char* kSyncP2PNotificationChannel = "http://www.google.com/chrome/sync"; |
| 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char kSyncNotificationChannel[] = "http://www.google.com/chrome/sync"; | |
23 | |
24 const char kNotifySelf[] = "notifySelf"; | 24 const char kNotifySelf[] = "notifySelf"; |
25 const char kNotifyOthers[] = "notifyOthers"; | 25 const char kNotifyOthers[] = "notifyOthers"; |
26 const char kNotifyAll[] = "notifyAll"; | 26 const char kNotifyAll[] = "notifyAll"; |
27 | 27 |
28 const char kSenderIdKey[] = "senderId"; | 28 const char kSenderIdKey[] = "senderId"; |
29 const char kNotificationTypeKey[] = "notificationType"; | 29 const char kNotificationTypeKey[] = "notificationType"; |
30 const char kChangedTypesKey[] = "changedTypes"; | 30 const char kChangedTypesKey[] = "changedTypes"; |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // If already logged in, the new credentials will take effect on the | 186 // If already logged in, the new credentials will take effect on the |
187 // next reconnection. | 187 // next reconnection. |
188 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); | 188 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); |
189 if (!logged_in_) { | 189 if (!logged_in_) { |
190 if (!talk_mediator_->Login()) { | 190 if (!talk_mediator_->Login()) { |
191 LOG(DFATAL) << "Could not login for " << email; | 191 LOG(DFATAL) << "Could not login for " << email; |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 notifier::Subscription subscription; | 195 notifier::Subscription subscription; |
196 subscription.channel = kSyncNotificationChannel; | 196 subscription.channel = kSyncP2PNotificationChannel; |
197 // There may be some subtle issues around case sensitivity of the | 197 // There may be some subtle issues around case sensitivity of the |
198 // from field, but it doesn't matter too much since this is only | 198 // from field, but it doesn't matter too much since this is only |
199 // used in p2p mode (which is only used in testing). | 199 // used in p2p mode (which is only used in testing). |
200 subscription.from = email; | 200 subscription.from = email; |
201 talk_mediator_->AddSubscription(subscription); | 201 talk_mediator_->AddSubscription(subscription); |
202 | 202 |
203 logged_in_ = true; | 203 logged_in_ = true; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 244 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
245 VLOG(1) << "Received notification " << notification.ToString(); | 245 VLOG(1) << "Received notification " << notification.ToString(); |
246 if (!logged_in_) { | 246 if (!logged_in_) { |
247 VLOG(1) << "Not logged in yet -- not emitting notification"; | 247 VLOG(1) << "Not logged in yet -- not emitting notification"; |
248 return; | 248 return; |
249 } | 249 } |
250 if (!notifications_enabled_) { | 250 if (!notifications_enabled_) { |
251 VLOG(1) << "Notifications not enabled -- not emitting notification"; | 251 VLOG(1) << "Notifications not enabled -- not emitting notification"; |
252 return; | 252 return; |
253 } | 253 } |
254 if (notification.channel != kSyncNotificationChannel) { | 254 if (notification.channel != kSyncP2PNotificationChannel) { |
255 LOG(WARNING) << "Notification from unexpected source " | 255 LOG(WARNING) << "Notification from unexpected source " |
256 << notification.channel; | 256 << notification.channel; |
257 } | 257 } |
258 P2PNotificationData notification_data; | 258 P2PNotificationData notification_data; |
259 if (!notification_data.FromString(notification.data)) { | 259 if (!notification_data.FromString(notification.data)) { |
260 LOG(WARNING) << "Could not parse notification data from " | 260 LOG(WARNING) << "Could not parse notification data from " |
261 << notification.data; | 261 << notification.data; |
262 notification_data = | 262 notification_data = |
263 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); | 263 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); |
264 } | 264 } |
(...skipping 18 matching lines...) Expand all Loading... |
283 | 283 |
284 void P2PNotifier::SendNotificationDataForTest( | 284 void P2PNotifier::SendNotificationDataForTest( |
285 const P2PNotificationData& notification_data) { | 285 const P2PNotificationData& notification_data) { |
286 SendNotificationData(notification_data); | 286 SendNotificationData(notification_data); |
287 } | 287 } |
288 | 288 |
289 void P2PNotifier::SendNotificationData( | 289 void P2PNotifier::SendNotificationData( |
290 const P2PNotificationData& notification_data) { | 290 const P2PNotificationData& notification_data) { |
291 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 291 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
292 notifier::Notification notification; | 292 notifier::Notification notification; |
293 notification.channel = kSyncNotificationChannel; | 293 notification.channel = kSyncP2PNotificationChannel; |
294 notification.data = notification_data.ToString(); | 294 notification.data = notification_data.ToString(); |
295 VLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 295 VLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
296 talk_mediator_->SendNotification(notification); | 296 talk_mediator_->SendNotification(notification); |
297 } | 297 } |
298 | 298 |
299 } // namespace sync_notifier | 299 } // namespace sync_notifier |
OLD | NEW |