Chromium Code Reviews| Index: base/metrics/field_trial.h |
| diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h |
| index 7fedb375ae43ecebdafc941fcdcd257ff6faf57a..11fcffdfdac490e995262d73d8add3dfd1ae5d6e 100644 |
| --- a/base/metrics/field_trial.h |
| +++ b/base/metrics/field_trial.h |
| @@ -73,6 +73,7 @@ |
| #include "base/memory/shared_memory.h" |
| #include "base/metrics/persistent_memory_allocator.h" |
| #include "base/observer_list_threadsafe.h" |
| +#include "base/pickle.h" |
| #include "base/process/launch.h" |
| #include "base/strings/string_piece.h" |
| #include "base/synchronization/lock.h" |
| @@ -133,6 +134,42 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { |
| ~State(); |
| }; |
| + // We create one FieldTrialEntry per field trial in shared memory, via |
| + // AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a |
| + // base::Pickle object that we unpickle and read from. Any changes to this |
| + // structure requires a bump in kFieldTrialType id defined above. |
| + struct FieldTrialEntry { |
| + // Expected size for 32/64-bit check. |
| + static constexpr size_t kExpectedInstanceSize = 8; |
| + |
| + // Whether or not this field trial is activated. This is really just a |
| + // boolean but marked as a uint32_t for portability reasons. |
| + uint32_t activated; |
| + |
| + // Size of the pickled structure, NOT the total size of this entry. |
| + uint32_t pickle_size; |
| + |
| + // Returns an iterator over the data containing names and params. |
| + PickleIterator GetPickleIterator() const; |
|
bcwhite
2016/12/09 19:40:28
Can this method be private?
lawrencewu
2016/12/09 19:47:59
Done.
|
| + |
| + // Takes the iterator and writes out the first two items into |trial_name| |
| + // and |group_name|. |
| + bool ReadStringPair(PickleIterator* iter, |
|
bcwhite
2016/12/09 19:40:28
Can this method be private?
lawrencewu
2016/12/09 19:47:59
Done.
|
| + StringPiece* trial_name, |
| + StringPiece* group_name) const; |
| + |
| + // 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; |
| + |
| + // Calling this is only valid when the entry is initialized as well. Reads |
| + // the parameters following the trial and group name and stores them as |
| + // key-value mappings in |params|. |
| + bool GetParams(std::map<std::string, std::string>* params) const; |
| + }; |
| + |
| typedef std::vector<ActiveGroup> ActiveGroups; |
| // A return value to indicate that a given instance has not yet had a group |
| @@ -577,6 +614,17 @@ class BASE_EXPORT FieldTrialList { |
| // Clears all the params in the allocator. |
| static void ClearParamsFromSharedMemoryForTesting(); |
| + // We want to be able to dump field trial state to an allocator so that it |
| + // can be analyzed after a crash. |
| + static void DumpAllFieldTrialsToPersistentAllocator( |
| + PersistentMemoryAllocator* allocator); |
| + |
| + // We want to be able to retrieve field trial state from an allocator so that |
| + // it can be analyzed after a crash. |
|
bcwhite
2016/12/09 19:40:28
Comment that the pointers are into the persistent
|
| + static std::vector<FieldTrial::FieldTrialEntry*> |
| + GetAllFieldTrialsFromPersistentAllocator( |
| + PersistentMemoryAllocator* allocator); |
|
bcwhite
2016/12/09 19:40:28
const PMA*
|
| + |
| private: |
| // Allow tests to access our innards for testing purposes. |
| FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); |
| @@ -620,7 +668,8 @@ class BASE_EXPORT FieldTrialList { |
| // Adds the field trial to the allocator. Caller must hold a lock before |
| // calling this. |
| - static void AddToAllocatorWhileLocked(FieldTrial* field_trial); |
| + static void AddToAllocatorWhileLocked(PersistentMemoryAllocator* allocator, |
| + FieldTrial* field_trial); |
| // Activate the corresponding field trial entry struct in shared memory. |
| static void ActivateFieldTrialEntryWhileLocked(FieldTrial* field_trial); |