OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ |
6 #define CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ | 6 #define CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "chrome/common/metrics/metrics_log_manager.h" | 11 #include "chrome/common/metrics/metrics_log_manager.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class ListValue; | 14 class ListValue; |
15 } | 15 } |
16 | 16 |
17 // Serializer for persisting metrics logs to prefs. | 17 // Serializer for persisting metrics logs to prefs. |
18 class MetricsLogSerializer : public MetricsLogManager::LogSerializer { | 18 class MetricsLogSerializer : public MetricsLogManager::LogSerializer { |
19 public: | 19 public: |
20 // Used to produce a historgram that keeps track of the status of recalling | 20 // Used to produce a histogram that keeps track of the status of recalling |
21 // persisted per logs. | 21 // persisted per logs. |
22 enum LogReadStatus { | 22 enum LogReadStatus { |
23 RECALL_SUCCESS, // We were able to correctly recall a persisted log. | 23 RECALL_SUCCESS, // We were able to correctly recall a persisted log. |
24 LIST_EMPTY, // Attempting to recall from an empty list. | 24 LIST_EMPTY, // Attempting to recall from an empty list. |
25 LIST_SIZE_MISSING, // Failed to recover list size using GetAsInteger(). | 25 LIST_SIZE_MISSING, // Failed to recover list size using GetAsInteger(). |
26 LIST_SIZE_TOO_SMALL, // Too few elements in the list (less than 3). | 26 LIST_SIZE_TOO_SMALL, // Too few elements in the list (less than 3). |
27 LIST_SIZE_CORRUPTION, // List size is not as expected. | 27 LIST_SIZE_CORRUPTION, // List size is not as expected. |
28 LOG_STRING_CORRUPTION, // Failed to recover log string using GetAsString(). | 28 LOG_STRING_CORRUPTION, // Failed to recover log string using GetAsString(). |
29 CHECKSUM_CORRUPTION, // Failed to verify checksum. | 29 CHECKSUM_CORRUPTION, // Failed to verify checksum. |
30 CHECKSUM_STRING_CORRUPTION, // Failed to recover checksum string using | 30 CHECKSUM_STRING_CORRUPTION, // Failed to recover checksum string using |
31 // GetAsString(). | 31 // GetAsString(). |
32 DECODE_FAIL, // Failed to decode log. | 32 DECODE_FAIL, // Failed to decode log. |
33 END_RECALL_STATUS // Number of bins to use to create the histogram. | 33 END_RECALL_STATUS // Number of bins to use to create the histogram. |
34 }; | 34 }; |
35 | 35 |
36 MetricsLogSerializer(); | 36 MetricsLogSerializer(); |
37 virtual ~MetricsLogSerializer(); | 37 virtual ~MetricsLogSerializer(); |
38 | 38 |
39 // Implementation of MetricsLogManager::LogSerializer | 39 // Implementation of MetricsLogManager::LogSerializer |
40 virtual void SerializeLogs(const std::vector<std::string>& logs, | 40 virtual void SerializeLogs( |
41 MetricsLogManager::LogType log_type) OVERRIDE; | 41 const std::vector<std::pair<std::string, std::string> >& logs, |
42 virtual void DeserializeLogs(MetricsLogManager::LogType log_type, | 42 MetricsLogManager::LogType log_type) OVERRIDE; |
43 std::vector<std::string>* logs) OVERRIDE; | 43 virtual void DeserializeLogs( |
| 44 MetricsLogManager::LogType log_type, |
| 45 std::vector<std::pair<std::string, std::string> >* logs) OVERRIDE; |
44 | 46 |
45 private: | 47 private: |
46 // Encodes the textual log data from |local_list| and writes it to the given | 48 // Encodes the textual log data from |local_list| and writes it to the given |
47 // pref list, along with list size and checksum. | 49 // pref list, along with list size and checksum. |
48 static void WriteLogsToPrefList(const std::vector<std::string>& local_list, | 50 static void WriteLogsToPrefList(const std::vector<std::string>& local_list, |
49 const size_t kMaxLocalListSize, | 51 const size_t kMaxLocalListSize, |
50 base::ListValue* list); | 52 base::ListValue* list); |
51 | 53 |
52 // Decodes and verifies the textual log data from |list|, populating | 54 // Decodes and verifies the textual log data from |list|, populating |
53 // |local_list| and returning a status code. | 55 // |local_list| and returning a status code. |
54 static LogReadStatus ReadLogsFromPrefList( | 56 static LogReadStatus ReadLogsFromPrefList( |
55 const base::ListValue& list, | 57 const base::ListValue& list, |
56 std::vector<std::string>* local_list); | 58 std::vector<std::string>* local_list); |
57 | 59 |
58 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, EmptyLogList); | 60 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, EmptyLogList); |
59 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SingleElementLogList); | 61 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SingleElementLogList); |
60 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, OverLimitLogList); | 62 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, OverLimitLogList); |
61 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SmallRecoveredListSize); | 63 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SmallRecoveredListSize); |
62 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, RemoveSizeFromLogList); | 64 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, RemoveSizeFromLogList); |
63 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptSizeOfLogList); | 65 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptSizeOfLogList); |
64 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptChecksumOfLogList); | 66 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptChecksumOfLogList); |
65 | 67 |
66 DISALLOW_COPY_AND_ASSIGN(MetricsLogSerializer); | 68 DISALLOW_COPY_AND_ASSIGN(MetricsLogSerializer); |
67 }; | 69 }; |
68 | 70 |
69 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ | 71 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ |
OLD | NEW |