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

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

Issue 2484773002: Store ref in field trial in child processes (Closed)
Patch Set: add comments 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 unified diff | Download patch
« no previous file with comments | « base/metrics/field_trial.h ('k') | no next file » | no next file with comments »
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 #include "base/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 size_t FieldTrialList::GetFieldTrialCount() { 816 size_t FieldTrialList::GetFieldTrialCount() {
817 if (!global_) 817 if (!global_)
818 return 0; 818 return 0;
819 AutoLock auto_lock(global_->lock_); 819 AutoLock auto_lock(global_->lock_);
820 return global_->registered_.size(); 820 return global_->registered_.size();
821 } 821 }
822 822
823 // static 823 // static
824 void FieldTrialList::CreateTrialsFromSharedMemory( 824 void FieldTrialList::CreateTrialsFromSharedMemory(
825 std::unique_ptr<SharedMemory> shm) { 825 std::unique_ptr<SharedMemory> shm) {
826 const SharedPersistentMemoryAllocator shalloc(std::move(shm), 0, 826 global_->field_trial_allocator_.reset(new SharedPersistentMemoryAllocator(
827 kAllocatorName, true); 827 std::move(shm), 0, kAllocatorName, true));
828 PersistentMemoryAllocator::Iterator mem_iter(&shalloc); 828 SharedPersistentMemoryAllocator* shalloc =
829 global_->field_trial_allocator_.get();
830 PersistentMemoryAllocator::Iterator mem_iter(shalloc);
829 831
830 SharedPersistentMemoryAllocator::Reference ref; 832 SharedPersistentMemoryAllocator::Reference ref;
831 while ((ref = mem_iter.GetNextOfType(kFieldTrialType)) != 833 while ((ref = mem_iter.GetNextOfType(kFieldTrialType)) !=
832 SharedPersistentMemoryAllocator::kReferenceNull) { 834 SharedPersistentMemoryAllocator::kReferenceNull) {
833 const FieldTrialEntry* entry = 835 const FieldTrialEntry* entry =
834 shalloc.GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType); 836 shalloc->GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType);
835 837
836 StringPiece trial_name; 838 StringPiece trial_name;
837 StringPiece group_name; 839 StringPiece group_name;
838 if (!entry->GetTrialAndGroupName(&trial_name, &group_name)) { 840 if (!entry->GetTrialAndGroupName(&trial_name, &group_name)) {
839 NOTREACHED(); 841 NOTREACHED();
840 continue; 842 continue;
841 } 843 }
842 844
843 // TODO(lawrencewu): Convert the API for CreateFieldTrial to take 845 // TODO(lawrencewu): Convert the API for CreateFieldTrial to take
844 // StringPieces. 846 // StringPieces.
845 FieldTrial* trial = 847 FieldTrial* trial =
846 CreateFieldTrial(trial_name.as_string(), group_name.as_string()); 848 CreateFieldTrial(trial_name.as_string(), group_name.as_string());
847 849
850 trial->ref_ = ref;
848 if (entry->activated) { 851 if (entry->activated) {
849 // Call |group()| to mark the trial as "used" and notify observers, if 852 // Call |group()| to mark the trial as "used" and notify observers, if
850 // any. This is useful to ensure that field trials created in child 853 // any. This is useful to ensure that field trials created in child
851 // processes are properly reported in crash reports. 854 // processes are properly reported in crash reports.
852 trial->group(); 855 trial->group();
853 } 856 }
854 } 857 }
855 } 858 }
856 859
857 #if !defined(OS_NACL) 860 #if !defined(OS_NACL)
(...skipping 30 matching lines...) Expand all
888 891
889 // static 892 // static
890 void FieldTrialList::AddToAllocatorWhileLocked(FieldTrial* field_trial) { 893 void FieldTrialList::AddToAllocatorWhileLocked(FieldTrial* field_trial) {
891 SharedPersistentMemoryAllocator* allocator = 894 SharedPersistentMemoryAllocator* allocator =
892 global_->field_trial_allocator_.get(); 895 global_->field_trial_allocator_.get();
893 896
894 // Don't do anything if the allocator hasn't been instantiated yet. 897 // Don't do anything if the allocator hasn't been instantiated yet.
895 if (allocator == nullptr) 898 if (allocator == nullptr)
896 return; 899 return;
897 900
901 // Or if the allocator is read only, which means we are in a child process and
902 // shouldn't be writing to it.
903 if (allocator->IsReadonly())
904 return;
905
898 // Or if we've already added it. 906 // Or if we've already added it.
899 if (field_trial->ref_ != SharedPersistentMemoryAllocator::kReferenceNull) 907 if (field_trial->ref_ != SharedPersistentMemoryAllocator::kReferenceNull)
900 return; 908 return;
901 909
902 FieldTrial::State trial_state; 910 FieldTrial::State trial_state;
903 if (!field_trial->GetState(&trial_state)) 911 if (!field_trial->GetState(&trial_state))
904 return; 912 return;
905 913
906 Pickle pickle; 914 Pickle pickle;
907 pickle.WriteString(trial_state.trial_name); 915 pickle.WriteString(trial_state.trial_name);
(...skipping 17 matching lines...) Expand all
925 933
926 allocator->MakeIterable(ref); 934 allocator->MakeIterable(ref);
927 field_trial->ref_ = ref; 935 field_trial->ref_ = ref;
928 } 936 }
929 937
930 // static 938 // static
931 void FieldTrialList::ActivateFieldTrialEntryWhileLocked( 939 void FieldTrialList::ActivateFieldTrialEntryWhileLocked(
932 FieldTrial* field_trial) { 940 FieldTrial* field_trial) {
933 SharedPersistentMemoryAllocator* allocator = 941 SharedPersistentMemoryAllocator* allocator =
934 global_->field_trial_allocator_.get(); 942 global_->field_trial_allocator_.get();
943
944 // Check if we're in the child process and return early if so.
945 if (allocator && allocator->IsReadonly())
946 return;
947
935 SharedPersistentMemoryAllocator::Reference ref = field_trial->ref_; 948 SharedPersistentMemoryAllocator::Reference ref = field_trial->ref_;
936 if (ref == SharedPersistentMemoryAllocator::kReferenceNull) { 949 if (ref == SharedPersistentMemoryAllocator::kReferenceNull) {
937 // It's fine to do this even if the allocator hasn't been instantiated 950 // It's fine to do this even if the allocator hasn't been instantiated
938 // yet -- it'll just return early. 951 // yet -- it'll just return early.
939 AddToAllocatorWhileLocked(field_trial); 952 AddToAllocatorWhileLocked(field_trial);
940 } else { 953 } else {
941 // It's also okay to do this even though the callee doesn't have a lock -- 954 // It's also okay to do this even though the callee doesn't have a lock --
942 // the only thing that happens on a stale read here is a slight performance 955 // the only thing that happens on a stale read here is a slight performance
943 // hit from the child re-synchronizing activation state. 956 // hit from the child re-synchronizing activation state.
944 FieldTrialEntry* entry = 957 FieldTrialEntry* entry =
(...skipping 27 matching lines...) Expand all
972 return; 985 return;
973 } 986 }
974 AutoLock auto_lock(global_->lock_); 987 AutoLock auto_lock(global_->lock_);
975 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); 988 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name();
976 trial->AddRef(); 989 trial->AddRef();
977 trial->SetTrialRegistered(); 990 trial->SetTrialRegistered();
978 global_->registered_[trial->trial_name()] = trial; 991 global_->registered_[trial->trial_name()] = trial;
979 } 992 }
980 993
981 } // namespace base 994 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698