| OLD | NEW |
| (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 #ifndef COMPONENTS_METRICS_METRICS_LOG_STORE_H_ |
| 6 #define COMPONENTS_METRICS_METRICS_LOG_STORE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "components/metrics/log_store.h" |
| 12 #include "components/metrics/metrics_log.h" |
| 13 #include "components/metrics/persisted_logs.h" |
| 14 |
| 15 class PrefService; |
| 16 class PrefRegistrySimple; |
| 17 |
| 18 namespace metrics { |
| 19 |
| 20 // A LogStore implementation for storing UMA logs. |
| 21 // This implementation keeps track of two types of logs, initial and ongoing, |
| 22 // each stored in PersistedLogs. It prioritizes staging initial logs over |
| 23 // ongoing logs. |
| 24 class MetricsLogStore : public LogStore { |
| 25 public: |
| 26 // Constructs a MetricsLogStore that persists data into |local_state|. |
| 27 // If max_log_size is non-zero, it will not persist ongoing logs larger than |
| 28 // |max_ongoing_log_size| bytes. |
| 29 MetricsLogStore(PrefService* local_state, size_t max_ongoing_log_size); |
| 30 ~MetricsLogStore(); |
| 31 |
| 32 // Registers local state prefs used by this class. |
| 33 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 34 |
| 35 // Saves |log_data| as the given type. |
| 36 void StoreLog(const std::string& log_data, MetricsLog::LogType log_type); |
| 37 |
| 38 // LogStore: |
| 39 bool has_unsent_logs() const override; |
| 40 bool has_staged_log() const override; |
| 41 const std::string& staged_log() const override; |
| 42 const std::string& staged_log_hash() const override; |
| 43 void StageNextLog() override; |
| 44 void DiscardStagedLog() override; |
| 45 void PersistUnsentLogs() const override; |
| 46 void LoadPersistedUnsentLogs() override; |
| 47 |
| 48 // Inspection methods for tests. |
| 49 size_t ongoing_log_count() const { return ongoing_log_queue_.size(); } |
| 50 size_t initial_log_count() const { return initial_log_queue_.size(); } |
| 51 |
| 52 private: |
| 53 // Tracks whether unsent logs (if any) have been loaded from the serializer. |
| 54 bool unsent_logs_loaded_; |
| 55 |
| 56 // Logs stored with the INITIAL_STABILITY_LOG type that haven't been sent yet. |
| 57 // These logs will be staged first when staging new logs. |
| 58 PersistedLogs initial_log_queue_; |
| 59 // Logs stored with the ONGOING_LOG type that haven't been sent yet. |
| 60 PersistedLogs ongoing_log_queue_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(MetricsLogStore); |
| 63 }; |
| 64 |
| 65 } // namespace metrics |
| 66 |
| 67 #endif // COMPONENTS_METRICS_METRICS_LOG_STORE_H_ |
| OLD | NEW |