Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: base/metrics/persistent_histogram_allocator.h

Issue 1803253002: Improved iterator for persistent memory allocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-hp
Patch Set: rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/persistent_histogram_allocator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/persistent_histogram_allocator.h
diff --git a/base/metrics/persistent_histogram_allocator.h b/base/metrics/persistent_histogram_allocator.h
index 570d5c0301458cde0ef57823d57815ad4d73de4f..12ac68500cb202c63ff8e813d6b16762022f6e85 100644
--- a/base/metrics/persistent_histogram_allocator.h
+++ b/base/metrics/persistent_histogram_allocator.h
@@ -23,19 +23,39 @@ BASE_EXPORT extern const Feature kPersistentHistogramsFeature;
// This class manages histograms created within a PersistentMemoryAllocator.
class BASE_EXPORT PersistentHistogramAllocator {
public:
- // This iterator is used for fetching persistent histograms from an allocator.
- class Iterator {
+ // A reference to a histogram. While this is implemented as PMA::Reference,
+ // it is not conceptually the same thing. Outside callers should always use
+ // a Reference matching the class it is for and not mix the two.
+ using Reference = PersistentMemoryAllocator::Reference;
+
+ // Iterator used for fetching persistent histograms from an allocator.
+ // It is lock-free and thread-safe.
+ // See PersistentMemoryAllocator::Iterator for more information.
+ class BASE_EXPORT Iterator {
public:
- bool is_clear() { return memory_iter.is_clear(); }
+ // Constructs an iterator on a given |allocator|, starting at the beginning.
+ // The allocator must live beyond the lifetime of the iterator.
+ explicit Iterator(PersistentHistogramAllocator* allocator);
+
+ // Gets the next histogram from persistent memory; returns null if there
+ // are no more histograms to be found. This may still be called again
+ // later to retrieve any new histograms added in the meantime.
+ std::unique_ptr<HistogramBase> GetNext() { return GetNextWithIgnore(0); }
+
+ // Gets the next histogram from persistent memory, ignoring one particular
+ // reference in the process. Pass |ignore| of zero (0) to ignore nothing.
+ std::unique_ptr<HistogramBase> GetNextWithIgnore(Reference ignore);
private:
- friend class PersistentHistogramAllocator;
+ // Weak-pointer to histogram allocator being iterated over.
+ PersistentHistogramAllocator* allocator_;
- // The iterator used for stepping through persistent memory iterables.
- PersistentMemoryAllocator::Iterator memory_iter;
- };
+ // The iterator used for stepping through objects in persistent memory.
+ // It is lock-free and thread-safe which is why this class is also such.
+ PersistentMemoryAllocator::Iterator memory_iter_;
- using Reference = PersistentMemoryAllocator::Reference;
+ DISALLOW_COPY_AND_ASSIGN(Iterator);
+ };
// A PersistentHistogramAllocator is constructed from a PersistentMemory-
// Allocator object of which it takes ownership.
@@ -65,14 +85,6 @@ class BASE_EXPORT PersistentHistogramAllocator {
// This method will return null if any problem is detected with the data.
std::unique_ptr<HistogramBase> GetHistogram(Reference ref);
- // Get the next histogram in persistent data based on iterator.
- std::unique_ptr<HistogramBase> GetNextHistogram(Iterator* iter) {
- return GetNextHistogramWithIgnore(iter, 0);
- }
-
- // Create an iterator for going through all histograms in an allocator.
- void CreateIterator(Iterator* iter);
-
// Allocate a new persistent histogram. The returned histogram will not
// be able to be located by other allocators until it is "finalized".
std::unique_ptr<HistogramBase> AllocateHistogram(
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/persistent_histogram_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698