| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/metrics/metrics_log_manager.h" | 5 #include "components/metrics/metrics_log_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "components/metrics/metrics_log.h" | 11 #include "components/metrics/metrics_log.h" |
| 12 #include "components/metrics/metrics_pref_names.h" | 12 #include "components/metrics/metrics_pref_names.h" |
| 13 #include "components/metrics/persisted_logs_metrics_impl.h" |
| 13 | 14 |
| 14 namespace metrics { | 15 namespace metrics { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // The number of "initial" logs to save, and hope to send during a future Chrome | 19 // The number of "initial" logs to save, and hope to send during a future Chrome |
| 19 // session. Initial logs contain crash stats, and are pretty small. | 20 // session. Initial logs contain crash stats, and are pretty small. |
| 20 const size_t kInitialLogsPersistLimit = 20; | 21 const size_t kInitialLogsPersistLimit = 20; |
| 21 | 22 |
| 22 // The number of ongoing logs to save persistently, and hope to | 23 // The number of ongoing logs to save persistently, and hope to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 // The number of bytes each of initial and ongoing logs that must be stored. | 34 // The number of bytes each of initial and ongoing logs that must be stored. |
| 34 // This ensures that a reasonable amount of history will be stored even if there | 35 // This ensures that a reasonable amount of history will be stored even if there |
| 35 // is a long series of very small logs. | 36 // is a long series of very small logs. |
| 36 const size_t kStorageByteLimitPerLogType = 300000; | 37 const size_t kStorageByteLimitPerLogType = 300000; |
| 37 | 38 |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| 40 MetricsLogManager::MetricsLogManager(PrefService* local_state, | 41 MetricsLogManager::MetricsLogManager(PrefService* local_state, |
| 41 size_t max_ongoing_log_size) | 42 size_t max_ongoing_log_size) |
| 42 : unsent_logs_loaded_(false), | 43 : unsent_logs_loaded_(false), |
| 43 initial_log_queue_(local_state, | 44 initial_log_queue_(std::unique_ptr<PersistedLogsMetricsImpl>( |
| 45 new PersistedLogsMetricsImpl()), |
| 46 local_state, |
| 44 prefs::kMetricsInitialLogs, | 47 prefs::kMetricsInitialLogs, |
| 45 prefs::kDeprecatedMetricsInitialLogs, | 48 prefs::kDeprecatedMetricsInitialLogs, |
| 46 kInitialLogsPersistLimit, | 49 kInitialLogsPersistLimit, |
| 47 kStorageByteLimitPerLogType, | 50 kStorageByteLimitPerLogType, |
| 48 0), | 51 0), |
| 49 ongoing_log_queue_(local_state, | 52 ongoing_log_queue_(std::unique_ptr<PersistedLogsMetricsImpl>( |
| 53 new PersistedLogsMetricsImpl()), |
| 54 local_state, |
| 50 prefs::kMetricsOngoingLogs, | 55 prefs::kMetricsOngoingLogs, |
| 51 prefs::kDeprecatedMetricsOngoingLogs, | 56 prefs::kDeprecatedMetricsOngoingLogs, |
| 52 kOngoingLogsPersistLimit, | 57 kOngoingLogsPersistLimit, |
| 53 kStorageByteLimitPerLogType, | 58 kStorageByteLimitPerLogType, |
| 54 max_ongoing_log_size) {} | 59 max_ongoing_log_size) {} |
| 55 | 60 |
| 56 MetricsLogManager::~MetricsLogManager() {} | 61 MetricsLogManager::~MetricsLogManager() {} |
| 57 | 62 |
| 58 void MetricsLogManager::BeginLoggingWithLog(std::unique_ptr<MetricsLog> log) { | 63 void MetricsLogManager::BeginLoggingWithLog(std::unique_ptr<MetricsLog> log) { |
| 59 DCHECK(!current_log_); | 64 DCHECK(!current_log_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ongoing_log_queue_.SerializeLogs(); | 128 ongoing_log_queue_.SerializeLogs(); |
| 124 } | 129 } |
| 125 | 130 |
| 126 void MetricsLogManager::LoadPersistedUnsentLogs() { | 131 void MetricsLogManager::LoadPersistedUnsentLogs() { |
| 127 initial_log_queue_.DeserializeLogs(); | 132 initial_log_queue_.DeserializeLogs(); |
| 128 ongoing_log_queue_.DeserializeLogs(); | 133 ongoing_log_queue_.DeserializeLogs(); |
| 129 unsent_logs_loaded_ = true; | 134 unsent_logs_loaded_ = true; |
| 130 } | 135 } |
| 131 | 136 |
| 132 } // namespace metrics | 137 } // namespace metrics |
| OLD | NEW |