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

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

Issue 2862123002: Pass the GUID for the SharedMemoryHandle used by base::FieldTrialList. (Closed)
Patch Set: clang format Created 3 years, 7 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 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 #include "base/atomicops.h" 66 #include "base/atomicops.h"
67 #include "base/base_export.h" 67 #include "base/base_export.h"
68 #include "base/command_line.h" 68 #include "base/command_line.h"
69 #include "base/feature_list.h" 69 #include "base/feature_list.h"
70 #include "base/files/file.h" 70 #include "base/files/file.h"
71 #include "base/gtest_prod_util.h" 71 #include "base/gtest_prod_util.h"
72 #include "base/macros.h" 72 #include "base/macros.h"
73 #include "base/memory/ref_counted.h" 73 #include "base/memory/ref_counted.h"
74 #include "base/memory/shared_memory.h" 74 #include "base/memory/shared_memory.h"
75 #include "base/memory/shared_memory_handle.h"
75 #include "base/metrics/persistent_memory_allocator.h" 76 #include "base/metrics/persistent_memory_allocator.h"
76 #include "base/observer_list_threadsafe.h" 77 #include "base/observer_list_threadsafe.h"
77 #include "base/pickle.h" 78 #include "base/pickle.h"
78 #include "base/process/launch.h" 79 #include "base/process/launch.h"
79 #include "base/strings/string_piece.h" 80 #include "base/strings/string_piece.h"
80 #include "base/synchronization/lock.h" 81 #include "base/synchronization/lock.h"
81 #include "base/time/time.h" 82 #include "base/time/time.h"
82 83
83 namespace base { 84 namespace base {
84 85
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 #if defined(OS_WIN) 567 #if defined(OS_WIN)
567 // On Windows, we need to explicitly pass down any handles to be inherited. 568 // On Windows, we need to explicitly pass down any handles to be inherited.
568 // This function adds the shared memory handle to field trial state to the 569 // This function adds the shared memory handle to field trial state to the
569 // list of handles to be inherited. 570 // list of handles to be inherited.
570 static void AppendFieldTrialHandleIfNeeded( 571 static void AppendFieldTrialHandleIfNeeded(
571 base::HandlesToInheritVector* handles); 572 base::HandlesToInheritVector* handles);
572 #endif 573 #endif
573 574
574 #if defined(OS_POSIX) && !defined(OS_NACL) 575 #if defined(OS_POSIX) && !defined(OS_NACL)
575 // On POSIX, we also need to explicitly pass down this file descriptor that 576 // On POSIX, we also need to explicitly pass down this file descriptor that
576 // should be shared with the child process. Returns kInvalidPlatformFile if no 577 // should be shared with the child process. Returns an invalid handle if it
577 // handle exists or was not initialized properly. 578 // was not initialized properly.
578 static PlatformFile GetFieldTrialHandle(); 579 static base::SharedMemoryHandle GetFieldTrialHandle();
579 #endif 580 #endif
580 581
581 // Adds a switch to the command line containing the field trial state as a 582 // Adds a switch to the command line containing the field trial state as a
582 // string (if not using shared memory to share field trial state), or the 583 // string (if not using shared memory to share field trial state), or the
583 // shared memory handle + length. 584 // shared memory handle + length.
584 // Needs the |field_trial_handle_switch| argument to be passed in since base/ 585 // Needs the |field_trial_handle_switch| argument to be passed in since base/
585 // can't depend on content/. 586 // can't depend on content/.
586 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, 587 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch,
587 const char* enable_features_switch, 588 const char* enable_features_switch,
588 const char* disable_features_switch, 589 const char* disable_features_switch,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 PersistentMemoryAllocator const& allocator); 639 PersistentMemoryAllocator const& allocator);
639 640
640 private: 641 private:
641 // Allow tests to access our innards for testing purposes. 642 // Allow tests to access our innards for testing purposes.
642 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator); 643 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, InstantiateAllocator);
643 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator); 644 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AddTrialsToAllocator);
644 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, 645 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest,
645 DoNotAddSimulatedFieldTrialsToAllocator); 646 DoNotAddSimulatedFieldTrialsToAllocator);
646 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams); 647 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, AssociateFieldTrialParams);
647 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory); 648 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest, ClearParamsFromSharedMemory);
649 FRIEND_TEST_ALL_PREFIXES(FieldTrialListTest,
650 SerializeSharedMemoryHandleMetadata);
651
652 // Serialization and deserialization doesn't actually transport the underlying
Alexei Svitkine (slow) 2017/05/05 18:02:16 Please start this comment explaining what serializ
erikchen 2017/05/05 19:41:51 Done.
653 // OS resource - that must be done by the Process launcher.
654 static std::string SerializeSharedMemoryHandleMetadata(
655 const SharedMemoryHandle& shm);
656 #if defined(OS_WIN)
657 static SharedMemoryHandle DeserializeSharedMemoryHandleMetadata(
658 const std::string& switch_value);
659 #elif defined(OS_POSIX) && !defined(OS_NACL)
660 static SharedMemoryHandle DeserializeSharedMemoryHandleMetadata(
661 int fd,
662 const std::string& switch_value);
663 #endif
648 664
649 #if defined(OS_WIN) 665 #if defined(OS_WIN)
650 // Takes in |handle_switch| from the command line which represents the shared 666 // Takes in |handle_switch| from the command line which represents the shared
651 // memory handle for field trials, parses it, and creates the field trials. 667 // memory handle for field trials, parses it, and creates the field trials.
652 // Returns true on success, false on failure. 668 // Returns true on success, false on failure.
653 static bool CreateTrialsFromHandleSwitch(const std::string& handle_switch); 669 // |switch_value| also contains the serialized GUID.
670 static bool CreateTrialsFromSwitchValue(const std::string& switch_value);
654 #endif 671 #endif
655 672
656 #if defined(OS_POSIX) && !defined(OS_NACL) 673 #if defined(OS_POSIX) && !defined(OS_NACL)
657 // On POSIX systems that use the zygote, we look up the correct fd that backs 674 // On POSIX systems that use the zygote, we look up the correct fd that backs
658 // the shared memory segment containing the field trials by looking it up via 675 // the shared memory segment containing the field trials by looking it up via
659 // an fd key in GlobalDescriptors. Returns true on success, false on failure. 676 // an fd key in GlobalDescriptors. Returns true on success, false on failure.
660 static bool CreateTrialsFromDescriptor(int fd_key); 677 // |switch_value| also contains the serialized GUID.
678 static bool CreateTrialsFromDescriptor(int fd_key,
679 const std::string& switch_value);
661 #endif 680 #endif
662 681
663 // Takes an unmapped SharedMemoryHandle, creates a SharedMemory object from it 682 // Takes an unmapped SharedMemoryHandle, creates a SharedMemory object from it
664 // and maps it with the correct size. 683 // and maps it with the correct size.
665 static bool CreateTrialsFromSharedMemoryHandle(SharedMemoryHandle shm_handle); 684 static bool CreateTrialsFromSharedMemoryHandle(SharedMemoryHandle shm_handle);
666 685
667 // Expects a mapped piece of shared memory |shm| that was created from the 686 // Expects a mapped piece of shared memory |shm| that was created from the
668 // browser process's field_trial_allocator and shared via the command line. 687 // browser process's field_trial_allocator and shared via the command line.
669 // This function recreates the allocator, iterates through all the field 688 // This function recreates the allocator, iterates through all the field
670 // trials in it, and creates them via CreateFieldTrial(). Returns true if 689 // trials in it, and creates them via CreateFieldTrial(). Returns true if
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 743
725 // Allocator in shared memory containing field trial data. Used in both 744 // Allocator in shared memory containing field trial data. Used in both
726 // browser and child processes, but readonly in the child. 745 // browser and child processes, but readonly in the child.
727 // In the future, we may want to move this to a more generic place if we want 746 // In the future, we may want to move this to a more generic place if we want
728 // to start passing more data other than field trials. 747 // to start passing more data other than field trials.
729 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr; 748 std::unique_ptr<FieldTrialAllocator> field_trial_allocator_ = nullptr;
730 749
731 // Readonly copy of the handle to the allocator. Needs to be a member variable 750 // Readonly copy of the handle to the allocator. Needs to be a member variable
732 // because it's needed from both CopyFieldTrialStateToFlags() and 751 // because it's needed from both CopyFieldTrialStateToFlags() and
733 // AppendFieldTrialHandleIfNeeded(). 752 // AppendFieldTrialHandleIfNeeded().
734 PlatformFile readonly_allocator_handle_ = kInvalidPlatformFile; 753 base::SharedMemoryHandle readonly_allocator_handle_;
735 754
736 // Tracks whether CreateTrialsFromCommandLine() has been called. 755 // Tracks whether CreateTrialsFromCommandLine() has been called.
737 bool create_trials_from_command_line_called_ = false; 756 bool create_trials_from_command_line_called_ = false;
738 757
739 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 758 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
740 }; 759 };
741 760
742 } // namespace base 761 } // namespace base
743 762
744 #endif // BASE_METRICS_FIELD_TRIAL_H_ 763 #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