| 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/debug/crash_logging.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/metrics/field_trial_param_associator.h" | 16 #include "base/metrics/field_trial_param_associator.h" |
| 16 #include "base/process/memory.h" | 17 #include "base/process/memory.h" |
| 17 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/unguessable_token.h" | 23 #include "base/unguessable_token.h" |
| 23 | 24 |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 return; | 1224 return; |
| 1224 | 1225 |
| 1225 SharedMemoryCreateOptions options; | 1226 SharedMemoryCreateOptions options; |
| 1226 options.size = kFieldTrialAllocationSize; | 1227 options.size = kFieldTrialAllocationSize; |
| 1227 options.share_read_only = true; | 1228 options.share_read_only = true; |
| 1228 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1229 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 1229 options.type = SharedMemoryHandle::POSIX; | 1230 options.type = SharedMemoryHandle::POSIX; |
| 1230 #endif | 1231 #endif |
| 1231 | 1232 |
| 1232 std::unique_ptr<SharedMemory> shm(new SharedMemory()); | 1233 std::unique_ptr<SharedMemory> shm(new SharedMemory()); |
| 1233 if (!shm->Create(options)) | 1234 if (!shm->Create(options)) { |
| 1235 #if !defined(OS_NACL) |
| 1236 // Temporary for http://crbug.com/703649. |
| 1237 base::debug::ScopedCrashKey crash_key( |
| 1238 "field_trial_shmem_create_error", |
| 1239 base::IntToString(static_cast<int>(shm->get_last_error()))); |
| 1240 #endif |
| 1234 OnOutOfMemory(kFieldTrialAllocationSize); | 1241 OnOutOfMemory(kFieldTrialAllocationSize); |
| 1242 } |
| 1235 | 1243 |
| 1236 if (!shm->Map(kFieldTrialAllocationSize)) | 1244 if (!shm->Map(kFieldTrialAllocationSize)) { |
| 1245 #if !defined(OS_NACL) |
| 1246 // Temporary for http://crbug.com/703649. |
| 1247 base::debug::ScopedCrashKey crash_key( |
| 1248 "field_trial_shmem_map_error", |
| 1249 base::IntToString(static_cast<int>(shm->get_last_error()))); |
| 1250 #endif |
| 1237 OnOutOfMemory(kFieldTrialAllocationSize); | 1251 OnOutOfMemory(kFieldTrialAllocationSize); |
| 1252 } |
| 1238 | 1253 |
| 1239 global_->field_trial_allocator_.reset( | 1254 global_->field_trial_allocator_.reset( |
| 1240 new FieldTrialAllocator(std::move(shm), 0, kAllocatorName, false)); | 1255 new FieldTrialAllocator(std::move(shm), 0, kAllocatorName, false)); |
| 1241 global_->field_trial_allocator_->CreateTrackingHistograms(kAllocatorName); | 1256 global_->field_trial_allocator_->CreateTrackingHistograms(kAllocatorName); |
| 1242 | 1257 |
| 1243 // Add all existing field trials. | 1258 // Add all existing field trials. |
| 1244 for (const auto& registered : global_->registered_) { | 1259 for (const auto& registered : global_->registered_) { |
| 1245 AddToAllocatorWhileLocked(global_->field_trial_allocator_.get(), | 1260 AddToAllocatorWhileLocked(global_->field_trial_allocator_.get(), |
| 1246 registered.second); | 1261 registered.second); |
| 1247 } | 1262 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 return; | 1374 return; |
| 1360 } | 1375 } |
| 1361 AutoLock auto_lock(global_->lock_); | 1376 AutoLock auto_lock(global_->lock_); |
| 1362 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 1377 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
| 1363 trial->AddRef(); | 1378 trial->AddRef(); |
| 1364 trial->SetTrialRegistered(); | 1379 trial->SetTrialRegistered(); |
| 1365 global_->registered_[trial->trial_name()] = trial; | 1380 global_->registered_[trial->trial_name()] = trial; |
| 1366 } | 1381 } |
| 1367 | 1382 |
| 1368 } // namespace base | 1383 } // namespace base |
| OLD | NEW |