| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/invalidation/p2p_invalidator.h" | 5 #include "components/invalidation/p2p_invalidator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool P2PNotificationData::Equals(const P2PNotificationData& other) const { | 97 bool P2PNotificationData::Equals(const P2PNotificationData& other) const { |
| 98 return | 98 return |
| 99 (sender_id_ == other.sender_id_) && | 99 (sender_id_ == other.sender_id_) && |
| 100 (target_ == other.target_) && | 100 (target_ == other.target_) && |
| 101 (invalidation_map_ == other.invalidation_map_); | 101 (invalidation_map_ == other.invalidation_map_); |
| 102 } | 102 } |
| 103 | 103 |
| 104 std::string P2PNotificationData::ToString() const { | 104 std::string P2PNotificationData::ToString() const { |
| 105 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 105 base::DictionaryValue dict; |
| 106 dict->SetString(kSenderIdKey, sender_id_); | 106 dict.SetString(kSenderIdKey, sender_id_); |
| 107 dict->SetString(kNotificationTypeKey, | 107 dict.SetString(kNotificationTypeKey, P2PNotificationTargetToString(target_)); |
| 108 P2PNotificationTargetToString(target_)); | 108 dict.Set(kInvalidationsKey, invalidation_map_.ToValue().release()); |
| 109 dict->Set(kInvalidationsKey, invalidation_map_.ToValue().release()); | |
| 110 std::string json; | 109 std::string json; |
| 111 base::JSONWriter::Write(dict.get(), &json); | 110 base::JSONWriter::Write(dict, &json); |
| 112 return json; | 111 return json; |
| 113 } | 112 } |
| 114 | 113 |
| 115 bool P2PNotificationData::ResetFromString(const std::string& str) { | 114 bool P2PNotificationData::ResetFromString(const std::string& str) { |
| 116 scoped_ptr<base::Value> data_value(base::JSONReader::Read(str)); | 115 scoped_ptr<base::Value> data_value(base::JSONReader::Read(str)); |
| 117 const base::DictionaryValue* data_dict = NULL; | 116 const base::DictionaryValue* data_dict = NULL; |
| 118 if (!data_value.get() || !data_value->GetAsDictionary(&data_dict)) { | 117 if (!data_value.get() || !data_value->GetAsDictionary(&data_dict)) { |
| 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 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return; | 290 return; |
| 292 } | 291 } |
| 293 notifier::Notification notification; | 292 notifier::Notification notification; |
| 294 notification.channel = kSyncP2PNotificationChannel; | 293 notification.channel = kSyncP2PNotificationChannel; |
| 295 notification.data = notification_data.ToString(); | 294 notification.data = notification_data.ToString(); |
| 296 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 295 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
| 297 push_client_->SendNotification(notification); | 296 push_client_->SendNotification(notification); |
| 298 } | 297 } |
| 299 | 298 |
| 300 } // namespace syncer | 299 } // namespace syncer |
| OLD | NEW |