1 // Copyright 2014 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.
5 #ifndef REMOTING_CLIENT_LOG_TO_SERVER_H_
6 #define REMOTING_CLIENT_LOG_TO_SERVER_H_
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/time.h"
14 #include "remoting/client/server_log_entry.h"
15 #include "remoting/jingle_glue/signal_strategy.h"
16 #include "remoting/protocol/connection_to_host.h"
17 #include "remoting/protocol/errors.h"
25 class ChromotingStats;
28 // Temporary namespace to prevent conflict with the same-named class in
29 // remoting/host when linking unittests.
31 // TODO(lambroslambrou): Remove this and factor out any shared code.
34 // LogToServer sends log entries to a server.
35 // The contents of the log entries are described in server_log_entry.cc.
36 // They do not contain any personally identifiable information.
37 class LogToServer : public base::NonThreadSafe,
38 public SignalStrategy::Listener {
40 LogToServer(ServerLogEntry::Mode mode,
41 SignalStrategy* signal_strategy,
42 const std::string& directory_bot_jid);
43 virtual ~LogToServer();
45 // Logs a session state change.
46 void LogSessionStateChange(protocol::ConnectionToHost::State state,
47 protocol::ErrorCode error);
48 void LogStatistics(remoting::ChromotingStats* statistics);
50 // SignalStrategy::Listener interface.
51 virtual void OnSignalStrategyStateChange(
52 SignalStrategy::State state) OVERRIDE;
53 virtual bool OnSignalStrategyIncomingStanza(
54 const buzz::XmlElement* stanza) OVERRIDE;
57 void Log(const ServerLogEntry& entry);
58 void SendPendingEntries();
60 // Generates a new random session ID.
61 void GenerateSessionId();
63 // Expire the session ID if the maximum duration has been exceeded.
64 void MaybeExpireSessionId();
66 ServerLogEntry::Mode mode_;
67 SignalStrategy* signal_strategy_;
68 scoped_ptr<IqSender> iq_sender_;
69 std::string directory_bot_jid_;
71 std::deque<ServerLogEntry> pending_entries_;
73 // A randomly generated session ID to be attached to log messages. This
74 // is regenerated at the start of a new session.
75 std::string session_id_;
77 // Start time of the session.
78 base::TimeTicks session_start_time_;
80 // Time when the session ID was generated.
81 base::TimeTicks session_id_generation_time_;
83 DISALLOW_COPY_AND_ASSIGN(LogToServer);
88 } // namespace remoting
90 #endif // REMOTING_CLIENT_LOG_TO_SERVER_H_