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 XML_PROTO_MISMATCH, // The XML and protobuf logs have inconsistent data. | |
33 END_RECALL_STATUS // Number of bins to use to create the histogram. | 34 END_RECALL_STATUS // Number of bins to use to create the histogram. |
34 }; | 35 }; |
35 | 36 |
36 MetricsLogSerializer(); | 37 MetricsLogSerializer(); |
37 virtual ~MetricsLogSerializer(); | 38 virtual ~MetricsLogSerializer(); |
38 | 39 |
39 // Implementation of MetricsLogManager::LogSerializer | 40 // Implementation of MetricsLogManager::LogSerializer |
40 virtual void SerializeLogs(const std::vector<std::string>& logs, | 41 virtual void SerializeLogs( |
41 MetricsLogManager::LogType log_type) OVERRIDE; | 42 const std::vector<std::pair<std::string, std::string> >& logs, |
jar (doing other things)
2012/02/23 01:59:18
Please add comment about the meaning of pairs of s
| |
42 virtual void DeserializeLogs(MetricsLogManager::LogType log_type, | 43 MetricsLogManager::LogType log_type) OVERRIDE; |
43 std::vector<std::string>* logs) OVERRIDE; | 44 virtual void DeserializeLogs( |
45 MetricsLogManager::LogType log_type, | |
46 std::vector<std::pair<std::string, std::string> >* logs) OVERRIDE; | |
44 | 47 |
45 private: | 48 private: |
46 // Encodes the textual log data from |local_list| and writes it to the given | 49 // Encodes the textual log data from |local_list| and writes it to the given |
47 // pref list, along with list size and checksum. | 50 // pref list, along with list size and checksum. |
48 static void WriteLogsToPrefList(const std::vector<std::string>& local_list, | 51 static void WriteLogsToPrefList(const std::vector<std::string>& local_list, |
49 const size_t kMaxLocalListSize, | 52 const size_t kMaxLocalListSize, |
50 base::ListValue* list); | 53 base::ListValue* list); |
51 | 54 |
52 // Decodes and verifies the textual log data from |list|, populating | 55 // Decodes and verifies the textual log data from |list|, populating |
53 // |local_list| and returning a status code. | 56 // |local_list| and returning a status code. |
57 // |is_xml| should be true if this is an XML log and false if this is a | |
jar (doing other things)
2012/02/23 01:59:18
I wasn't able to understand the comment as written
Ilya Sherman
2012/02/24 02:10:06
Is it clearer now, or still confusing?
jar (doing other things)
2012/02/27 20:35:34
Much better. Thanks!
On 2012/02/24 02:10:06, Ilya
| |
58 // protobuf log; it is used exclusively for logging histograms. | |
54 static LogReadStatus ReadLogsFromPrefList( | 59 static LogReadStatus ReadLogsFromPrefList( |
55 const base::ListValue& list, | 60 const base::ListValue& list, |
61 bool is_xml, | |
56 std::vector<std::string>* local_list); | 62 std::vector<std::string>* local_list); |
57 | 63 |
58 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, EmptyLogList); | 64 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, EmptyLogList); |
59 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SingleElementLogList); | 65 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SingleElementLogList); |
60 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, OverLimitLogList); | 66 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, OverLimitLogList); |
61 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SmallRecoveredListSize); | 67 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SmallRecoveredListSize); |
62 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, RemoveSizeFromLogList); | 68 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, RemoveSizeFromLogList); |
63 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptSizeOfLogList); | 69 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptSizeOfLogList); |
64 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptChecksumOfLogList); | 70 FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, CorruptChecksumOfLogList); |
65 | 71 |
66 DISALLOW_COPY_AND_ASSIGN(MetricsLogSerializer); | 72 DISALLOW_COPY_AND_ASSIGN(MetricsLogSerializer); |
67 }; | 73 }; |
68 | 74 |
69 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ | 75 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_SERIALIZER_H_ |
OLD | NEW |