summaryrefslogtreecommitdiffstats
path: root/remoting/host/host_change_notification_listener.h
blob: 26f19390586176002098d4d0d4153a232581923e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2013 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.

#ifndef REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H
#define REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H

#include <string>

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "remoting/signaling/signal_strategy.h"

namespace buzz {
class XmlElement;
}  // namespace buzz

namespace remoting {

// HostChangeNotificationListener listens for messages from the remoting bot
// indicating that its host entry has been changed in the directory.
// If a message is received indicating that the host was deleted, it uses the
// OnHostDeleted callback to shut down the host.
class HostChangeNotificationListener : public SignalStrategy::Listener {
 public:
  class Listener {
   protected:
    virtual ~Listener() {}
    // Invoked when a notification that the host was deleted is received.
   public:
    virtual void OnHostDeleted() = 0;
  };

  // Both listener and signal_strategy are expected to outlive this object.
  HostChangeNotificationListener(Listener* listener,
                                 const std::string& host_id,
                                 SignalStrategy* signal_strategy,
                                 const std::string& directory_bot_jid);
  ~HostChangeNotificationListener() override;

  // SignalStrategy::Listener interface.
  void OnSignalStrategyStateChange(SignalStrategy::State state) override;
  bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override;

 private:
  void OnHostDeleted();

  Listener* listener_;
  std::string host_id_;
  SignalStrategy* signal_strategy_;
  std::string directory_bot_jid_;
  base::WeakPtrFactory<HostChangeNotificationListener> weak_factory_;
  DISALLOW_COPY_AND_ASSIGN(HostChangeNotificationListener);
};

}  // namespace remoting

#endif  // REMOTING_HOST_HOST_CHANGE_NOTIFICATION_LISTENER_H