| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // If already logged in, the new credentials will take effect on the | 189 // If already logged in, the new credentials will take effect on the |
| 190 // next reconnection. | 190 // next reconnection. |
| 191 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); | 191 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); |
| 192 if (!logged_in_) { | 192 if (!logged_in_) { |
| 193 if (!talk_mediator_->Login()) { | 193 if (!talk_mediator_->Login()) { |
| 194 LOG(DFATAL) << "Could not login for " << email; | 194 LOG(DFATAL) << "Could not login for " << email; |
| 195 return; | 195 return; |
| 196 } | 196 } |
| 197 | 197 |
| 198 notifier::Subscription subscription; | 198 notifier::Subscription subscription; |
| 199 subscription.channel = kSyncNotificationChannel; | 199 subscription.channel = kSyncP2PNotificationChannel; |
| 200 // There may be some subtle issues around case sensitivity of the | 200 // There may be some subtle issues around case sensitivity of the |
| 201 // from field, but it doesn't matter too much since this is only | 201 // from field, but it doesn't matter too much since this is only |
| 202 // used in p2p mode (which is only used in testing). | 202 // used in p2p mode (which is only used in testing). |
| 203 subscription.from = email; | 203 subscription.from = email; |
| 204 talk_mediator_->AddSubscription(subscription); | 204 talk_mediator_->AddSubscription(subscription); |
| 205 | 205 |
| 206 logged_in_ = true; | 206 logged_in_ = true; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 247 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 248 VLOG(1) << "Received notification " << notification.ToString(); | 248 VLOG(1) << "Received notification " << notification.ToString(); |
| 249 if (!logged_in_) { | 249 if (!logged_in_) { |
| 250 VLOG(1) << "Not logged in yet -- not emitting notification"; | 250 VLOG(1) << "Not logged in yet -- not emitting notification"; |
| 251 return; | 251 return; |
| 252 } | 252 } |
| 253 if (!notifications_enabled_) { | 253 if (!notifications_enabled_) { |
| 254 VLOG(1) << "Notifications not enabled -- not emitting notification"; | 254 VLOG(1) << "Notifications not enabled -- not emitting notification"; |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 if (notification.channel != kSyncNotificationChannel) { | 257 if (notification.channel != kSyncP2PNotificationChannel) { |
| 258 LOG(WARNING) << "Notification from unexpected source " | 258 LOG(WARNING) << "Notification from unexpected source " |
| 259 << notification.channel; | 259 << notification.channel; |
| 260 } | 260 } |
| 261 P2PNotificationData notification_data; | 261 P2PNotificationData notification_data; |
| 262 if (!notification_data.ResetFromString(notification.data)) { | 262 if (!notification_data.ResetFromString(notification.data)) { |
| 263 LOG(WARNING) << "Could not parse notification data from " | 263 LOG(WARNING) << "Could not parse notification data from " |
| 264 << notification.data; | 264 << notification.data; |
| 265 notification_data = | 265 notification_data = |
| 266 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); | 266 P2PNotificationData(unique_id_, NOTIFY_ALL, enabled_types_); |
| 267 } | 267 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 286 | 286 |
| 287 void P2PNotifier::SendNotificationDataForTest( | 287 void P2PNotifier::SendNotificationDataForTest( |
| 288 const P2PNotificationData& notification_data) { | 288 const P2PNotificationData& notification_data) { |
| 289 SendNotificationData(notification_data); | 289 SendNotificationData(notification_data); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void P2PNotifier::SendNotificationData( | 292 void P2PNotifier::SendNotificationData( |
| 293 const P2PNotificationData& notification_data) { | 293 const P2PNotificationData& notification_data) { |
| 294 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 294 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 295 notifier::Notification notification; | 295 notifier::Notification notification; |
| 296 notification.channel = kSyncNotificationChannel; | 296 notification.channel = kSyncP2PNotificationChannel; |
| 297 notification.data = notification_data.ToString(); | 297 notification.data = notification_data.ToString(); |
| 298 VLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 298 VLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 299 talk_mediator_->SendNotification(notification); | 299 talk_mediator_->SendNotification(notification); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace sync_notifier | 302 } // namespace sync_notifier |
| OLD | NEW |