host_status_logger.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.
  4. #include "remoting/host/host_status_logger.h"
  5. #include "base/bind.h"
  6. #include "remoting/base/constants.h"
  7. #include "remoting/host/host_status_monitor.h"
  8. #include "remoting/host/server_log_entry_host.h"
  9. #include "remoting/protocol/transport.h"
  10. #include "remoting/signaling/server_log_entry.h"
  11. namespace remoting {
  12. HostStatusLogger::HostStatusLogger(scoped_refptr<HostStatusMonitor> monitor,
  13. LogToServer* log_to_server)
  14. : log_to_server_(log_to_server), monitor_(monitor) {
  15. DCHECK(log_to_server_);
  16. DCHECK(monitor_);
  17. monitor_->AddStatusObserver(this);
  18. }
  19. HostStatusLogger::~HostStatusLogger() {
  20. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  21. monitor_->RemoveStatusObserver(this);
  22. }
  23. void HostStatusLogger::LogSessionStateChange(const std::string& jid,
  24. bool connected) {
  25. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  26. std::unique_ptr<ServerLogEntry> entry(
  27. MakeLogEntryForSessionStateChange(connected));
  28. AddHostFieldsToLogEntry(entry.get());
  29. entry->AddModeField(log_to_server_->mode());
  30. if (connected && connection_route_type_.count(jid) > 0)
  31. AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]);
  32. log_to_server_->Log(*entry.get());
  33. }
  34. void HostStatusLogger::OnClientConnected(const std::string& jid) {
  35. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  36. LogSessionStateChange(jid, true);
  37. }
  38. void HostStatusLogger::OnClientDisconnected(const std::string& jid) {
  39. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  40. LogSessionStateChange(jid, false);
  41. connection_route_type_.erase(jid);
  42. }
  43. void HostStatusLogger::OnClientRouteChange(
  44. const std::string& jid,
  45. const std::string& channel_name,
  46. const protocol::TransportRoute& route) {
  47. // Store connection type for the video channel. It is logged later
  48. // when client authentication is finished. For WebRTC clients, the
  49. // route-change notification is not per-channel, so the channel_name is
  50. // empty.
  51. if (channel_name.empty() || channel_name == kVideoChannelName) {
  52. connection_route_type_[jid] = route.type;
  53. }
  54. }
  55. } // namespace remoting