Chromium Code Reviews| Index: remoting/host/host_status_service.h |
| diff --git a/remoting/host/host_status_service.h b/remoting/host/host_status_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2d9a233e0f33cf9652a00485e512f450325489a |
| --- /dev/null |
| +++ b/remoting/host/host_status_service.h |
| @@ -0,0 +1,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 WebSocket server that communicates with the |
| +// remoting web app and lets it get current status of the host. |
|
Wez
2012/11/20 05:55:53
nit: "HostStatusService implements a WebSocket ser
Sergey Ulanov
2012/11/22 00:29:35
Done.
|
| +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; |
| + |
| + // A helper to validate origin of an incoming connection. |
| + 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_ |