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

Unified Diff: base/metrics/field_trial.h

Issue 2412113002: Use SharedPersistentMemoryAllocator to share field trial state (Closed)
Patch Set: move field_trial_allocator into anon namespace Created 4 years, 2 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
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.h
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h
index 99e705a1fa82dd80a34701cbad08e857c589d9f7..d29719e3c84fc085e94766bf3095a876c3861b3e 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -69,7 +69,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory.h"
+#include "base/metrics/persistent_memory_allocator.h"
#include "base/observer_list_threadsafe.h"
+#include "base/process/launch.h"
#include "base/strings/string_piece.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
@@ -479,14 +481,22 @@ class BASE_EXPORT FieldTrialList {
const base::CommandLine& cmd_line,
const char* field_trial_handle_switch);
+#if defined(OS_WIN)
+ static void AppendFieldTrialHandleIfNeeded(
+ base::HandlesToInheritVector* handles);
+#endif
+
// Adds a switch to the command line containing the field trial state as a
// string (if not using shared memory to share field trial state), or the
// shared memory handle + length.
// Needs the |field_trial_handle_switch| argument to be passed in since base/
// can't depend on content/.
- static std::unique_ptr<base::SharedMemory> CopyFieldTrialStateToFlags(
- const char* field_trial_handle_switch,
- base::CommandLine* cmd_line);
+ static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch,
+ base::CommandLine* cmd_line);
+
+ // Returns a pointer to the global field trial allocator object for testing.
+ static base::SharedPersistentMemoryAllocator*
+ GetFieldTrialAllocatorForTesting();
// Create a FieldTrial with the given |name| and using 100% probability for
// the FieldTrial, force FieldTrial to have the same group string as
@@ -512,6 +522,25 @@ class BASE_EXPORT FieldTrialList {
static size_t GetFieldTrialCount();
private:
+ // Allow tests to access our innards for testing purposes.
+ FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
+
+ // Expects a mapped piece of shared memory |shm| that was created from the
+ // browser process's field_trial_allocator and shared via the command line.
+ // This function recreates the allocator, iterates through all the field
+ // trials in it, and creates them via CreateFieldTrial().
+ static void CreateTrialsFromSharedMemory(
+ std::unique_ptr<base::SharedMemory> shm);
+
+ // Instantiate the field trial allocator, add all existing field trials to it,
+ // and duplicates its handle to a read-only handle, which gets stored in
+ // |readonly_allocator_handle|.
+ static void InstantiateFieldTrialAllocatorIfNeeded();
+
+ // Called in NotifyFieldTrialGroupSelection(). Updates field_trial_allocator
+ // by adding the newly-created |field_trial|.
+ static void UpdateFieldTrialAllocator(FieldTrial* field_trial);
+
// A map from FieldTrial names to the actual instances.
typedef std::map<std::string, FieldTrial*> RegistrationMap;
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698