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

Unified Diff: base/metrics/field_trial.h

Issue 2530573002: Share field trial allocator on zygote-using Linuxes (Closed)
Patch Set: fallback to command line if descriptor not found Created 4 years, 1 month 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') | content/app/content_main_runner.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 34b9782bee0fe06c51abf1383c3d98c247c4a958..c28def2f6f38c010c8f161625bb197496e5427d2 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -65,6 +65,7 @@
#include "base/base_export.h"
#include "base/command_line.h"
+#include "base/files/file.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
@@ -507,12 +508,25 @@ class BASE_EXPORT FieldTrialList {
const base::CommandLine& cmd_line,
const char* field_trial_handle_switch);
+#if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MACOSX) && \
+ !defined(OS_ANDROID)
+ // On POSIX systems that use the zygote, we look up the correct fd that backs
+ // the shared memory segment containing the field trials by looking it up via
+ // an fd key in GlobalDescriptors. Returns true on success, false on failure.
+ static bool CreateTrialsFromDescriptor(int fd_key);
+#endif
+
#if defined(OS_WIN)
// On Windows, we need to explicitly pass down any handles to be inherited.
// This function adds the shared memory handle to field trial state to the
// list of handles to be inherited.
static void AppendFieldTrialHandleIfNeeded(
base::HandlesToInheritVector* handles);
+#elif defined(OS_POSIX)
+ // On POSIX, we also need to explicitly pass down this file descriptor that
+ // should be shared with the child process. Returns kInvalidPlatformFile if no
+ // handle exists or was not initialized properly.
+ static PlatformFile GetFieldTrialHandle();
#endif
// Adds a switch to the command line containing the field trial state as a
@@ -558,12 +572,16 @@ class BASE_EXPORT FieldTrialList {
DoNotAddSimulatedFieldTrialsToAllocator);
#if defined(OS_WIN)
- // Takes in |handle| that should have been retrieved from the command line and
- // creates a SharedMemoryHandle from it, and then calls
- // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
- static bool CreateTrialsFromWindowsHandle(HANDLE handle);
+ // Takes in |handle_switch| from the command line which represents the shared
+ // memory handle for field trials, parses it, and creates the field trials.
+ // Returns true on success, false on failure.
+ static bool CreateTrialsFromHandleSwitch(const std::string& handle_switch);
#endif
+ // Takes an unmapped SharedMemoryHandle, creates a SharedMemory object from it
+ // and maps it with the correct size.
+ static bool CreateTrialsFromSharedMemoryHandle(SharedMemoryHandle shm_handle);
+
// 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
@@ -627,12 +645,10 @@ class BASE_EXPORT FieldTrialList {
// to start passing more data other than field trials.
std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr;
-#if defined(OS_WIN)
// Readonly copy of the handle to the allocator. Needs to be a member variable
// because it's needed from both CopyFieldTrialStateToFlags() and
// AppendFieldTrialHandleIfNeeded().
- HANDLE readonly_allocator_handle_ = nullptr;
-#endif
+ PlatformFile readonly_allocator_handle_ = kInvalidPlatformFile;
// Tracks whether CreateTrialsFromCommandLine() has been called.
bool create_trials_from_command_line_called_ = false;
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | content/app/content_main_runner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698