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 "sync/notifier/p2p_invalidator.h" | 5 #include "sync/notifier/p2p_invalidator.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 bool P2PNotificationData::Equals(const P2PNotificationData& other) const { | 94 bool P2PNotificationData::Equals(const P2PNotificationData& other) const { |
95 return | 95 return |
96 (sender_id_ == other.sender_id_) && | 96 (sender_id_ == other.sender_id_) && |
97 (target_ == other.target_) && | 97 (target_ == other.target_) && |
98 ObjectIdInvalidationMapEquals(invalidation_map_, | 98 ObjectIdInvalidationMapEquals(invalidation_map_, |
99 other.invalidation_map_); | 99 other.invalidation_map_); |
100 } | 100 } |
101 | 101 |
102 std::string P2PNotificationData::ToString() const { | 102 std::string P2PNotificationData::ToString() const { |
103 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); | 103 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
104 dict->SetString(kSenderIdKey, sender_id_); | 104 dict->SetString(kSenderIdKey, sender_id_); |
105 dict->SetString(kNotificationTypeKey, | 105 dict->SetString(kNotificationTypeKey, |
106 P2PNotificationTargetToString(target_)); | 106 P2PNotificationTargetToString(target_)); |
107 dict->Set(kIdInvalidationMapKey, | 107 dict->Set(kIdInvalidationMapKey, |
108 ObjectIdInvalidationMapToValue(invalidation_map_).release()); | 108 ObjectIdInvalidationMapToValue(invalidation_map_).release()); |
109 std::string json; | 109 std::string json; |
110 base::JSONWriter::Write(dict.get(), &json); | 110 base::JSONWriter::Write(dict.get(), &json); |
111 return json; | 111 return json; |
112 } | 112 } |
113 | 113 |
114 bool P2PNotificationData::ResetFromString(const std::string& str) { | 114 bool P2PNotificationData::ResetFromString(const std::string& str) { |
115 scoped_ptr<Value> data_value(base::JSONReader::Read(str)); | 115 scoped_ptr<base::Value> data_value(base::JSONReader::Read(str)); |
116 const base::DictionaryValue* data_dict = NULL; | 116 const base::DictionaryValue* data_dict = NULL; |
117 if (!data_value.get() || !data_value->GetAsDictionary(&data_dict)) { | 117 if (!data_value.get() || !data_value->GetAsDictionary(&data_dict)) { |
118 LOG(WARNING) << "Could not parse " << str << " as a dictionary"; | 118 LOG(WARNING) << "Could not parse " << str << " as a dictionary"; |
119 return false; | 119 return false; |
120 } | 120 } |
121 if (!data_dict->GetString(kSenderIdKey, &sender_id_)) { | 121 if (!data_dict->GetString(kSenderIdKey, &sender_id_)) { |
122 LOG(WARNING) << "Could not find string value for " << kSenderIdKey; | 122 LOG(WARNING) << "Could not find string value for " << kSenderIdKey; |
123 } | 123 } |
124 std::string target_str; | 124 std::string target_str; |
125 if (!data_dict->GetString(kNotificationTypeKey, &target_str)) { | 125 if (!data_dict->GetString(kNotificationTypeKey, &target_str)) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 return; | 289 return; |
290 } | 290 } |
291 notifier::Notification notification; | 291 notifier::Notification notification; |
292 notification.channel = kSyncP2PNotificationChannel; | 292 notification.channel = kSyncP2PNotificationChannel; |
293 notification.data = notification_data.ToString(); | 293 notification.data = notification_data.ToString(); |
294 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 294 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); |
295 push_client_->SendNotification(notification); | 295 push_client_->SendNotification(notification); |
296 } | 296 } |
297 | 297 |
298 } // namespace syncer | 298 } // namespace syncer |
OLD | NEW |