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

Side by Side Diff: components/metrics/reporting_service.h

Issue 2608833002: Move logic for uploading logs into a ReportingService object. (Closed)
Patch Set: Fix iOS/Android typo Created 3 years, 9 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 2017 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 // This file defines a service that sends metrics logs to a server.
6
7 #ifndef COMPONENTS_METRICS_REPORTING_SERVICE_H_
8 #define COMPONENTS_METRICS_REPORTING_SERVICE_H_
9
10 #include <stdint.h>
11
12 #include <string>
13
14 #include "base/macros.h"
15 #include "base/time/time.h"
16 #include "build/build_config.h"
17 #include "components/metrics/data_use_tracker.h"
18 #include "components/metrics/metrics_log_uploader.h"
19
20 class PrefService;
21 class PrefRegistrySimple;
22
23 namespace metrics {
24
25 class LogStore;
26 class MetricsUploadScheduler;
27 class MetricsServiceClient;
28
29 // See metrics_service.cc for a detailed description.
Alexei Svitkine (slow) 2017/02/28 18:03:45 I think this should have its own description. Or a
Steven Holte 2017/03/01 02:02:33 Done.
30 class ReportingService {
31 public:
32 // Creates the MetricsService with the given |client|, |max_retransmit_size|
33 // and
Alexei Svitkine (slow) 2017/02/28 18:03:45 Nit: Wrapping is off.
Steven Holte 2017/03/01 02:02:33 Done.
34 // |local_state|. Does not take ownership of the paramaters; instead stores
35 // a weak pointer to each. Caller should ensure that the parameters are valid
36 // for the lifetime of this class.
37 ReportingService(MetricsServiceClient* client,
38 PrefService* local_state,
39 size_t max_retransmit_size);
40 virtual ~ReportingService();
41
42 // Complete any setup tasks that can't be done at construction time.
43 virtual void Initialize();
44
45 // Starts the metrics reporting system.
46 // Should be called when metrics enabled or new logs are created.
47 // When the service is already running, this is a safe no-op.
48 void Start();
49
50 // Shuts down the metrics system. Should be called at shutdown, or if metrics
51 // are turned off.
52 void Stop();
53
54 // Enable/disable transmission of accumulated logs and crash reports (dumps).
55 // Calling Start() automatically enables reporting, but sending is
56 // asyncronous so this can be called immediately after Start() to prevent
57 // any uploading.
58 void EnableReporting();
59 void DisableReporting();
60
61 // True iff reporting is currently enabled.
62 bool reporting_active() const;
63
64 // Updates data usage tracking prefs with the specified values.
65 void UpdateMetricsUsagePrefs(const std::string& service_name,
66 int message_size,
67 bool is_cellular);
68
69 // At startup, prefs needs to be called with a list of all the pref names and
Alexei Svitkine (slow) 2017/02/28 18:03:45 "prefs needs to be called" isn't very clear to me.
Steven Holte 2017/03/01 02:02:33 Rephrased (on MetricsService too) and mentioned he
70 // types we'll be using.
71 static void RegisterPrefs(PrefRegistrySimple* registry);
72
73 protected:
74 MetricsServiceClient* client() { return client_; };
75
76 private:
77 // Retrieves the log store backing this service.
78 virtual LogStore* log_store() = 0;
79
80 // Getters for MetricsLogUploader parameters.
81 virtual std::string upload_url() = 0;
Alexei Svitkine (slow) 2017/02/28 18:03:45 return by const string ref?
Steven Holte 2017/03/01 02:02:33 I can return const strings, but not const string r
Alexei Svitkine (slow) 2017/03/01 16:06:29 I don't think returning const strings makes much s
Steven Holte 2017/03/04 01:35:51 Done.
82 virtual std::string upload_mime_type() = 0;
83 virtual MetricsLogUploader::MetricServiceType service_type() = 0;
84
85 // Methods for recording data to histograms.
86 virtual void LogActualUploadInterval(base::TimeDelta interval){};
Alexei Svitkine (slow) 2017/02/28 18:03:45 Nit: Add space before { Same for others.
Steven Holte 2017/03/01 02:02:33 clang-format deletes these spaces
Alexei Svitkine (slow) 2017/03/01 16:06:29 Weird. I noticed you have semicolons at the end -
Steven Holte 2017/03/04 01:35:51 Ah, yes it was the semicolons. Fixed.
87 virtual void LogCellularConstraint(bool upload_canceled){};
88 virtual void LogResponseCode(int response_code){};
89 virtual void LogSuccess(size_t log_size){};
90 virtual void LogLargeRejection(size_t log_size){};
91
92 // If recording is enabled, begins uploading the next completed log from
93 // the log manager, staging it if necessary.
94 void SendNextLog();
95
96 // Uploads the currently staged log (which must be non-null).
97 void SendStagedLog();
98
99 // Called after transmission completes (either successfully or with failure).
100 void OnLogUploadComplete(int response_code);
101
102 // Used to interact with the embedder. Weak pointer; must outlive |this|
103 // instance.
104 MetricsServiceClient* const client_;
105
106 // Largest log size to attempt to retransmit.
107 size_t max_retransmit_size_;
108
109 // Indicate whether recording and reporting are currently happening.
110 // These should not be set directly, but by calling SetRecording and
111 // SetReporting.
112 bool reporting_active_;
113
114 // Instance of the helper class for uploading logs.
115 std::unique_ptr<MetricsLogUploader> log_uploader_;
116
117 // Whether there is a current log upload in progress.
118 bool log_upload_in_progress_;
119
120 // The scheduler for determining when uploads should happen.
121 std::unique_ptr<MetricsUploadScheduler> upload_scheduler_;
122
123 // Pointer used for obtaining data use pref updater callback on above layers.
124 std::unique_ptr<DataUseTracker> data_use_tracker_;
125
126 // The tick count of the last time log upload has been finished and null if no
127 // upload has been done yet.
128 base::TimeTicks last_upload_finish_time_;
129
130 base::ThreadChecker thread_checker_;
131
132 // Weak pointers factory used to post task on different threads. All weak
133 // pointers managed by this factory have the same lifetime as
134 // ReportingService.
135 base::WeakPtrFactory<ReportingService> self_ptr_factory_;
136
137 DISALLOW_COPY_AND_ASSIGN(ReportingService);
138 };
139
140 } // namespace metrics
141
142 #endif // COMPONENTS_METRICS_REPORTING_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698