OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | 5 #ifndef BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ |
6 #define BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | 6 #define BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 public: | 23 public: |
24 PersistentSystemProfile(); | 24 PersistentSystemProfile(); |
25 ~PersistentSystemProfile(); | 25 ~PersistentSystemProfile(); |
26 | 26 |
27 // This object can store records in multiple memory allocators. | 27 // This object can store records in multiple memory allocators. |
28 void RegisterPersistentAllocator( | 28 void RegisterPersistentAllocator( |
29 base::PersistentMemoryAllocator* memory_allocator); | 29 base::PersistentMemoryAllocator* memory_allocator); |
30 void DeregisterPersistentAllocator( | 30 void DeregisterPersistentAllocator( |
31 base::PersistentMemoryAllocator* memory_allocator); | 31 base::PersistentMemoryAllocator* memory_allocator); |
32 | 32 |
33 // Stores a complete system profile. | 33 // Stores a complete system profile. Use the version taking the serialized |
| 34 // version if available to avoid multiple serialization actions. |
34 void SetSystemProfile(const std::string& serialized_profile); | 35 void SetSystemProfile(const std::string& serialized_profile); |
| 36 void SetSystemProfile(const SystemProfileProto& profile); |
| 37 |
| 38 // Tests if a persistent memory allocator contains an system profile. |
| 39 static bool HasSystemProfile( |
| 40 const base::PersistentMemoryAllocator& memory_allocator); |
35 | 41 |
36 // Retrieves the system profile from a persistent memory allocator. Returns | 42 // Retrieves the system profile from a persistent memory allocator. Returns |
37 // true if a profile was successfully retrieved. | 43 // true if a profile was successfully retrieved. |
38 static bool GetSystemProfile( | 44 static bool GetSystemProfile( |
39 const base::PersistentMemoryAllocator& memory_allocator, | 45 const base::PersistentMemoryAllocator& memory_allocator, |
40 SystemProfileProto* system_profile); | 46 SystemProfileProto* system_profile); |
41 | 47 |
42 private: | 48 private: |
43 friend class PersistentSystemProfileTest; | 49 friend class PersistentSystemProfileTest; |
44 | 50 |
(...skipping 13 matching lines...) Expand all Loading... |
58 // Construct an allocator for reading. | 64 // Construct an allocator for reading. |
59 RecordAllocator(const base::PersistentMemoryAllocator* memory_allocator); | 65 RecordAllocator(const base::PersistentMemoryAllocator* memory_allocator); |
60 | 66 |
61 // These methods manage writing records to the allocator. Do not mix these | 67 // These methods manage writing records to the allocator. Do not mix these |
62 // with "read" calls; it's one or the other. | 68 // with "read" calls; it's one or the other. |
63 void Reset(); | 69 void Reset(); |
64 bool Write(RecordType type, const std::string& record); | 70 bool Write(RecordType type, const std::string& record); |
65 | 71 |
66 // Read a record from the allocator. Do not mix this with "write" calls; | 72 // Read a record from the allocator. Do not mix this with "write" calls; |
67 // it's one or the other. | 73 // it's one or the other. |
| 74 bool HasMoreData() const; |
68 bool Read(RecordType* type, std::string* record) const; | 75 bool Read(RecordType* type, std::string* record) const; |
69 | 76 |
70 base::PersistentMemoryAllocator* allocator() { return allocator_; } | 77 base::PersistentMemoryAllocator* allocator() { return allocator_; } |
71 | 78 |
72 private: | 79 private: |
73 // Advance to the next record segment in the memory allocator. | 80 // Advance to the next record segment in the memory allocator. |
74 bool NextSegment() const; | 81 bool NextSegment() const; |
75 | 82 |
76 // Advance to the next record segment, creating a new one if necessary with | 83 // Advance to the next record segment, creating a new one if necessary with |
77 // sufficent |min_size| space. | 84 // sufficent |min_size| space. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 124 |
118 GlobalPersistentSystemProfile() {} | 125 GlobalPersistentSystemProfile() {} |
119 ~GlobalPersistentSystemProfile() {} | 126 ~GlobalPersistentSystemProfile() {} |
120 | 127 |
121 DISALLOW_COPY_AND_ASSIGN(GlobalPersistentSystemProfile); | 128 DISALLOW_COPY_AND_ASSIGN(GlobalPersistentSystemProfile); |
122 }; | 129 }; |
123 | 130 |
124 } // namespace metrics | 131 } // namespace metrics |
125 | 132 |
126 #endif // BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | 133 #endif // BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ |
OLD | NEW |