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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 changed_types_.Equals(other.changed_types_); | 97 changed_types_.Equals(other.changed_types_); |
98 } | 98 } |
99 | 99 |
100 std::string P2PNotificationData::ToString() const { | 100 std::string P2PNotificationData::ToString() const { |
101 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); | 101 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); |
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(), false /* pretty_print */, &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( |
113 base::JSONReader::Read(str, false /* allow_trailing_comma */)); | 113 base::JSONReader::Read(str, false /* allow_trailing_comma */)); |
114 if (!data_value.get()) { | 114 if (!data_value.get()) { |
115 LOG(WARNING) << "Could not parse " << str; | 115 LOG(WARNING) << "Could not parse " << str; |
116 return false; | 116 return false; |
117 } | 117 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = kSyncP2PNotificationChannel; | 296 notification.channel = kSyncP2PNotificationChannel; |
297 notification.data = notification_data.ToString(); | 297 notification.data = notification_data.ToString(); |
298 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); | 298 DVLOG(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 |