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

Side by Side Diff: base/metrics/field_trial.h

Issue 2530573002: Share field trial allocator on zygote-using Linuxes (Closed)
Patch Set: fix ifdef Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // FieldTrial is a class for handling details of statistical experiments 5 // FieldTrial is a class for handling details of statistical experiments
6 // performed by actual users in the field (i.e., in a shipped or beta product). 6 // performed by actual users in the field (i.e., in a shipped or beta product).
7 // All code is called exclusively on the UI thread currently. 7 // All code is called exclusively on the UI thread currently.
8 // 8 //
9 // The simplest example is an experiment to see whether one of two options 9 // The simplest example is an experiment to see whether one of two options
10 // produces "better" results across our user population. In that scenario, UMA 10 // produces "better" results across our user population. In that scenario, UMA
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 static void CreateTrialsFromCommandLine( 506 static void CreateTrialsFromCommandLine(
507 const base::CommandLine& cmd_line, 507 const base::CommandLine& cmd_line,
508 const char* field_trial_handle_switch); 508 const char* field_trial_handle_switch);
509 509
510 #if defined(OS_WIN) 510 #if defined(OS_WIN)
511 // On Windows, we need to explicitly pass down any handles to be inherited. 511 // On Windows, we need to explicitly pass down any handles to be inherited.
512 // This function adds the shared memory handle to field trial state to the 512 // This function adds the shared memory handle to field trial state to the
513 // list of handles to be inherited. 513 // list of handles to be inherited.
514 static void AppendFieldTrialHandleIfNeeded( 514 static void AppendFieldTrialHandleIfNeeded(
515 base::HandlesToInheritVector* handles); 515 base::HandlesToInheritVector* handles);
516 #elif defined(OS_POSIX)
517 // On POSIX, we also need to explicitly pass down any fds to be inherited via
518 // |files_to_register| in child_process_launcher.cc. This gets the handle so
Alexei Svitkine (slow) 2016/11/24 17:44:34 I don't think this should mention child_process_la
lawrencewu 2016/11/24 18:16:13 Done.
519 // we can add it to the mapping there. Returns -1 if no handle exists or was
520 // not initialized properly.
521 static int GetFieldTrialHandle();
516 #endif 522 #endif
517 523
518 // Adds a switch to the command line containing the field trial state as a 524 // Adds a switch to the command line containing the field trial state as a
519 // string (if not using shared memory to share field trial state), or the 525 // string (if not using shared memory to share field trial state), or the
520 // shared memory handle + length. 526 // shared memory handle + length.
521 // Needs the |field_trial_handle_switch| argument to be passed in since base/ 527 // Needs the |field_trial_handle_switch| argument to be passed in since base/
522 // can't depend on content/. 528 // can't depend on content/.
523 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, 529 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch,
524 base::CommandLine* cmd_line); 530 base::CommandLine* cmd_line);
525 531
(...skipping 24 matching lines...) Expand all
550 // Return the number of active field trials. 556 // Return the number of active field trials.
551 static size_t GetFieldTrialCount(); 557 static size_t GetFieldTrialCount();
552 558
553 private: 559 private:
554 // Allow tests to access our innards for testing purposes. 560 // Allow tests to access our innards for testing purposes.
555 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 561 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
556 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 562 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
557 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, 563 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest,
558 DoNotAddSimulatedFieldTrialsToAllocator); 564 DoNotAddSimulatedFieldTrialsToAllocator);
559 565
560 #if defined(OS_WIN) 566 // Takes in |handle_switch| from the command line which represents the shared
561 // Takes in |handle| that should have been retrieved from the command line and 567 // memory handle for field trials, parses it, and creates the field trials.
562 // creates a SharedMemoryHandle from it, and then calls 568 // Returns true on success, false on failure.
563 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. 569 static bool CreateTrialsFromHandleSwitch(const std::string& handle_switch);
564 static bool CreateTrialsFromWindowsHandle(HANDLE handle); 570
565 #endif 571 // Takes an unmapped SharedMemoryHandle, creates a SharedMemory object from it
572 // and maps it with the correct size.
573 static bool CreateTrialsFromSharedMemoryHandle(SharedMemoryHandle shm_handle);
566 574
567 // Expects a mapped piece of shared memory |shm| that was created from the 575 // Expects a mapped piece of shared memory |shm| that was created from the
568 // browser process's field_trial_allocator and shared via the command line. 576 // browser process's field_trial_allocator and shared via the command line.
569 // This function recreates the allocator, iterates through all the field 577 // This function recreates the allocator, iterates through all the field
570 // trials in it, and creates them via CreateFieldTrial(). Returns true if 578 // trials in it, and creates them via CreateFieldTrial(). Returns true if
571 // successful and false otherwise. 579 // successful and false otherwise.
572 static bool CreateTrialsFromSharedMemory( 580 static bool CreateTrialsFromSharedMemory(
573 std::unique_ptr<base::SharedMemory> shm); 581 std::unique_ptr<base::SharedMemory> shm);
574 582
575 // Instantiate the field trial allocator, add all existing field trials to it, 583 // Instantiate the field trial allocator, add all existing field trials to it,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // browser and child processes, but readonly in the child. 633 // browser and child processes, but readonly in the child.
626 // In the future, we may want to move this to a more generic place if we want 634 // In the future, we may want to move this to a more generic place if we want
627 // to start passing more data other than field trials. 635 // to start passing more data other than field trials.
628 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr; 636 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr;
629 637
630 #if defined(OS_WIN) 638 #if defined(OS_WIN)
631 // Readonly copy of the handle to the allocator. Needs to be a member variable 639 // Readonly copy of the handle to the allocator. Needs to be a member variable
632 // because it's needed from both CopyFieldTrialStateToFlags() and 640 // because it's needed from both CopyFieldTrialStateToFlags() and
633 // AppendFieldTrialHandleIfNeeded(). 641 // AppendFieldTrialHandleIfNeeded().
634 HANDLE readonly_allocator_handle_ = nullptr; 642 HANDLE readonly_allocator_handle_ = nullptr;
643 #elif defined(OS_POSIX)
644 int readonly_allocator_handle_ = -1;
Alexei Svitkine (slow) 2016/11/24 17:44:34 Hmm, how about having this be the same var on Win
lawrencewu 2016/11/24 18:16:13 That's much cleaner, done.
635 #endif 645 #endif
636 646
637 // Tracks whether CreateTrialsFromCommandLine() has been called. 647 // Tracks whether CreateTrialsFromCommandLine() has been called.
638 bool create_trials_from_command_line_called_ = false; 648 bool create_trials_from_command_line_called_ = false;
639 649
640 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 650 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
641 }; 651 };
642 652
643 } // namespace base 653 } // namespace base
644 654
645 #endif // BASE_METRICS_FIELD_TRIAL_H_ 655 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW
« 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