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
3 // found in the LICENSE file.
5 #include "jingle/notifier/listener/notification_defines.h"
9 #include "base/json/string_escape.h"
10 #include "base/logging.h"
11 #include "base/strings/string_util.h"
12 #include "base/values.h"
16 Subscription::Subscription() {}
17 Subscription::~Subscription() {}
19 bool Subscription::Equals(const Subscription
& other
) const {
20 return channel
== other
.channel
&& from
== other
.from
;
26 bool ListsEqual(const T
& t1
, const T
& t2
) {
27 if (t1
.size() != t2
.size()) {
30 for (size_t i
= 0; i
< t1
.size(); ++i
) {
31 if (!t1
[i
].Equals(t2
[i
])) {
40 bool SubscriptionListsEqual(const SubscriptionList
& subscriptions1
,
41 const SubscriptionList
& subscriptions2
) {
42 return ListsEqual(subscriptions1
, subscriptions2
);
45 Recipient::Recipient() {}
46 Recipient::~Recipient() {}
48 bool Recipient::Equals(const Recipient
& other
) const {
49 return to
== other
.to
&& user_specific_data
== other
.user_specific_data
;
52 bool RecipientListsEqual(const RecipientList
& recipients1
,
53 const RecipientList
& recipients2
) {
54 return ListsEqual(recipients1
, recipients2
);
57 Notification::Notification() {}
58 Notification::~Notification() {}
60 bool Notification::Equals(const Notification
& other
) const {
62 channel
== other
.channel
&&
64 RecipientListsEqual(recipients
, other
.recipients
);
67 std::string
Notification::ToString() const {
68 // |channel| or |data| could hold binary data, so convert all non-ASCII
69 // characters to escape sequences.
70 const std::string
& printable_channel
=
71 base::EscapeBytesAsInvalidJSONString(channel
, true /* put_in_quotes */);
72 const std::string
& printable_data
=
73 base::EscapeBytesAsInvalidJSONString(data
, true /* put_in_quotes */);
75 "{ channel: " + printable_channel
+ ", data: " + printable_data
+ " }";
78 } // namespace notifier