summaryrefslogtreecommitdiffstats
path: root/remoting/jingle_glue/fake_signal_strategy.h
blob: 553313e335d5ee027031cf6320f170e7ca59e3e5 (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
// Copyright (c) 2011 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_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
#define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_

#include <queue>
#include <string>

#include "base/task.h"
#include "base/threading/non_thread_safe.h"
#include "remoting/jingle_glue/javascript_iq_request.h"
#include "remoting/jingle_glue/signal_strategy.h"

namespace remoting {

class FakeSignalStrategy : public SignalStrategy,
                           public base::NonThreadSafe {
 public:
  static void Connect(FakeSignalStrategy* peer1, FakeSignalStrategy* peer2);

  FakeSignalStrategy(const std::string& jid);
  virtual ~FakeSignalStrategy();

  // SignalStrategy interface.
  virtual void Init(StatusObserver* observer) OVERRIDE;
  virtual void Close() OVERRIDE;
  virtual void SetListener(Listener* listener) OVERRIDE;
  virtual void SendStanza(buzz::XmlElement* stanza) OVERRIDE;
  virtual std::string GetNextId() OVERRIDE;
  virtual IqRequest* CreateIqRequest() OVERRIDE;

 private:
  // Called by the |peer_|. Takes ownership of |stanza|.
  void OnIncomingMessage(buzz::XmlElement* stanza);

  void DeliverIncomingMessages();

  std::string jid_;
  FakeSignalStrategy* peer_;
  Listener* listener_;
  JavascriptIqRegistry iq_registry_;

  int last_id_;

  std::queue<buzz::XmlElement*> pending_messages_;

  ScopedRunnableMethodFactory<FakeSignalStrategy> task_factory_;

  DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);
};

}  // namespace remoting

#endif  // REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_