Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: remoting/base/telemetry_log_writer.h

Issue 1972793002: TelemetryLogWriter cleanups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/base/chromoting_event_log_writer.h ('k') | remoting/base/telemetry_log_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_SIGNALING_TELEMETRY_LOG_WRITER_H_ 5 #ifndef REMOTING_BASE_TELEMETRY_LOG_WRITER_H_
6 #define REMOTING_SIGNALING_TELEMETRY_LOG_WRITER_H_ 6 #define REMOTING_BASE_TELEMETRY_LOG_WRITER_H_
7 7
8 #include <deque> 8 #include <deque>
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/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "remoting/base/chromoting_event.h"
17 #include "remoting/base/chromoting_event_log_writer.h"
16 #include "remoting/base/url_request.h" 18 #include "remoting/base/url_request.h"
17 #include "remoting/signaling/chromoting_event.h"
18 #include "remoting/signaling/chromoting_event_log_writer.h"
19 19
20 namespace remoting { 20 namespace remoting {
21 21
22 // TelemetryLogWriter sends log entries (ChromotingEvent) to the telemetry 22 // TelemetryLogWriter sends log entries (ChromotingEvent) to the telemetry
23 // server. 23 // server.
24 // Logs to be sent will be queued and sent when it is available. Logs failed 24 // Logs to be sent will be queued and sent when it is available. Logs failed
25 // to send will be retried for a few times and dropped if they still can't be 25 // to send will be retried for a few times and dropped if they still can't be
26 // sent. 26 // sent.
27 class TelemetryLogWriter : public ChromotingEventLogWriter, 27 class TelemetryLogWriter : public ChromotingEventLogWriter {
28 public base::NonThreadSafe {
29 public: 28 public:
30 TelemetryLogWriter(const std::string& telemetry_base_url, 29 TelemetryLogWriter(const std::string& telemetry_base_url,
31 std::unique_ptr<UrlRequestFactory> request_factory); 30 std::unique_ptr<UrlRequestFactory> request_factory);
32 31
33 // "Authorization:Bearer {TOKEN}" will be added if auth_token is not empty. 32 // "Authorization:Bearer {TOKEN}" will be added if auth_token is not empty.
34 // After this function is called, the log writer will try to send out pending 33 // After this function is called, the log writer will try to send out pending
35 // logs if the list is not empty. 34 // logs if the list is not empty.
36 void SetAuthToken(const std::string& auth_token) override; 35 void SetAuthToken(const std::string& auth_token) override;
37 36
38 // The closure will be called when the request fails with unauthorized error 37 // The closure will be called when the request fails with unauthorized error
39 // code. The closure should call SetAuthToken to set the token. 38 // code. The closure should call SetAuthToken to set the token.
40 // If the closure is not set, the log writer will try to resend the logs 39 // If the closure is not set, the log writer will try to resend the logs
41 // immediately. 40 // immediately.
42 void SetAuthClosure(const base::Closure& closure) override; 41 void SetAuthClosure(const base::Closure& closure) override;
43 42
44 // Push the log entry to the pending list and send out all the pending logs. 43 // Push the log entry to the pending list and send out all the pending logs.
45 void Log(const ChromotingEvent& entry) override; 44 void Log(const ChromotingEvent& entry) override;
46 45
47 ~TelemetryLogWriter() override; 46 ~TelemetryLogWriter() override;
48 47
49 private: 48 private:
50 void SendPendingEntries(); 49 void SendPendingEntries();
51 void PostJsonToServer(const std::string& json); 50 void PostJsonToServer(const std::string& json);
52 void OnSendLogResult(const remoting::UrlRequest::Result& result); 51 void OnSendLogResult(const remoting::UrlRequest::Result& result);
53 52
53 base::ThreadChecker thread_checker_;
54 std::string telemetry_base_url_; 54 std::string telemetry_base_url_;
55 std::unique_ptr<UrlRequestFactory> request_factory_; 55 std::unique_ptr<UrlRequestFactory> request_factory_;
56 std::string auth_token_; 56 std::string auth_token_;
57 base::Closure auth_closure_; 57 base::Closure auth_closure_;
58 std::unique_ptr<UrlRequest> request_; 58 std::unique_ptr<UrlRequest> request_;
59 59
60 // Entries to be sent. 60 // Entries to be sent.
61 std::deque<ChromotingEvent> pending_entries_; 61 std::deque<ChromotingEvent> pending_entries_;
62 62
63 // Entries being sent. 63 // Entries being sent.
64 // These will be pushed back to pending_entries if error occurs. 64 // These will be pushed back to pending_entries if error occurs.
65 std::deque<ChromotingEvent> sending_entries_; 65 std::deque<ChromotingEvent> sending_entries_;
66 66
67 DISALLOW_COPY_AND_ASSIGN(TelemetryLogWriter); 67 DISALLOW_COPY_AND_ASSIGN(TelemetryLogWriter);
68 }; 68 };
69 69
70 } // namespace remoting 70 } // namespace remoting
71 #endif // REMOTING_SIGNALING_TELEMETRY_LOG_WRITER_H_ 71 #endif // REMOTING_BASE_TELEMETRY_LOG_WRITER_H_
OLDNEW
« no previous file with comments | « remoting/base/chromoting_event_log_writer.h ('k') | remoting/base/telemetry_log_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698