OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/signaling/push_notification_subscriber.h" | 5 #include "remoting/signaling/push_notification_subscriber.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "remoting/base/logging.h" | 10 #include "remoting/base/logging.h" |
11 #include "remoting/signaling/iq_sender.h" | 11 #include "remoting/signaling/iq_sender.h" |
12 #include "remoting/signaling/jid_util.h" | 12 #include "remoting/signaling/jid_util.h" |
| 13 #include "remoting/signaling/signaling_address.h" |
13 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" | 14 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
14 | 15 |
15 namespace remoting { | 16 namespace remoting { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const char kGooglePushNamespace[] = "google:push"; | 20 const char kGooglePushNamespace[] = "google:push"; |
20 | 21 |
21 } // namespace | 22 } // namespace |
22 | 23 |
23 PushNotificationSubscriber::Subscription::Subscription() { | 24 PushNotificationSubscriber::Subscription::Subscription() {} |
24 } | 25 PushNotificationSubscriber::Subscription::~Subscription() {} |
25 | |
26 PushNotificationSubscriber::Subscription::~Subscription() { | |
27 } | |
28 | 26 |
29 PushNotificationSubscriber::PushNotificationSubscriber( | 27 PushNotificationSubscriber::PushNotificationSubscriber( |
30 SignalStrategy* signal_strategy, | 28 SignalStrategy* signal_strategy, |
31 const SubscriptionList& subscriptions) | 29 const SubscriptionList& subscriptions) |
32 : signal_strategy_(signal_strategy), subscriptions_(subscriptions) { | 30 : signal_strategy_(signal_strategy), subscriptions_(subscriptions) { |
33 signal_strategy_->AddListener(this); | 31 signal_strategy_->AddListener(this); |
34 } | 32 } |
35 | 33 |
36 PushNotificationSubscriber::~PushNotificationSubscriber() { | 34 PushNotificationSubscriber::~PushNotificationSubscriber() { |
37 signal_strategy_->RemoveListener(this); | 35 signal_strategy_->RemoveListener(this); |
(...skipping 13 matching lines...) Expand all Loading... |
51 const buzz::XmlElement* stanza) { | 49 const buzz::XmlElement* stanza) { |
52 // Ignore all XMPP stanzas. | 50 // Ignore all XMPP stanzas. |
53 return false; | 51 return false; |
54 } | 52 } |
55 | 53 |
56 void PushNotificationSubscriber::Subscribe(const Subscription& subscription) { | 54 void PushNotificationSubscriber::Subscribe(const Subscription& subscription) { |
57 VLOG(0) << "Subscribing to push notifications on channel: " | 55 VLOG(0) << "Subscribing to push notifications on channel: " |
58 << subscription.channel << "."; | 56 << subscription.channel << "."; |
59 | 57 |
60 std::string bare_jid; | 58 std::string bare_jid; |
61 SplitJidResource(signal_strategy_->GetLocalJid(), &bare_jid, nullptr); | 59 SplitJidResource(signal_strategy_->GetLocalAddress().jid(), &bare_jid, |
| 60 nullptr); |
62 | 61 |
63 // Build a subscription request. | 62 // Build a subscription request. |
64 buzz::XmlElement* subscribe_element = | 63 buzz::XmlElement* subscribe_element = |
65 new buzz::XmlElement(buzz::QName(kGooglePushNamespace, "subscribe")); | 64 new buzz::XmlElement(buzz::QName(kGooglePushNamespace, "subscribe")); |
66 buzz::XmlElement* item_element = | 65 buzz::XmlElement* item_element = |
67 new buzz::XmlElement(buzz::QName(kGooglePushNamespace, "item")); | 66 new buzz::XmlElement(buzz::QName(kGooglePushNamespace, "item")); |
68 subscribe_element->AddElement(item_element); | 67 subscribe_element->AddElement(item_element); |
69 item_element->SetAttr(buzz::QName(std::string(), "channel"), | 68 item_element->SetAttr(buzz::QName(std::string(), "channel"), |
70 subscription.channel); | 69 subscription.channel); |
71 item_element->SetAttr(buzz::QName(std::string(), "from"), subscription.from); | 70 item_element->SetAttr(buzz::QName(std::string(), "from"), subscription.from); |
(...skipping 15 matching lines...) Expand all Loading... |
87 LOG(ERROR) << "Invalid response type for subscription: " << response_type; | 86 LOG(ERROR) << "Invalid response type for subscription: " << response_type; |
88 } | 87 } |
89 | 88 |
90 // The IqSender and IqRequest are no longer needed after receiving a | 89 // The IqSender and IqRequest are no longer needed after receiving a |
91 // reply to the subscription request. | 90 // reply to the subscription request. |
92 iq_request_.reset(); | 91 iq_request_.reset(); |
93 iq_sender_.reset(); | 92 iq_sender_.reset(); |
94 } | 93 } |
95 | 94 |
96 } // namespace remoting | 95 } // namespace remoting |
OLD | NEW |