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" |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 #if defined(OS_WIN) | 1120 #if defined(OS_WIN) |
1121 // Tell the child process the name of the inherited HANDLE. | 1121 // Tell the child process the name of the inherited HANDLE. |
1122 uintptr_t uintptr_handle = reinterpret_cast<uintptr_t>(shm.GetHandle()); | 1122 uintptr_t uintptr_handle = reinterpret_cast<uintptr_t>(shm.GetHandle()); |
1123 ss << uintptr_handle << ","; | 1123 ss << uintptr_handle << ","; |
1124 #elif !defined(OS_POSIX) | 1124 #elif !defined(OS_POSIX) |
1125 #error Unsupported OS | 1125 #error Unsupported OS |
1126 #endif | 1126 #endif |
1127 | 1127 |
1128 base::UnguessableToken guid = shm.GetGUID(); | 1128 base::UnguessableToken guid = shm.GetGUID(); |
1129 ss << guid.GetHighForSerialization() << "," << guid.GetLowForSerialization(); | 1129 ss << guid.GetHighForSerialization() << "," << guid.GetLowForSerialization(); |
| 1130 ss << "," << shm.GetSize(); |
1130 return ss.str(); | 1131 return ss.str(); |
1131 } | 1132 } |
1132 | 1133 |
1133 #if defined(OS_WIN) | 1134 #if defined(OS_WIN) |
1134 // static | 1135 // static |
1135 SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata( | 1136 SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata( |
1136 const std::string& switch_value) { | 1137 const std::string& switch_value) { |
1137 std::vector<base::StringPiece> tokens = base::SplitStringPiece( | 1138 std::vector<base::StringPiece> tokens = base::SplitStringPiece( |
1138 switch_value, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 1139 switch_value, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
1139 | 1140 |
1140 if (tokens.size() != 3) | 1141 if (tokens.size() != 4) |
1141 return SharedMemoryHandle(); | 1142 return SharedMemoryHandle(); |
1142 | 1143 |
1143 int field_trial_handle = 0; | 1144 int field_trial_handle = 0; |
1144 if (!base::StringToInt(tokens[0], &field_trial_handle)) | 1145 if (!base::StringToInt(tokens[0], &field_trial_handle)) |
1145 return SharedMemoryHandle(); | 1146 return SharedMemoryHandle(); |
1146 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); | 1147 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); |
1147 | 1148 |
1148 base::UnguessableToken guid; | 1149 base::UnguessableToken guid; |
1149 if (!DeserializeGUIDFromStringPieces(tokens[1], tokens[2], &guid)) | 1150 if (!DeserializeGUIDFromStringPieces(tokens[1], tokens[2], &guid)) |
1150 return SharedMemoryHandle(); | 1151 return SharedMemoryHandle(); |
1151 | 1152 |
1152 return SharedMemoryHandle(handle, guid); | 1153 int size; |
| 1154 if (!base::StringToInt(tokens[3], &size)) |
| 1155 return SharedMemoryHandle(); |
| 1156 |
| 1157 return SharedMemoryHandle(handle, static_cast<size_t>(size), guid); |
1153 } | 1158 } |
1154 #endif // defined(OS_WIN) | 1159 #endif // defined(OS_WIN) |
1155 | 1160 |
1156 #if defined(OS_POSIX) && !defined(OS_NACL) | 1161 #if defined(OS_POSIX) && !defined(OS_NACL) |
1157 // static | 1162 // static |
1158 SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata( | 1163 SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata( |
1159 int fd, | 1164 int fd, |
1160 const std::string& switch_value) { | 1165 const std::string& switch_value) { |
1161 std::vector<base::StringPiece> tokens = base::SplitStringPiece( | 1166 std::vector<base::StringPiece> tokens = base::SplitStringPiece( |
1162 switch_value, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 1167 switch_value, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
1163 | 1168 |
1164 if (tokens.size() != 2) | 1169 if (tokens.size() != 3) |
1165 return SharedMemoryHandle(); | 1170 return SharedMemoryHandle(); |
1166 | 1171 |
1167 base::UnguessableToken guid; | 1172 base::UnguessableToken guid; |
1168 if (!DeserializeGUIDFromStringPieces(tokens[0], tokens[1], &guid)) | 1173 if (!DeserializeGUIDFromStringPieces(tokens[0], tokens[1], &guid)) |
1169 return SharedMemoryHandle(); | 1174 return SharedMemoryHandle(); |
1170 | 1175 |
1171 return SharedMemoryHandle(FileDescriptor(fd, true), guid); | 1176 int size; |
| 1177 if (!base::StringToInt(tokens[2], &size)) |
| 1178 return SharedMemoryHandle(); |
| 1179 |
| 1180 return SharedMemoryHandle(FileDescriptor(fd, true), static_cast<size_t>(size), |
| 1181 guid); |
1172 } | 1182 } |
1173 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 1183 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
1174 | 1184 |
1175 #if defined(OS_WIN) | 1185 #if defined(OS_WIN) |
1176 // static | 1186 // static |
1177 bool FieldTrialList::CreateTrialsFromSwitchValue( | 1187 bool FieldTrialList::CreateTrialsFromSwitchValue( |
1178 const std::string& switch_value) { | 1188 const std::string& switch_value) { |
1179 SharedMemoryHandle shm = DeserializeSharedMemoryHandleMetadata(switch_value); | 1189 SharedMemoryHandle shm = DeserializeSharedMemoryHandleMetadata(switch_value); |
1180 if (!shm.IsValid()) | 1190 if (!shm.IsValid()) |
1181 return false; | 1191 return false; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 return; | 1423 return; |
1414 } | 1424 } |
1415 AutoLock auto_lock(global_->lock_); | 1425 AutoLock auto_lock(global_->lock_); |
1416 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 1426 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
1417 trial->AddRef(); | 1427 trial->AddRef(); |
1418 trial->SetTrialRegistered(); | 1428 trial->SetTrialRegistered(); |
1419 global_->registered_[trial->trial_name()] = trial; | 1429 global_->registered_[trial->trial_name()] = trial; |
1420 } | 1430 } |
1421 | 1431 |
1422 } // namespace base | 1432 } // namespace base |
OLD | NEW |