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

Side by Side Diff: remoting/host/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: 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 (c) 2015 The Chromium Authors. All rights reserved.
Sergey Ulanov 2015/05/07 18:22:38 remove (c)
John Williams 2015/05/15 00:51:12 Done.
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/host/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 "third_party/webrtc/libjingle/xmllite/xmlelement.h"
12
13 namespace remoting {
14
15 namespace {
16
17 const char kNsGooglePush[] = "google:push";
18
19 } // namespace
20
21 GcdNotificationSubscriber::GcdNotificationSubscriber(
22 SignalStrategy* signal_strategy)
23 : signal_strategy_(signal_strategy) {
24 signal_strategy_->AddListener(this);
25 }
26
27 GcdNotificationSubscriber::~GcdNotificationSubscriber() {
28 signal_strategy_->RemoveListener(this);
29 }
30
31 void GcdNotificationSubscriber::OnSignalStrategyStateChange(
32 SignalStrategy::State state) {
33 if (state == SignalStrategy::CONNECTED) {
34 DLOG(INFO) << "subscribing to GCD command notifications";
Sergey Ulanov 2015/05/07 18:22:38 nit: s/subscribing/Subscribing/ Add . at the end
John Williams 2015/05/15 00:51:12 Done.
35
36 // Convert full JID to bare JID.
37 std::string bare_jid = signal_strategy_->GetLocalJid();
38 size_t slash_index = bare_jid.find('/');
Sergey Ulanov 2015/05/07 18:22:38 There are at least two other places where we need
John Williams 2015/05/15 00:51:12 Done.
39 if (slash_index != std::string::npos) {
40 bare_jid.resize(slash_index);
41 }
42
43 // Build a subscription request.
44 buzz::XmlElement* itemElement =
Sergey Ulanov 2015/05/07 18:22:38 item_element
John Williams 2015/05/15 00:51:12 Done.
45 new buzz::XmlElement(buzz::QName(kNsGooglePush, "item"));
46 itemElement->SetAttr(buzz::QName("", "channel"), "cloud_devices");
47 itemElement->SetAttr(buzz::QName("", "from"), "");
48 buzz::XmlElement* subscribeElement =
Sergey Ulanov 2015/05/07 18:22:38 subscribe_element. In other code that builds XmlEl
John Williams 2015/05/15 00:51:11 Done.
49 new buzz::XmlElement(buzz::QName(kNsGooglePush, "subscribe"));
50 subscribeElement->AddElement(itemElement);
51
52 // Send the request.
53 iq_sender_.reset(new IqSender(signal_strategy_));
54 iq_request_ = iq_sender_->SendIq(
55 "set", bare_jid, make_scoped_ptr(subscribeElement),
56 base::Bind(&GcdNotificationSubscriber::OnSubscriptionResult,
57 base::Unretained(this)));
58 }
59 }
60
61 bool GcdNotificationSubscriber::OnSignalStrategyIncomingStanza(
62 const buzz::XmlElement* stanza) {
63 // Ignore all XMPP stanzas.
64 return false;
65 }
66
67 void GcdNotificationSubscriber::OnSubscriptionResult(
68 IqRequest* request,
69 const buzz::XmlElement* response) {
70 DCHECK_EQ(response->Attr(buzz::QName("", "type")), "result")
Sergey Ulanov 2015/05/07 18:22:38 This shouldn't be DCHECK. Crashing in response to
John Williams 2015/05/15 00:51:12 Done.
71 << "invalid response type";
72
73 // The IqSender and IqRequest are no longer needed after receiving a
74 // reply to the subscription request.
75 iq_request_.reset();
76 iq_sender_.reset();
77 }
78
79 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698