| OLD | NEW |
| 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 "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/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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 dict->SetString(kSenderIdKey, sender_id_); | 102 dict->SetString(kSenderIdKey, sender_id_); |
| 103 dict->SetString(kNotificationTypeKey, | 103 dict->SetString(kNotificationTypeKey, |
| 104 P2PNotificationTargetToString(target_)); | 104 P2PNotificationTargetToString(target_)); |
| 105 dict->Set(kChangedTypesKey, syncable::ModelTypeSetToValue(changed_types_)); | 105 dict->Set(kChangedTypesKey, syncable::ModelTypeSetToValue(changed_types_)); |
| 106 std::string json; | 106 std::string json; |
| 107 base::JSONWriter::Write(dict.get(), &json); | 107 base::JSONWriter::Write(dict.get(), &json); |
| 108 return json; | 108 return json; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool P2PNotificationData::ResetFromString(const std::string& str) { | 111 bool P2PNotificationData::ResetFromString(const std::string& str) { |
| 112 scoped_ptr<Value> data_value( | 112 scoped_ptr<Value> data_value(base::JSONReader::Read(str)); |
| 113 base::JSONReader::Read(str, false /* allow_trailing_comma */)); | |
| 114 if (!data_value.get()) { | 113 if (!data_value.get()) { |
| 115 LOG(WARNING) << "Could not parse " << str; | 114 LOG(WARNING) << "Could not parse " << str; |
| 116 return false; | 115 return false; |
| 117 } | 116 } |
| 118 if (!data_value->IsType(Value::TYPE_DICTIONARY)) { | 117 if (!data_value->IsType(Value::TYPE_DICTIONARY)) { |
| 119 LOG(WARNING) << "Could not parse " << str << " as a dictionary"; | 118 LOG(WARNING) << "Could not parse " << str << " as a dictionary"; |
| 120 return false; | 119 return false; |
| 121 } | 120 } |
| 122 // TODO(akalin): Use Values::AsDictionary() when it becomes | 121 // TODO(akalin): Use Values::AsDictionary() when it becomes |
| 123 // available. | 122 // available. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 const P2PNotificationData& notification_data) { | 292 const P2PNotificationData& notification_data) { |
| 294 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 293 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
| 295 notifier::Notification notification; | 294 notifier::Notification notification; |
| 296 notification.channel = kSyncP2PNotificationChannel; | 295 notification.channel = kSyncP2PNotificationChannel; |
| 297 notification.data = notification_data.ToString(); | 296 notification.data = notification_data.ToString(); |
| 298 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 297 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 299 talk_mediator_->SendNotification(notification); | 298 talk_mediator_->SendNotification(notification); |
| 300 } | 299 } |
| 301 | 300 |
| 302 } // namespace sync_notifier | 301 } // namespace sync_notifier |
| OLD | NEW |