Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ | 5 #ifndef REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ |
| 6 #define REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ | 6 #define REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "remoting/base/chromoting_event.h" | 14 #include "remoting/base/chromoting_event.h" |
| 15 #include "remoting/base/chromoting_event_log_writer.h" | 15 #include "remoting/base/chromoting_event_log_writer.h" |
| 16 #include "remoting/base/url_request.h" | 16 #include "remoting/base/url_request.h" |
| 17 #include "remoting/protocol/connection_to_host.h" | 17 #include "remoting/protocol/connection_to_host.h" |
| 18 #include "remoting/protocol/performance_tracker.h" | 18 #include "remoting/protocol/performance_tracker.h" |
| 19 | 19 |
| 20 namespace remoting { | 20 namespace remoting { |
| 21 | 21 |
| 22 // ClientTelemetryLogger sends client log entries to the telemetry server. | 22 // ClientTelemetryLogger sends client log entries to the telemetry server. |
| 23 // The logger should be run entirely on one single thread. | 23 // The logger should be run entirely on one single thread. |
| 24 // TODO(yuweih): Implement new features that session_logger.js provides. | 24 // TODO(yuweih): Implement new features that session_logger.js provides. |
| 25 // TODO(BUG 680752): Refactor this so that it's bounded to only one session. | |
|
Sergey Ulanov
2017/01/13 00:23:17
s/bounded/bound/
Yuwei
2017/01/13 01:51:12
Done.
| |
| 25 class ClientTelemetryLogger { | 26 class ClientTelemetryLogger { |
| 26 public: | 27 public: |
| 27 explicit ClientTelemetryLogger(ChromotingEvent::Mode mode); | 28 explicit ClientTelemetryLogger(ChromotingEvent::Mode mode); |
| 28 ~ClientTelemetryLogger(); | 29 ~ClientTelemetryLogger(); |
| 29 | 30 |
| 31 // Sets the host info to be posted along with other log data. By default | |
| 32 // no host info will be logged. | |
| 33 void SetHostInfo(const std::string& host_version, | |
| 34 ChromotingEvent::Os host_os, | |
| 35 const std::string& host_os_version); | |
| 36 | |
| 30 // Start must be called before posting logs or setting auth token or closure. | 37 // Start must be called before posting logs or setting auth token or closure. |
| 31 void Start(std::unique_ptr<UrlRequestFactory> request_factory, | 38 void Start(std::unique_ptr<UrlRequestFactory> request_factory, |
| 32 const std::string& telemetry_base_url); | 39 const std::string& telemetry_base_url); |
| 33 | 40 |
| 34 void LogSessionStateChange(ChromotingEvent::SessionState state, | 41 void LogSessionStateChange(ChromotingEvent::SessionState state, |
| 35 ChromotingEvent::ConnectionError error); | 42 ChromotingEvent::ConnectionError error); |
| 36 | 43 |
| 37 // TODO(yuweih): Investigate possibility of making PerformanceTracker const. | 44 // TODO(yuweih): Investigate possibility of making PerformanceTracker const. |
| 38 void LogStatistics(protocol::PerformanceTracker* perf_tracker); | 45 void LogStatistics(protocol::PerformanceTracker* perf_tracker); |
| 39 | 46 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 58 // after calling this function. | 65 // after calling this function. |
| 59 void StartForTest(std::unique_ptr<ChromotingEventLogWriter> writer); | 66 void StartForTest(std::unique_ptr<ChromotingEventLogWriter> writer); |
| 60 | 67 |
| 61 static ChromotingEvent::SessionState TranslateState( | 68 static ChromotingEvent::SessionState TranslateState( |
| 62 protocol::ConnectionToHost::State state); | 69 protocol::ConnectionToHost::State state); |
| 63 | 70 |
| 64 static ChromotingEvent::ConnectionError TranslateError( | 71 static ChromotingEvent::ConnectionError TranslateError( |
| 65 protocol::ErrorCode state); | 72 protocol::ErrorCode state); |
| 66 | 73 |
| 67 private: | 74 private: |
| 75 struct HostInfo; | |
| 68 | 76 |
| 69 void FillEventContext(ChromotingEvent* event) const; | 77 void FillEventContext(ChromotingEvent* event) const; |
| 70 | 78 |
| 71 // Generates a new random session ID. | 79 // Generates a new random session ID. |
| 72 void GenerateSessionId(); | 80 void GenerateSessionId(); |
| 73 | 81 |
| 74 // Expire the session ID if the maximum duration has been exceeded. | 82 // Expire the session ID if the maximum duration has been exceeded. |
| 75 // Sends SessionIdOld and SessionIdNew events describing the change of id. | 83 // Sends SessionIdOld and SessionIdNew events describing the change of id. |
| 76 void ExpireSessionIdIfOutdated(); | 84 void ExpireSessionIdIfOutdated(); |
| 77 | 85 |
| 78 ChromotingEvent MakeStatsEvent(protocol::PerformanceTracker* perf_tracker); | 86 ChromotingEvent MakeStatsEvent(protocol::PerformanceTracker* perf_tracker); |
| 79 ChromotingEvent MakeSessionStateChangeEvent( | 87 ChromotingEvent MakeSessionStateChangeEvent( |
| 80 ChromotingEvent::SessionState state, | 88 ChromotingEvent::SessionState state, |
| 81 ChromotingEvent::ConnectionError error); | 89 ChromotingEvent::ConnectionError error); |
| 82 ChromotingEvent MakeSessionIdOldEvent(); | 90 ChromotingEvent MakeSessionIdOldEvent(); |
| 83 ChromotingEvent MakeSessionIdNewEvent(); | 91 ChromotingEvent MakeSessionIdNewEvent(); |
| 84 | 92 |
| 85 // A randomly generated session ID to be attached to log messages. This | 93 // A randomly generated session ID to be attached to log messages. This |
| 86 // is regenerated at the start of a new session. | 94 // is regenerated at the start of a new session. |
| 87 std::string session_id_; | 95 std::string session_id_; |
| 88 | 96 |
| 89 base::TimeTicks session_start_time_; | 97 base::TimeTicks session_start_time_; |
| 90 | 98 |
| 91 base::TimeTicks session_id_generation_time_; | 99 base::TimeTicks session_id_generation_time_; |
| 92 | 100 |
| 93 ChromotingEvent::Mode mode_; | 101 ChromotingEvent::Mode mode_; |
| 94 | 102 |
| 103 std::unique_ptr<HostInfo> host_info_; | |
| 104 | |
| 95 // The log writer that actually sends log to the server. | 105 // The log writer that actually sends log to the server. |
| 96 std::unique_ptr<ChromotingEventLogWriter> log_writer_; | 106 std::unique_ptr<ChromotingEventLogWriter> log_writer_; |
| 97 | 107 |
| 98 base::ThreadChecker thread_checker_; | 108 base::ThreadChecker thread_checker_; |
| 99 | 109 |
| 100 DISALLOW_COPY_AND_ASSIGN(ClientTelemetryLogger); | 110 DISALLOW_COPY_AND_ASSIGN(ClientTelemetryLogger); |
| 101 }; | 111 }; |
| 102 | 112 |
| 103 } // namespace remoting | 113 } // namespace remoting |
| 104 | 114 |
| 105 #endif // REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ | 115 #endif // REMOTING_CLIENT_CLIENT_TELEMETRY_LOGGER_H_ |
| OLD | NEW |