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

Unified Diff: components/metrics/persistent_system_profile.cc

Issue 2918533003: Send metrics with embedded system profiles after system startup. (Closed)
Patch Set: addressed final review comments Created 3 years, 6 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
Index: components/metrics/persistent_system_profile.cc
diff --git a/components/metrics/persistent_system_profile.cc b/components/metrics/persistent_system_profile.cc
index 526b1407f0fa7351be0bc3900c361847307c2432..dc4e7eb7a772e7ad88c62a9fbccc2c2cc0431c67 100644
--- a/components/metrics/persistent_system_profile.cc
+++ b/components/metrics/persistent_system_profile.cc
@@ -101,6 +101,22 @@ bool PersistentSystemProfile::RecordAllocator::Write(
return true;
}
+bool PersistentSystemProfile::RecordAllocator::HasMoreData() const {
+ if (alloc_reference_ == 0 && !NextSegment())
+ return false;
+
+ char* block =
+ allocator_->GetAsArray<char>(alloc_reference_, kTypeIdSystemProfile,
+ base::PersistentMemoryAllocator::kSizeAny);
+ if (!block)
+ return false;
+
+ RecordHeader header;
+ header.as_atomic = base::subtle::Acquire_Load(
+ reinterpret_cast<base::subtle::Atomic32*>(block + end_offset_));
+ return header.as_parts.type != kUnusedSpace;
+}
+
bool PersistentSystemProfile::RecordAllocator::Read(RecordType* type,
std::string* record) const {
*type = kUnusedSpace;
@@ -276,6 +292,21 @@ void PersistentSystemProfile::SetSystemProfile(
}
}
+void PersistentSystemProfile::SetSystemProfile(
+ const SystemProfileProto& profile) {
+ std::string serialized_profile;
+ if (!profile.SerializeToString(&serialized_profile))
+ return;
+ SetSystemProfile(serialized_profile);
+}
+
+// static
+bool PersistentSystemProfile::HasSystemProfile(
+ const base::PersistentMemoryAllocator& memory_allocator) {
+ const RecordAllocator records(&memory_allocator);
+ return records.HasMoreData();
+}
+
// static
bool PersistentSystemProfile::GetSystemProfile(
const base::PersistentMemoryAllocator& memory_allocator,
« no previous file with comments | « components/metrics/persistent_system_profile.h ('k') | components/metrics/persistent_system_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698