Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc |
| index 63f549e5729d69b3587de96dbef7ad61764bac26..388e1171e2e40e0d86e5c4d9fefd012c213fdbaf 100644 |
| --- a/base/metrics/field_trial.cc |
| +++ b/base/metrics/field_trial.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/command_line.h" |
| #include "base/feature_list.h" |
| #include "base/logging.h" |
| +#include "base/metrics/field_trial_param_associator.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/pickle.h" |
| #include "base/process/memory.h" |
| @@ -55,21 +56,23 @@ struct FieldTrialEntry { |
| // Size of the pickled structure, NOT the total size of this entry. |
| uint32_t size; |
|
Alexei Svitkine (slow)
2016/11/01 14:57:16
Add a blank line below this and a comment about th
lawrencewu
2016/11/01 18:29:05
Done.
|
| + PickleIterator GetPickleIterator() const { |
| + char* src = reinterpret_cast<char*>(const_cast<FieldTrialEntry*>(this)) + |
| + sizeof(FieldTrialEntry); |
| + |
| + Pickle pickle(src, size); |
| + return PickleIterator(pickle); |
| + } |
| // Calling this is only valid when the entry is initialized. That is, it |
| // resides in shared memory and has a pickle containing the trial name and |
| // group name following it. |
| bool GetTrialAndGroupName(StringPiece* trial_name, |
| StringPiece* group_name) const { |
| - char* src = reinterpret_cast<char*>(const_cast<FieldTrialEntry*>(this)) + |
| - sizeof(FieldTrialEntry); |
| - |
| - Pickle pickle(src, size); |
| - PickleIterator pickle_iter(pickle); |
| - |
| - if (!pickle_iter.ReadStringPiece(trial_name)) |
| + PickleIterator iter = GetPickleIterator(); |
| + if (!iter.ReadStringPiece(trial_name)) |
| return false; |
| - if (!pickle_iter.ReadStringPiece(group_name)) |
| + if (!iter.ReadStringPiece(group_name)) |
| return false; |
| return true; |
| } |
| @@ -181,6 +184,24 @@ HANDLE CreateReadOnlyHandle(SharedPersistentMemoryAllocator* allocator) { |
| } |
| #endif |
| +bool PickleFieldTrialState(const FieldTrial::State& trial_state, |
| + Pickle* pickle) { |
| + pickle->WriteString(trial_state.trial_name); |
| + pickle->WriteString(trial_state.group_name); |
| + |
| + std::map<std::string, std::string> params; |
| + if (!FieldTrialParamAssociator::GetInstance()->GetFieldTrialParamsWhileLocked( |
| + trial_state.trial_name.as_string(), |
| + trial_state.group_name.as_string(), ¶ms)) |
|
Alexei Svitkine (slow)
2016/11/01 14:57:16
Nit: {}'s
lawrencewu
2016/11/01 18:29:05
Done.
|
| + return false; |
| + |
| + for (const auto& param : params) { |
| + pickle->WriteString(StringPiece(param.first)); |
| + pickle->WriteString(StringPiece(param.second)); |
|
Alexei Svitkine (slow)
2016/11/01 14:57:16
Can you also add the changes to actually read from
lawrencewu
2016/11/01 18:29:05
Done.
|
| + } |
| + return true; |
| +} |
| + |
| } // namespace |
| // statics |
| @@ -904,8 +925,8 @@ void FieldTrialList::AddToAllocatorWhileLocked(FieldTrial* field_trial) { |
| return; |
| Pickle pickle; |
| - pickle.WriteString(trial_state.trial_name); |
| - pickle.WriteString(trial_state.group_name); |
| + if (!PickleFieldTrialState(trial_state, &pickle)) |
| + return; |
| size_t total_size = sizeof(FieldTrialEntry) + pickle.size(); |
| SharedPersistentMemoryAllocator::Reference ref = |