1// Copyright (c) 2013 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#ifndef REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H 6#define REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H 7 8#include <string> 9 10#include "base/compiler_specific.h" 11#include "base/memory/scoped_ptr.h" 12#include "base/memory/weak_ptr.h" 13#include "remoting/jingle_glue/signal_strategy.h" 14 15namespace buzz { 16class XmlElement; 17} // namespace buzz 18 19namespace remoting { 20 21// HostChangeNotificationListener listens for messages from the remoting bot 22// indicating that its host entry has been changed in the directory. 23// If a message is received indicating that the host was deleted, it uses the 24// OnHostDeleted callback to shut down the host. 25class HostChangeNotificationListener : public SignalStrategy::Listener { 26 public: 27 class Listener { 28 protected: 29 virtual ~Listener() {} 30 // Invoked when a notification that the host was deleted is received. 31 public: 32 virtual void OnHostDeleted() = 0; 33 }; 34 35 // Both listener and signal_strategy are expected to outlive this object. 36 HostChangeNotificationListener(Listener* listener, 37 const std::string& host_id, 38 SignalStrategy* signal_strategy, 39 const std::string& directory_bot_jid); 40 virtual ~HostChangeNotificationListener(); 41 42 // SignalStrategy::Listener interface. 43 virtual void OnSignalStrategyStateChange( 44 SignalStrategy::State state) OVERRIDE; 45 virtual bool OnSignalStrategyIncomingStanza( 46 const buzz::XmlElement* stanza) OVERRIDE; 47 48 private: 49 void OnHostDeleted(); 50 51 Listener* listener_; 52 std::string host_id_; 53 SignalStrategy* signal_strategy_; 54 std::string directory_bot_jid_; 55 base::WeakPtrFactory<HostChangeNotificationListener> weak_factory_; 56 DISALLOW_COPY_AND_ASSIGN(HostChangeNotificationListener); 57}; 58 59} // namespace remoting 60 61#endif // REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H 62