| Index: remoting/signaling/gcd_notification_subscriber.cc
|
| diff --git a/remoting/signaling/gcd_notification_subscriber.cc b/remoting/signaling/gcd_notification_subscriber.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a74a27f48f52c9934bf987376d1c8f3c297faf63
|
| --- /dev/null
|
| +++ b/remoting/signaling/gcd_notification_subscriber.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "remoting/signaling/gcd_notification_subscriber.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback.h"
|
| +#include "remoting/base/logging.h"
|
| +#include "remoting/signaling/iq_sender.h"
|
| +#include "remoting/signaling/jid_util.h"
|
| +#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
|
| +
|
| +namespace remoting {
|
| +
|
| +namespace {
|
| +
|
| +const char kNsGooglePush[] = "google:push";
|
| +
|
| +} // namespace
|
| +
|
| +GcdNotificationSubscriber::GcdNotificationSubscriber(
|
| + SignalStrategy* signal_strategy)
|
| + : signal_strategy_(signal_strategy) {
|
| + signal_strategy_->AddListener(this);
|
| +}
|
| +
|
| +GcdNotificationSubscriber::~GcdNotificationSubscriber() {
|
| + signal_strategy_->RemoveListener(this);
|
| +}
|
| +
|
| +void GcdNotificationSubscriber::OnSignalStrategyStateChange(
|
| + SignalStrategy::State state) {
|
| + if (state == SignalStrategy::CONNECTED) {
|
| + HOST_LOG << "Subscribing to GCD command notifications.";
|
| +
|
| + std::string bare_jid;
|
| + SplitJidResource(signal_strategy_->GetLocalJid(), &bare_jid, nullptr);
|
| +
|
| + // Build a subscription request.
|
| + buzz::XmlElement* subscribe_element =
|
| + new buzz::XmlElement(buzz::QName(kNsGooglePush, "subscribe"));
|
| + buzz::XmlElement* item_element =
|
| + new buzz::XmlElement(buzz::QName(kNsGooglePush, "item"));
|
| + subscribe_element->AddElement(item_element);
|
| + item_element->SetAttr(buzz::QName("", "channel"), "cloud_devices");
|
| + item_element->SetAttr(buzz::QName("", "from"), "");
|
| +
|
| + // Send the request.
|
| + iq_sender_.reset(new IqSender(signal_strategy_));
|
| + iq_request_ = iq_sender_->SendIq(
|
| + "set", bare_jid, make_scoped_ptr(subscribe_element),
|
| + base::Bind(&GcdNotificationSubscriber::OnSubscriptionResult,
|
| + base::Unretained(this)));
|
| + }
|
| +}
|
| +
|
| +bool GcdNotificationSubscriber::OnSignalStrategyIncomingStanza(
|
| + const buzz::XmlElement* stanza) {
|
| + // Ignore all XMPP stanzas.
|
| + return false;
|
| +}
|
| +
|
| +void GcdNotificationSubscriber::OnSubscriptionResult(
|
| + IqRequest* request,
|
| + const buzz::XmlElement* response) {
|
| + std::string response_type = response->Attr(buzz::QName("", "type"));
|
| + if (response_type != "result") {
|
| + LOG(ERROR) << "Invalid response type for subscription: " << response_type;
|
| + }
|
| +
|
| + // The IqSender and IqRequest are no longer needed after receiving a
|
| + // reply to the subscription request.
|
| + iq_request_.reset();
|
| + iq_sender_.reset();
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|