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

Unified Diff: components/metrics/metrics_log_store.h

Issue 2689323010: Split a MetricsLogStore object out of MetricsLogManager. (Closed)
Patch Set: Incorporate Feedback Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/metrics/metrics_log_store.h
diff --git a/components/metrics/metrics_log_store.h b/components/metrics/metrics_log_store.h
new file mode 100644
index 0000000000000000000000000000000000000000..f66e85f5c2989149980a5a887a569993e241f57a
--- /dev/null
+++ b/components/metrics/metrics_log_store.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef COMPONENTS_METRICS_METRICS_LOG_STORE_H_
+#define COMPONENTS_METRICS_METRICS_LOG_STORE_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "components/metrics/log_store.h"
+#include "components/metrics/metrics_log.h"
+#include "components/metrics/persisted_logs.h"
+
+class PrefService;
+class PrefRegistrySimple;
+
+namespace metrics {
+
+// A LogStore implementation for storing UMA logs.
+// This implementation keeps track of two types of logs, initial and ongoing,
+// each stored in PersistedLogs. It prioritizes staging initial logs over
+// ongoing logs.
+class MetricsLogStore : public LogStore {
+ public:
+ MetricsLogStore(PrefService* local_state, size_t max_retransmit_size);
+ ~MetricsLogStore();
+
+ // At startup, prefs needs to be called with a list of all the pref names and
+ // types we'll be using.
bcwhite 2017/02/22 16:25:09 "types being used".
Steven Holte 2017/02/22 20:35:50 Replaced this with a simpler comment.
+ static void RegisterPrefs(PrefRegistrySimple* registry);
+
+ // Saves |log_data| as the given type.
+ void StoreLog(const std::string& log_data, MetricsLog::LogType log_type);
+
+ // metrics::LogStore implementation
bcwhite 2017/02/22 16:25:09 Just metrics::LogStore:
Steven Holte 2017/02/22 20:35:50 Done.
+ bool has_unsent_logs() const override;
+ bool has_staged_log() const override;
+ const std::string& staged_log() const override;
+ const std::string& staged_log_hash() const override;
+ void StageNextLog() override;
+ void DiscardStagedLog() override;
+ void PersistUnsentLogs() const override;
+ void LoadPersistedUnsentLogs() override;
+
+ // Inspection methods for tests.
+ size_t ongoing_log_count() const { return ongoing_log_queue_.size(); }
+ size_t initial_log_count() const { return initial_log_queue_.size(); }
+
+ private:
+ // Tracks whether unsent logs (if any) have been loaded from the serializer.
+ bool unsent_logs_loaded_;
+
+ // Logs stored with the INITIAL_STABILITY_LOG type that haven't been sent yet.
+ // These logs will be staged first when staging new logs.
+ PersistedLogs initial_log_queue_;
+ // Logs stored with the ONGOING_LOG type that haven't been sent yet.
+ PersistedLogs ongoing_log_queue_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsLogStore);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_METRICS_LOG_STORE_H_

Powered by Google App Engine
This is Rietveld 408576698