• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "jingle/notifier/listener/notification_defines.h"
6 
7 #include <cstddef>
8 
9 #include "base/json/string_escape.h"
10 #include "base/logging.h"
11 #include "base/strings/string_util.h"
12 #include "base/values.h"
13 
14 namespace notifier {
15 
Subscription()16 Subscription::Subscription() {}
~Subscription()17 Subscription::~Subscription() {}
18 
Equals(const Subscription & other) const19 bool Subscription::Equals(const Subscription& other) const {
20   return channel == other.channel && from == other.from;
21 }
22 
23 namespace {
24 
25 template <typename T>
ListsEqual(const T & t1,const T & t2)26 bool ListsEqual(const T& t1, const T& t2) {
27   if (t1.size() != t2.size()) {
28     return false;
29   }
30   for (size_t i = 0; i < t1.size(); ++i) {
31     if (!t1[i].Equals(t2[i])) {
32       return false;
33     }
34   }
35   return true;
36 }
37 
38 }  // namespace
39 
SubscriptionListsEqual(const SubscriptionList & subscriptions1,const SubscriptionList & subscriptions2)40 bool SubscriptionListsEqual(const SubscriptionList& subscriptions1,
41                             const SubscriptionList& subscriptions2) {
42   return ListsEqual(subscriptions1, subscriptions2);
43 }
44 
Recipient()45 Recipient::Recipient() {}
~Recipient()46 Recipient::~Recipient() {}
47 
Equals(const Recipient & other) const48 bool Recipient::Equals(const Recipient& other) const {
49   return to == other.to && user_specific_data == other.user_specific_data;
50 }
51 
RecipientListsEqual(const RecipientList & recipients1,const RecipientList & recipients2)52 bool RecipientListsEqual(const RecipientList& recipients1,
53                          const RecipientList& recipients2) {
54   return ListsEqual(recipients1, recipients2);
55 }
56 
Notification()57 Notification::Notification() {}
~Notification()58 Notification::~Notification() {}
59 
Equals(const Notification & other) const60 bool Notification::Equals(const Notification& other) const {
61   return
62       channel == other.channel &&
63       data == other.data &&
64       RecipientListsEqual(recipients, other.recipients);
65 }
66 
ToString() const67 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 */);
74   return
75       "{ channel: " + printable_channel + ", data: " + printable_data + " }";
76 }
77 
78 }  // namespace notifier
79