OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/signaling/push_notification_subscriber.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/callback.h" | |
9 #include "remoting/base/logging.h" | |
10 #include "remoting/signaling/iq_sender.h" | |
11 #include "remoting/signaling/jid_util.h" | |
12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | |
13 | |
14 namespace remoting { | |
15 | |
16 namespace { | |
17 | |
18 const char kNsGooglePush[] = "google:push"; | |
Sergey Ulanov
2015/05/16 00:56:08
maybe call it kGooglePushNamespace?
John Williams
2015/05/16 02:10:06
Done.
| |
19 | |
20 } // namespace | |
21 | |
22 PushNotificationSubscriber::PushNotificationSubscriber( | |
23 SignalStrategy* signal_strategy, | |
24 const std::string& push_channel) | |
25 : signal_strategy_(signal_strategy), push_channel_(push_channel) { | |
26 signal_strategy_->AddListener(this); | |
27 } | |
28 | |
29 PushNotificationSubscriber::~PushNotificationSubscriber() { | |
30 signal_strategy_->RemoveListener(this); | |
31 } | |
32 | |
33 void PushNotificationSubscriber::OnSignalStrategyStateChange( | |
34 SignalStrategy::State state) { | |
35 if (state == SignalStrategy::CONNECTED) { | |
36 HOST_LOG << "Subscribing to push notifications on channel: " | |
Sergey Ulanov
2015/05/16 00:56:08
I think this should be VLOG()
John Williams
2015/05/16 02:10:06
Done.
| |
37 << push_channel_ << "."; | |
38 | |
39 std::string bare_jid; | |
40 SplitJidResource(signal_strategy_->GetLocalJid(), &bare_jid, nullptr); | |
41 | |
42 // Build a subscription request. | |
43 buzz::XmlElement* subscribe_element = | |
44 new buzz::XmlElement(buzz::QName(kNsGooglePush, "subscribe")); | |
45 buzz::XmlElement* item_element = | |
46 new buzz::XmlElement(buzz::QName(kNsGooglePush, "item")); | |
47 subscribe_element->AddElement(item_element); | |
48 item_element->SetAttr(buzz::QName("", "channel"), push_channel_); | |
Sergey Ulanov
2015/05/16 00:56:08
here and everywhere else: use std::string() instea
John Williams
2015/05/16 02:10:06
Done.
| |
49 item_element->SetAttr(buzz::QName("", "from"), ""); | |
50 | |
51 // Send the request. | |
52 iq_sender_.reset(new IqSender(signal_strategy_)); | |
53 iq_request_ = iq_sender_->SendIq( | |
54 "set", bare_jid, make_scoped_ptr(subscribe_element), | |
55 base::Bind(&PushNotificationSubscriber::OnSubscriptionResult, | |
56 base::Unretained(this))); | |
57 } | |
58 } | |
59 | |
60 bool PushNotificationSubscriber::OnSignalStrategyIncomingStanza( | |
61 const buzz::XmlElement* stanza) { | |
62 // Ignore all XMPP stanzas. | |
63 return false; | |
64 } | |
65 | |
66 void PushNotificationSubscriber::OnSubscriptionResult( | |
67 IqRequest* request, | |
68 const buzz::XmlElement* response) { | |
69 std::string response_type = response->Attr(buzz::QName("", "type")); | |
70 if (response_type != "result") { | |
71 LOG(ERROR) << "Invalid response type for subscription: " << response_type; | |
72 } | |
73 | |
74 // The IqSender and IqRequest are no longer needed after receiving a | |
75 // reply to the subscription request. | |
76 iq_request_.reset(); | |
77 iq_sender_.reset(); | |
78 } | |
79 | |
80 } // namespace remoting | |
OLD | NEW |