Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / remoting / host / log_to_server.h
1 // Copyright (c) 2012 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_LOG_TO_SERVER_H_
6 #define REMOTING_HOST_LOG_TO_SERVER_H_
7
8 #include <deque>
9 #include <map>
10 #include <string>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/host/host_status_observer.h"
16 #include "remoting/jingle_glue/server_log_entry.h"
17 #include "remoting/jingle_glue/signal_strategy.h"
18 #include "remoting/protocol/transport.h"
19
20 namespace base {
21 class MessageLoopProxy;
22 }  // namespace base
23
24 namespace buzz {
25 class XmlElement;
26 }  // namespace buzz
27
28 namespace remoting {
29
30 class HostStatusMonitor;
31 class IqSender;
32
33 // LogToServer sends log entries to a server.
34 // The contents of the log entries are described in server_log_entry.cc.
35 // They do not contain any personally identifiable information.
36 class LogToServer : public base::NonThreadSafe,
37                     public HostStatusObserver,
38                     public SignalStrategy::Listener {
39  public:
40   explicit LogToServer(base::WeakPtr<HostStatusMonitor> monitor,
41                        ServerLogEntry::Mode mode,
42                        SignalStrategy* signal_strategy,
43                        const std::string& directory_bot_jid);
44   virtual ~LogToServer();
45
46   // Logs a session state change. Currently, this is either
47   // connection or disconnection.
48   void LogSessionStateChange(const std::string& jid, bool connected);
49
50   // SignalStrategy::Listener interface.
51   virtual void OnSignalStrategyStateChange(
52       SignalStrategy::State state) OVERRIDE;
53   virtual bool OnSignalStrategyIncomingStanza(
54       const buzz::XmlElement* stanza) OVERRIDE;
55
56   // HostStatusObserver interface.
57   virtual void OnClientConnected(const std::string& jid) OVERRIDE;
58   virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;
59   virtual void OnClientRouteChange(
60       const std::string& jid,
61       const std::string& channel_name,
62       const protocol::TransportRoute& route) OVERRIDE;
63
64  private:
65   void Log(const ServerLogEntry& entry);
66   void SendPendingEntries();
67
68   base::WeakPtr<HostStatusMonitor> monitor_;
69   ServerLogEntry::Mode mode_;
70   SignalStrategy* signal_strategy_;
71   scoped_ptr<IqSender> iq_sender_;
72   std::string directory_bot_jid_;
73
74   // A map from client JID to the route type of that client's connection to
75   // this host.
76   std::map<std::string, protocol::TransportRoute::RouteType>
77       connection_route_type_;
78   std::deque<ServerLogEntry> pending_entries_;
79
80   DISALLOW_COPY_AND_ASSIGN(LogToServer);
81 };
82
83 }  // namespace remoting
84
85 #endif  // REMOTING_HOST_LOG_TO_SERVER_H_