| OLD | NEW |
| (Empty) |
| 1 // Copyright 2006-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 // Iterator over persisted metrics | |
| 17 #ifndef OMAHA_STATSREPORT_PERSISTENT_ITERATOR_WIN32_H__ | |
| 18 #define OMAHA_STATSREPORT_PERSISTENT_ITERATOR_WIN32_H__ | |
| 19 | |
| 20 #include "base/scoped_ptr.h" | |
| 21 #include "metrics.h" | |
| 22 #include "const-win32.h" | |
| 23 | |
| 24 #include <atlbase.h> | |
| 25 #include <atlstr.h> | |
| 26 #include <iterator> | |
| 27 | |
| 28 namespace stats_report { | |
| 29 | |
| 30 /// Forward iterator for persisted metrics | |
| 31 class PersistentMetricsIteratorWin32 | |
| 32 : public std::iterator<std::forward_iterator_tag, const MetricBase *> { | |
| 33 public: | |
| 34 /// @param app_name see MetricsAggregatorWin32 | |
| 35 explicit PersistentMetricsIteratorWin32(const wchar_t *app_name) | |
| 36 : state_(kUninitialized), | |
| 37 is_machine_(false) { | |
| 38 key_name_.Format(kStatsKeyFormatString, app_name); | |
| 39 Next(); | |
| 40 } | |
| 41 | |
| 42 /// @param app_name see MetricsAggregatorWin32 | |
| 43 /// @param is_machine specifies the registry hive | |
| 44 PersistentMetricsIteratorWin32(const wchar_t *app_name, bool is_machine) | |
| 45 : state_(kUninitialized), | |
| 46 is_machine_(is_machine) { | |
| 47 key_name_.Format(kStatsKeyFormatString, app_name); | |
| 48 Next(); | |
| 49 } | |
| 50 | |
| 51 /// Constructs the at-end iterator | |
| 52 PersistentMetricsIteratorWin32() : state_(kUninitialized) { | |
| 53 } | |
| 54 | |
| 55 MetricBase *operator* () { | |
| 56 return Current(); | |
| 57 } | |
| 58 MetricBase *operator-> () { | |
| 59 return Current(); | |
| 60 } | |
| 61 | |
| 62 /// Preincrement, we don't implement postincrement because we don't | |
| 63 /// want to deal with making iterators copyable, comparable etc. | |
| 64 PersistentMetricsIteratorWin32 &operator++() { | |
| 65 Next(); | |
| 66 | |
| 67 return (*this); | |
| 68 } | |
| 69 | |
| 70 /// Compare for equality with o. | |
| 71 bool equals(const PersistentMetricsIteratorWin32 &o) const { | |
| 72 // compare equal to self, and end iterators compare equal | |
| 73 if ((this == &o) || (NULL == current_value_.get() && | |
| 74 NULL == o.current_value_.get())) | |
| 75 return true; | |
| 76 | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 private: | |
| 81 MetricBase *Current() { | |
| 82 DCHECK(current_value_.get()); | |
| 83 return current_value_.get(); | |
| 84 } | |
| 85 | |
| 86 enum IterationState { | |
| 87 kUninitialized, | |
| 88 kCounts, | |
| 89 kTimings, | |
| 90 kIntegers, | |
| 91 kBooleans, | |
| 92 kFinished, | |
| 93 }; | |
| 94 | |
| 95 /// Walk to the next key/value under iteration | |
| 96 void Next(); | |
| 97 | |
| 98 /// Keeps track of which subkey we're iterating over | |
| 99 IterationState state_; | |
| 100 | |
| 101 /// The full path from HKCU to the key we iterate over | |
| 102 CString key_name_; | |
| 103 | |
| 104 /// The top-level key we're iterating over, valid only | |
| 105 /// after first call to Next(). | |
| 106 CRegKey key_; | |
| 107 | |
| 108 /// The subkey we're currently enumerating over | |
| 109 CRegKey sub_key_; | |
| 110 | |
| 111 /// Current value we're indexing over | |
| 112 DWORD value_index_; | |
| 113 | |
| 114 /// Name of the value under the iterator | |
| 115 CStringA current_value_name_; | |
| 116 | |
| 117 /// The metric under the iterator | |
| 118 scoped_ptr<MetricBase> current_value_; | |
| 119 | |
| 120 /// Specifies HKLM or HKCU, respectively. | |
| 121 bool is_machine_; | |
| 122 }; | |
| 123 | |
| 124 inline bool operator == (const PersistentMetricsIteratorWin32 &a, | |
| 125 const PersistentMetricsIteratorWin32 &b) { | |
| 126 return a.equals(b); | |
| 127 } | |
| 128 | |
| 129 inline bool operator != (const PersistentMetricsIteratorWin32 &a, | |
| 130 const PersistentMetricsIteratorWin32 &b) { | |
| 131 return !a.equals(b); | |
| 132 } | |
| 133 | |
| 134 } // namespace stats_report | |
| 135 | |
| 136 #endif // OMAHA_STATSREPORT_PERSISTENT_ITERATOR_WIN32_H__ | |
| OLD | NEW |