Index: base/feature_list.cc |
diff --git a/base/feature_list.cc b/base/feature_list.cc |
index 89b105defc6df0119688cb3b0e708f1b905f36df..47da1bf6575afd707a729edf7468efd06a426d20 100644 |
--- a/base/feature_list.cc |
+++ b/base/feature_list.cc |
@@ -12,6 +12,7 @@ |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
#include "base/metrics/field_trial.h" |
+#include "base/pickle.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
@@ -27,6 +28,20 @@ FeatureList* g_instance = nullptr; |
// Tracks whether the FeatureList instance was initialized via an accessor. |
bool g_initialized_from_accessor = false; |
+const uint32_t kFeatureType = 0x06567CA6 + 1; // SHA1(FeatureEntry) v1 |
+ |
+struct FeatureEntry { |
+ // Expected size for 32/64-bit check. |
+ static constexpr size_t kExpectedInstanceSize = 8; |
+ |
+ // Specifies whether a feature override enables or disables the future. Same |
+ // values as the OverrideState enum in feature_list.h |
+ uint32_t override_state; |
+ |
+ // Size of the pickled structure, NOT the total size of this entry. |
+ uint32_t size; |
+}; |
+ |
// Some characters are not allowed to appear in feature names or the associated |
// field trial names, as they are used as special characters for command-line |
// serialization. This function checks that the strings are ASCII (since they |
@@ -56,6 +71,23 @@ void FeatureList::InitializeFromCommandLine( |
initialized_from_command_line_ = true; |
} |
+void FeatureList::InitializeFromSharedMemory( |
+ SharedPersistentMemoryAllocator* allocator) { |
+ DCHECK(!initialized_); |
+ |
+ SharedPersistentMemoryAllocator::Iterator iter(allocator); |
+ |
+ SharedPersistentMemoryAllocator::Reference ref; |
+ while ((ref = iter.GetNextOfType(kFeatureType)) != |
+ SharedPersistentMemoryAllocator::kReferenceNull) { |
+ const FeatureEntry* entry = |
+ allocator->GetAsObject<const FeatureEntry>(ref, kFeatureType); |
+ LOG(ERROR) << entry; |
+ // get the field trial, feature name, and overiden state and call |
+ // registeroverride here. |
+ } |
+} |
+ |
bool FeatureList::IsFeatureOverriddenFromCommandLine( |
const std::string& feature_name, |
OverrideState state) const { |
@@ -98,6 +130,35 @@ void FeatureList::RegisterFieldTrialOverride(const std::string& feature_name, |
RegisterOverride(feature_name, override_state, field_trial); |
} |
+void FeatureList::AddFeaturesToAllocator( |
+ FieldTrialList::FieldTrialAllocator* allocator) { |
+ DCHECK(initialized_); |
+ |
+ for (const auto& override : overrides_) { |
+ Pickle pickle; |
+ pickle.WriteString(override.first); |
+ if (override.second.field_trial) |
+ pickle.WriteString(override.second.field_trial->trial_name()); |
+ |
+ size_t total_size = sizeof(FeatureEntry) + pickle.size(); |
+ SharedPersistentMemoryAllocator::Reference ref = |
+ allocator->Allocate(total_size, kFeatureType); |
+ if (!ref) |
+ return; |
+ |
+ FeatureEntry* entry = |
+ allocator->GetAsObject<FeatureEntry>(ref, kFeatureType); |
+ entry->override_state = override.second.overridden_state; |
+ entry->size = pickle.size(); |
+ |
+ char* dst = reinterpret_cast<char*>(entry) + sizeof(FeatureEntry); |
+ memcpy(dst, pickle.data(), pickle.size()); |
+ |
+ allocator->MakeIterable(ref); |
+ // should we add a ref to each feature? |
+ } |
+} |
+ |
void FeatureList::GetFeatureOverrides(std::string* enable_overrides, |
std::string* disable_overrides) { |
DCHECK(initialized_); |