| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 registry()->RegisterListPref(prefs::kMetricsOngoingLogs); | 30 registry()->RegisterListPref(prefs::kMetricsOngoingLogs); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Returns the number of logs of the given type. | 33 // Returns the number of logs of the given type. |
| 34 size_t TypeCount(MetricsLog::LogType log_type) { | 34 size_t TypeCount(MetricsLog::LogType log_type) { |
| 35 int list_length = 0; | 35 int list_length = 0; |
| 36 if (log_type == MetricsLog::INITIAL_STABILITY_LOG) | 36 if (log_type == MetricsLog::INITIAL_STABILITY_LOG) |
| 37 list_length = GetList(prefs::kMetricsInitialLogs)->GetSize(); | 37 list_length = GetList(prefs::kMetricsInitialLogs)->GetSize(); |
| 38 else | 38 else |
| 39 list_length = GetList(prefs::kMetricsOngoingLogs)->GetSize(); | 39 list_length = GetList(prefs::kMetricsOngoingLogs)->GetSize(); |
| 40 return list_length / 2; | 40 return list_length; |
| 41 } | 41 } |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 TEST(MetricsLogManagerTest, StandardFlow) { | 46 TEST(MetricsLogManagerTest, StandardFlow) { |
| 47 TestMetricsServiceClient client; | 47 TestMetricsServiceClient client; |
| 48 TestLogPrefService pref_service; | 48 TestLogPrefService pref_service; |
| 49 MetricsLogManager log_manager(&pref_service, 0); | 49 MetricsLogManager log_manager(&pref_service, 0); |
| 50 | 50 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 TestLogPrefService pref_service; | 156 TestLogPrefService pref_service; |
| 157 // Set up some in-progress logging in a scoped log manager simulating the | 157 // Set up some in-progress logging in a scoped log manager simulating the |
| 158 // leadup to quitting, then persist as would be done on quit. | 158 // leadup to quitting, then persist as would be done on quit. |
| 159 { | 159 { |
| 160 MetricsLogManager log_manager(&pref_service, 0); | 160 MetricsLogManager log_manager(&pref_service, 0); |
| 161 log_manager.LoadPersistedUnsentLogs(); | 161 log_manager.LoadPersistedUnsentLogs(); |
| 162 | 162 |
| 163 // Simulate a log having already been unsent from a previous session. | 163 // Simulate a log having already been unsent from a previous session. |
| 164 { | 164 { |
| 165 std::string log("proto"); | 165 std::string log("proto"); |
| 166 PersistedLogs ongoing_logs(&pref_service, prefs::kMetricsOngoingLogs, 1, | 166 PersistedLogs ongoing_logs(&pref_service, prefs::kMetricsOngoingLogs, |
| 167 1, 0); | 167 prefs::kDeprecatedMetricsOngoingLogs, 1, 1, 0); |
| 168 ongoing_logs.StoreLog(log); | 168 ongoing_logs.StoreLog(log); |
| 169 ongoing_logs.SerializeLogs(); | 169 ongoing_logs.SerializeLogs(); |
| 170 } | 170 } |
| 171 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); | 171 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); |
| 172 EXPECT_FALSE(log_manager.has_unsent_logs()); | 172 EXPECT_FALSE(log_manager.has_unsent_logs()); |
| 173 log_manager.LoadPersistedUnsentLogs(); | 173 log_manager.LoadPersistedUnsentLogs(); |
| 174 EXPECT_TRUE(log_manager.has_unsent_logs()); | 174 EXPECT_TRUE(log_manager.has_unsent_logs()); |
| 175 | 175 |
| 176 log_manager.BeginLoggingWithLog(base::MakeUnique<MetricsLog>( | 176 log_manager.BeginLoggingWithLog(base::MakeUnique<MetricsLog>( |
| 177 "id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &pref_service)); | 177 "id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &pref_service)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 log_manager.FinishCurrentLog(); | 298 log_manager.FinishCurrentLog(); |
| 299 log_manager.DiscardStagedLog(); | 299 log_manager.DiscardStagedLog(); |
| 300 | 300 |
| 301 log_manager.PersistUnsentLogs(); | 301 log_manager.PersistUnsentLogs(); |
| 302 EXPECT_EQ(0U, pref_service.TypeCount(MetricsLog::INITIAL_STABILITY_LOG)); | 302 EXPECT_EQ(0U, pref_service.TypeCount(MetricsLog::INITIAL_STABILITY_LOG)); |
| 303 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); | 303 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace metrics | 307 } // namespace metrics |
| OLD | NEW |