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

Side by Side Diff: remoting/signaling/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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_SIGNALING_TELEMETRY_LOG_WRITER_H_
6 #define REMOTING_SIGNALING_TELEMETRY_LOG_WRITER_H_
7
8 #include <deque>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/values.h"
16 #include "remoting/base/url_request.h"
17 #include "remoting/signaling/chromoting_event.h"
18 #include "remoting/signaling/chromoting_event_log_writer.h"
19
20 namespace remoting {
21
22 // TelemetryLogWriter sends log entries (ChromotingEvent) to the telemetry
23 // server.
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
26 // sent.
27 class TelemetryLogWriter : public ChromotingEventLogWriter,
28 public base::NonThreadSafe {
29 public:
30 TelemetryLogWriter(const std::string& telemetry_base_url,
31 std::unique_ptr<UrlRequestFactory> request_factory);
32
33 // "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
35 // logs if the list is not empty.
36 void SetAuthToken(const std::string& auth_token) override;
37
38 // The closure will be called when the request fails with unauthorized error
39 // 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
41 // immediately.
42 void SetAuthClosure(const base::Closure& closure) override;
43
44 // Push the log entry to the pending list and send out all the pending logs.
45 void Log(const ChromotingEvent& entry) override;
46
47 ~TelemetryLogWriter() override;
48
49 private:
50 void SendPendingEntries();
51 void PostJsonToServer(const std::string& json);
52 void OnSendLogResult(const remoting::UrlRequest::Result& result);
53
54 std::string telemetry_base_url_;
55 std::unique_ptr<UrlRequestFactory> request_factory_;
56 std::string auth_token_;
57 base::Closure auth_closure_;
58 std::unique_ptr<UrlRequest> request_;
59
60 // Entries to be sent.
61 std::deque<ChromotingEvent> pending_entries_;
62
63 // Entries being sent.
64 // These will be pushed back to pending_entries if error occurs.
65 std::deque<ChromotingEvent> sending_entries_;
66
67 DISALLOW_COPY_AND_ASSIGN(TelemetryLogWriter);
68 };
69
70 } // namespace remoting
71 #endif // REMOTING_SIGNALING_TELEMETRY_LOG_WRITER_H_
OLDNEW
« no previous file with comments | « remoting/signaling/chromoting_event_log_writer.h ('k') | remoting/signaling/telemetry_log_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698