Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: remoting/signaling/gcd_notification_subscriber.cc

Issue 1123153002: Added class to subscribe to GCD notifications over XMPP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-xmpp-connect2a
Patch Set: revised unit test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/gcd_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";
19
20 } // namespace
21
22 GcdNotificationSubscriber::GcdNotificationSubscriber(
23 SignalStrategy* signal_strategy)
24 : signal_strategy_(signal_strategy) {
25 signal_strategy_->AddListener(this);
26 }
27
28 GcdNotificationSubscriber::~GcdNotificationSubscriber() {
29 signal_strategy_->RemoveListener(this);
30 }
31
32 void GcdNotificationSubscriber::OnSignalStrategyStateChange(
33 SignalStrategy::State state) {
34 if (state == SignalStrategy::CONNECTED) {
35 HOST_LOG << "Subscribing to GCD command notifications.";
36
37 std::string bare_jid;
38 SplitJidResource(signal_strategy_->GetLocalJid(), &bare_jid, nullptr);
39
40 // Build a subscription request.
41 buzz::XmlElement* subscribe_element =
42 new buzz::XmlElement(buzz::QName(kNsGooglePush, "subscribe"));
43 buzz::XmlElement* item_element =
44 new buzz::XmlElement(buzz::QName(kNsGooglePush, "item"));
45 subscribe_element->AddElement(item_element);
46 item_element->SetAttr(buzz::QName("", "channel"), "cloud_devices");
47 item_element->SetAttr(buzz::QName("", "from"), "");
48
49 // Send the request.
50 iq_sender_.reset(new IqSender(signal_strategy_));
51 iq_request_ = iq_sender_->SendIq(
52 "set", bare_jid, make_scoped_ptr(subscribe_element),
53 base::Bind(&GcdNotificationSubscriber::OnSubscriptionResult,
54 base::Unretained(this)));
55 }
56 }
57
58 bool GcdNotificationSubscriber::OnSignalStrategyIncomingStanza(
59 const buzz::XmlElement* stanza) {
60 // Ignore all XMPP stanzas.
61 return false;
62 }
63
64 void GcdNotificationSubscriber::OnSubscriptionResult(
65 IqRequest* request,
66 const buzz::XmlElement* response) {
67 std::string response_type = response->Attr(buzz::QName("", "type"));
68 if (response_type != "result") {
69 LOG(ERROR) << "Invalid response type for subscription: " << response_type;
70 }
71
72 // The IqSender and IqRequest are no longer needed after receiving a
73 // reply to the subscription request.
74 iq_request_.reset();
75 iq_sender_.reset();
76 }
77
78 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698