summaryrefslogtreecommitdiffstats
path: root/remoting/host/host_status_service.h
blob: 2e2d083d138f1ce5dcb042f01c602f7b2761e7ee (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
61
62
63
// Copyright (c) 2012 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_STATUS_SERVICE_H_
#define REMOTING_HOST_HOST_STATUS_SERVICE_H_

#include <string>

#include "base/memory/scoped_ptr.h"
#include "remoting/host/websocket_listener.h"

namespace base {
class DictionaryValue;
}  // namespace remoting

namespace remoting {

// HostStatusService implements a WebSocket server for the remoting web app to
// use to query the current status of the host.
class HostStatusService {
 public:
  HostStatusService();
  ~HostStatusService();

  // Must be called whenever state of the host changes.
  void SetHostIsUp(const std::string& host_id);
  void SetHostIsDown();

 private:
  class Connection;
  friend class Connection;

  // Returns true if |origin| is one of the remoting extension URLs.
  static bool IsAllowedOrigin(const std::string& origin);

  // Callback from WebsocketListener.
  void OnNewConnection(scoped_ptr<WebSocketConnection> connection);

  // Called from Connection instances when |connection| is closed and the
  // Connection object should be destroyed.
  void OnConnectionClosed(Connection* connection);

  // Creates a status message that should be sent as a response to an incoming
  // getHostState message.
  scoped_ptr<base::DictionaryValue> GetStatusMessage();

  WebSocketListener websocket_listener_;
  std::set<Connection*> connections_;

  // Host name we expect in incoming connections, e.g. "localhost:12810".
  std::string service_host_name_;

  // Current state of the host to provide to clients.
  bool started_;
  std::string host_id_;

  DISALLOW_COPY_AND_ASSIGN(HostStatusService);
};

}  // namespace remoting

#endif  // REMOTING_HOST_HOST_STATUS_SERVICE_H_