OLD | NEW |
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" |
11 #include "base/build_time.h" | 11 #include "base/build_time.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/activity_tracker.h" | 13 #include "base/debug/activity_tracker.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/field_trial_param_associator.h" | 15 #include "base/metrics/field_trial_param_associator.h" |
16 #include "base/process/memory.h" | 16 #include "base/process/memory.h" |
17 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/unguessable_token.h" |
22 | 23 |
23 // On POSIX, the fd is shared using the mapping in GlobalDescriptors. | 24 // On POSIX, the fd is shared using the mapping in GlobalDescriptors. |
24 #if defined(OS_POSIX) && !defined(OS_NACL) | 25 #if defined(OS_POSIX) && !defined(OS_NACL) |
25 #include "base/posix/global_descriptors.h" | 26 #include "base/posix/global_descriptors.h" |
26 #endif | 27 #endif |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 } | 1131 } |
1131 return entries; | 1132 return entries; |
1132 } | 1133 } |
1133 | 1134 |
1134 #if defined(OS_WIN) | 1135 #if defined(OS_WIN) |
1135 // static | 1136 // static |
1136 bool FieldTrialList::CreateTrialsFromHandleSwitch( | 1137 bool FieldTrialList::CreateTrialsFromHandleSwitch( |
1137 const std::string& handle_switch) { | 1138 const std::string& handle_switch) { |
1138 int field_trial_handle = std::stoi(handle_switch); | 1139 int field_trial_handle = std::stoi(handle_switch); |
1139 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); | 1140 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); |
1140 SharedMemoryHandle shm_handle(handle); | 1141 // TODO(erikchen): Plumb a GUID for this SharedMemoryHandle. |
| 1142 // https://crbug.com/713763. |
| 1143 SharedMemoryHandle shm_handle(handle, base::UnguessableToken::Create()); |
1141 return FieldTrialList::CreateTrialsFromSharedMemoryHandle(shm_handle); | 1144 return FieldTrialList::CreateTrialsFromSharedMemoryHandle(shm_handle); |
1142 } | 1145 } |
1143 #endif | 1146 #endif |
1144 | 1147 |
1145 #if defined(OS_POSIX) && !defined(OS_NACL) | 1148 #if defined(OS_POSIX) && !defined(OS_NACL) |
1146 // static | 1149 // static |
1147 bool FieldTrialList::CreateTrialsFromDescriptor(int fd_key) { | 1150 bool FieldTrialList::CreateTrialsFromDescriptor(int fd_key) { |
1148 if (!kUseSharedMemoryForFieldTrials) | 1151 if (!kUseSharedMemoryForFieldTrials) |
1149 return false; | 1152 return false; |
1150 | 1153 |
1151 if (fd_key == -1) | 1154 if (fd_key == -1) |
1152 return false; | 1155 return false; |
1153 | 1156 |
1154 int fd = GlobalDescriptors::GetInstance()->MaybeGet(fd_key); | 1157 int fd = GlobalDescriptors::GetInstance()->MaybeGet(fd_key); |
1155 if (fd == -1) | 1158 if (fd == -1) |
1156 return false; | 1159 return false; |
1157 | 1160 |
1158 SharedMemoryHandle shm_handle(FileDescriptor(fd, true)); | 1161 // TODO(erikchen): Plumb a GUID for this SharedMemoryHandle. |
| 1162 // https://crbug.com/713763. |
| 1163 SharedMemoryHandle shm_handle(FileDescriptor(fd, true), |
| 1164 base::UnguessableToken::Create()); |
1159 | 1165 |
1160 bool result = FieldTrialList::CreateTrialsFromSharedMemoryHandle(shm_handle); | 1166 bool result = FieldTrialList::CreateTrialsFromSharedMemoryHandle(shm_handle); |
1161 DCHECK(result); | 1167 DCHECK(result); |
1162 return true; | 1168 return true; |
1163 } | 1169 } |
1164 #endif | 1170 #endif |
1165 | 1171 |
1166 // static | 1172 // static |
1167 bool FieldTrialList::CreateTrialsFromSharedMemoryHandle( | 1173 bool FieldTrialList::CreateTrialsFromSharedMemoryHandle( |
1168 SharedMemoryHandle shm_handle) { | 1174 SharedMemoryHandle shm_handle) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 return; | 1359 return; |
1354 } | 1360 } |
1355 AutoLock auto_lock(global_->lock_); | 1361 AutoLock auto_lock(global_->lock_); |
1356 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 1362 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
1357 trial->AddRef(); | 1363 trial->AddRef(); |
1358 trial->SetTrialRegistered(); | 1364 trial->SetTrialRegistered(); |
1359 global_->registered_[trial->trial_name()] = trial; | 1365 global_->registered_[trial->trial_name()] = trial; |
1360 } | 1366 } |
1361 | 1367 |
1362 } // namespace base | 1368 } // namespace base |
OLD | NEW |