Index: base/metrics/field_trial.h |
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h |
index 34b9782bee0fe06c51abf1383c3d98c247c4a958..c61afd93b4c15dc65e3a7bf3d80cac83892c7c6a 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" |
@@ -76,6 +77,13 @@ |
#include "base/synchronization/lock.h" |
#include "base/time/time.h" |
+// On systems that use the zygote process to spawn child processes, we must |
+// retrieve the correct fd using the mapping in GlobalDescriptors. |
+#if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MACOSX) && \ |
+ !defined(OS_ANDROID) |
+#define POSIX_WITH_ZYGOTE 1 |
Alexei Svitkine (slow)
2016/11/28 16:56:13
I don't think we should define this in the header
lawrencewu
2016/11/29 14:38:07
Done.
|
+#endif |
+ |
namespace base { |
class FieldTrialList; |
@@ -503,9 +511,9 @@ class BASE_EXPORT FieldTrialList { |
// If not, then create the trials as before (using the kForceFieldTrials |
// switch). Needs the |field_trial_handle_switch| argument to be passed in |
// since base/ can't depend on content/. |
- static void CreateTrialsFromCommandLine( |
- const base::CommandLine& cmd_line, |
- const char* field_trial_handle_switch); |
+ static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, |
+ const char* field_trial_handle_switch, |
+ const int field_trial_handle); |
Alexei Svitkine (slow)
2016/11/28 16:56:13
Nit: No reason to mark primitive params (int) as c
lawrencewu
2016/11/29 14:38:07
Done.
|
#if defined(OS_WIN) |
// On Windows, we need to explicitly pass down any handles to be inherited. |
@@ -513,6 +521,11 @@ class BASE_EXPORT FieldTrialList { |
// 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 +571,23 @@ 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 |
+ |
+#if defined(POSIX_WITH_ZYGOTE) |
+ // 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 CreateTrialsFromFdKey(const int fd_key); |
Alexei Svitkine (slow)
2016/11/28 16:56:13
Nit: No const
lawrencewu
2016/11/29 14:38:07
Done.
|
#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 +651,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; |