Chromium Code Reviews| Index: components/metrics/reporting_service.h |
| diff --git a/components/metrics/reporting_service.h b/components/metrics/reporting_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a1e1c986eb3ed406831b84048ada6dd7e26cb36a |
| --- /dev/null |
| +++ b/components/metrics/reporting_service.h |
| @@ -0,0 +1,142 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This file defines a service that sends metrics logs to a server. |
| + |
| +#ifndef COMPONENTS_METRICS_REPORTING_SERVICE_H_ |
| +#define COMPONENTS_METRICS_REPORTING_SERVICE_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| +#include "base/time/time.h" |
| +#include "build/build_config.h" |
| +#include "components/metrics/data_use_tracker.h" |
| +#include "components/metrics/metrics_log_uploader.h" |
| + |
| +class PrefService; |
| +class PrefRegistrySimple; |
| + |
| +namespace metrics { |
| + |
| +class LogStore; |
| +class MetricsUploadScheduler; |
| +class MetricsServiceClient; |
| + |
| +// 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.
|
| +class ReportingService { |
| + public: |
| + // Creates the MetricsService with the given |client|, |max_retransmit_size| |
| + // and |
|
Alexei Svitkine (slow)
2017/02/28 18:03:45
Nit: Wrapping is off.
Steven Holte
2017/03/01 02:02:33
Done.
|
| + // |local_state|. Does not take ownership of the paramaters; instead stores |
| + // a weak pointer to each. Caller should ensure that the parameters are valid |
| + // for the lifetime of this class. |
| + ReportingService(MetricsServiceClient* client, |
| + PrefService* local_state, |
| + size_t max_retransmit_size); |
| + virtual ~ReportingService(); |
| + |
| + // Complete any setup tasks that can't be done at construction time. |
| + virtual void Initialize(); |
| + |
| + // Starts the metrics reporting system. |
| + // Should be called when metrics enabled or new logs are created. |
| + // When the service is already running, this is a safe no-op. |
| + void Start(); |
| + |
| + // Shuts down the metrics system. Should be called at shutdown, or if metrics |
| + // are turned off. |
| + void Stop(); |
| + |
| + // Enable/disable transmission of accumulated logs and crash reports (dumps). |
| + // Calling Start() automatically enables reporting, but sending is |
| + // asyncronous so this can be called immediately after Start() to prevent |
| + // any uploading. |
| + void EnableReporting(); |
| + void DisableReporting(); |
| + |
| + // True iff reporting is currently enabled. |
| + bool reporting_active() const; |
| + |
| + // Updates data usage tracking prefs with the specified values. |
| + void UpdateMetricsUsagePrefs(const std::string& service_name, |
| + int message_size, |
| + bool is_cellular); |
| + |
| + // 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
|
| + // types we'll be using. |
| + static void RegisterPrefs(PrefRegistrySimple* registry); |
| + |
| + protected: |
| + MetricsServiceClient* client() { return client_; }; |
| + |
| + private: |
| + // Retrieves the log store backing this service. |
| + virtual LogStore* log_store() = 0; |
| + |
| + // Getters for MetricsLogUploader parameters. |
| + 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.
|
| + virtual std::string upload_mime_type() = 0; |
| + virtual MetricsLogUploader::MetricServiceType service_type() = 0; |
| + |
| + // Methods for recording data to histograms. |
| + 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.
|
| + virtual void LogCellularConstraint(bool upload_canceled){}; |
| + virtual void LogResponseCode(int response_code){}; |
| + virtual void LogSuccess(size_t log_size){}; |
| + virtual void LogLargeRejection(size_t log_size){}; |
| + |
| + // If recording is enabled, begins uploading the next completed log from |
| + // the log manager, staging it if necessary. |
| + void SendNextLog(); |
| + |
| + // Uploads the currently staged log (which must be non-null). |
| + void SendStagedLog(); |
| + |
| + // Called after transmission completes (either successfully or with failure). |
| + void OnLogUploadComplete(int response_code); |
| + |
| + // Used to interact with the embedder. Weak pointer; must outlive |this| |
| + // instance. |
| + MetricsServiceClient* const client_; |
| + |
| + // Largest log size to attempt to retransmit. |
| + size_t max_retransmit_size_; |
| + |
| + // Indicate whether recording and reporting are currently happening. |
| + // These should not be set directly, but by calling SetRecording and |
| + // SetReporting. |
| + bool reporting_active_; |
| + |
| + // Instance of the helper class for uploading logs. |
| + std::unique_ptr<MetricsLogUploader> log_uploader_; |
| + |
| + // Whether there is a current log upload in progress. |
| + bool log_upload_in_progress_; |
| + |
| + // The scheduler for determining when uploads should happen. |
| + std::unique_ptr<MetricsUploadScheduler> upload_scheduler_; |
| + |
| + // Pointer used for obtaining data use pref updater callback on above layers. |
| + std::unique_ptr<DataUseTracker> data_use_tracker_; |
| + |
| + // The tick count of the last time log upload has been finished and null if no |
| + // upload has been done yet. |
| + base::TimeTicks last_upload_finish_time_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + // Weak pointers factory used to post task on different threads. All weak |
| + // pointers managed by this factory have the same lifetime as |
| + // ReportingService. |
| + base::WeakPtrFactory<ReportingService> self_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ReportingService); |
| +}; |
| + |
| +} // namespace metrics |
| + |
| +#endif // COMPONENTS_METRICS_REPORTING_SERVICE_H_ |