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

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

Issue 2530573002: Share field trial allocator on zygote-using Linuxes (Closed)
Patch Set: make handle read-only 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 static void CreateTrialsFromCommandLine( 504 static void CreateTrialsFromCommandLine(
505 const base::CommandLine& cmd_line, 505 const base::CommandLine& cmd_line,
506 const char* field_trial_handle_switch); 506 const char* field_trial_handle_switch);
507 507
508 #if defined(OS_WIN) 508 #if defined(OS_WIN)
509 // On Windows, we need to explicitly pass down any handles to be inherited. 509 // On Windows, we need to explicitly pass down any handles to be inherited.
510 // This function adds the shared memory handle to field trial state to the 510 // This function adds the shared memory handle to field trial state to the
511 // list of handles to be inherited. 511 // list of handles to be inherited.
512 static void AppendFieldTrialHandleIfNeeded( 512 static void AppendFieldTrialHandleIfNeeded(
513 base::HandlesToInheritVector* handles); 513 base::HandlesToInheritVector* handles);
514 #elif defined(OS_POSIX)
515 // On POSIX, we also need to explicitly pass down any fds to be inherited via
516 // |files_to_register| in child_process_launcher.cc. This gets the handle so
517 // we can add it to the mapping there.
Alexei Svitkine (slow) 2016/11/23 17:49:55 You check the return value of this for -1 but don'
lawrencewu 2016/11/23 18:59:44 Done.
518 static int FieldTrialHandle();
Alexei Svitkine (slow) 2016/11/23 17:49:55 Functions should use a verb. GetFieldTrialHandle()
lawrencewu 2016/11/23 18:59:44 Done.
514 #endif 519 #endif
515 520
516 // Adds a switch to the command line containing the field trial state as a 521 // Adds a switch to the command line containing the field trial state as a
517 // string (if not using shared memory to share field trial state), or the 522 // string (if not using shared memory to share field trial state), or the
518 // shared memory handle + length. 523 // shared memory handle + length.
519 // Needs the |field_trial_handle_switch| argument to be passed in since base/ 524 // Needs the |field_trial_handle_switch| argument to be passed in since base/
520 // can't depend on content/. 525 // can't depend on content/.
521 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, 526 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch,
522 base::CommandLine* cmd_line); 527 base::CommandLine* cmd_line);
523 528
(...skipping 23 matching lines...) Expand all
547 552
548 // Return the number of active field trials. 553 // Return the number of active field trials.
549 static size_t GetFieldTrialCount(); 554 static size_t GetFieldTrialCount();
550 555
551 private: 556 private:
552 // Allow tests to access our innards for testing purposes. 557 // Allow tests to access our innards for testing purposes.
553 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 558 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
554 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 559 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
555 560
556 #if defined(OS_WIN) 561 #if defined(OS_WIN)
557 // Takes in |handle| that should have been retrieved from the command line and 562 // Takes in |cli_switch| that should have been retrieved from the command line
558 // creates a SharedMemoryHandle from it, and then calls 563 // and constructs a SharedMemoryHandle from it, and then calls
559 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure. 564 // CreateTrialsFromSharedMemory(). Returns true on success, false on failure.
560 static bool CreateTrialsFromWindowsHandle(HANDLE handle); 565 static bool CreateTrialsFromWindowsSwitch(std::string cli_switch);
Alexei Svitkine (slow) 2016/11/23 17:49:55 Don't pass strings by value. const std::string&
lawrencewu 2016/11/23 18:59:44 Done.
566 #elif defined(OS_POSIX)
567 // Takes in |cli_switch| that should have been retrieved from the command
568 // line, looks up the fd using GlobalDescriptor, constructs a
569 // SharedMemoryHandle from it, and then calls CreateTrialsFromSharedMemory().
570 // Returns true on success, false on failure.
571 static bool CreateTrialsFromPosixSwitch(std::string cli_switch);
Alexei Svitkine (slow) 2016/11/23 17:49:55 Do we need two separate functions? Why not keeping
lawrencewu 2016/11/23 18:59:44 Yeah, that works better. Done.
561 #endif 572 #endif
562 573
574 // Takes an unmapped SharedMemoryHandle, creates a SharedMemory object from it
575 // and maps it with the correct size.
576 static bool CreateTrialsFromSharedMemoryHandle(SharedMemoryHandle shm_handle);
577
563 // Expects a mapped piece of shared memory |shm| that was created from the 578 // Expects a mapped piece of shared memory |shm| that was created from the
564 // browser process's field_trial_allocator and shared via the command line. 579 // browser process's field_trial_allocator and shared via the command line.
565 // This function recreates the allocator, iterates through all the field 580 // This function recreates the allocator, iterates through all the field
566 // trials in it, and creates them via CreateFieldTrial(). Returns true if 581 // trials in it, and creates them via CreateFieldTrial(). Returns true if
567 // successful and false otherwise. 582 // successful and false otherwise.
568 static bool CreateTrialsFromSharedMemory( 583 static bool CreateTrialsFromSharedMemory(
569 std::unique_ptr<base::SharedMemory> shm); 584 std::unique_ptr<base::SharedMemory> shm);
570 585
571 // Instantiate the field trial allocator, add all existing field trials to it, 586 // Instantiate the field trial allocator, add all existing field trials to it,
572 // and duplicates its handle to a read-only handle, which gets stored in 587 // and duplicates its handle to a read-only handle, which gets stored in
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // browser and child processes, but readonly in the child. 636 // browser and child processes, but readonly in the child.
622 // In the future, we may want to move this to a more generic place if we want 637 // In the future, we may want to move this to a more generic place if we want
623 // to start passing more data other than field trials. 638 // to start passing more data other than field trials.
624 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr; 639 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr;
625 640
626 #if defined(OS_WIN) 641 #if defined(OS_WIN)
627 // Readonly copy of the handle to the allocator. Needs to be a member variable 642 // Readonly copy of the handle to the allocator. Needs to be a member variable
628 // because it's needed from both CopyFieldTrialStateToFlags() and 643 // because it's needed from both CopyFieldTrialStateToFlags() and
629 // AppendFieldTrialHandleIfNeeded(). 644 // AppendFieldTrialHandleIfNeeded().
630 HANDLE readonly_allocator_handle_ = nullptr; 645 HANDLE readonly_allocator_handle_ = nullptr;
646 #elif defined(OS_POSIX)
647 int readonly_allocator_handle_ = -1;
631 #endif 648 #endif
632 649
633 // Tracks whether CreateTrialsFromCommandLine() has been called. 650 // Tracks whether CreateTrialsFromCommandLine() has been called.
634 bool create_trials_from_command_line_called_ = false; 651 bool create_trials_from_command_line_called_ = false;
635 652
636 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 653 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
637 }; 654 };
638 655
639 } // namespace base 656 } // namespace base
640 657
641 #endif // BASE_METRICS_FIELD_TRIAL_H_ 658 #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