| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 StringPiece name) { | 792 StringPiece name) { |
| 793 if ((!memory->memory() && !memory->Map(size)) || | 793 if ((!memory->memory() && !memory->Map(size)) || |
| 794 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*memory)) { | 794 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*memory)) { |
| 795 NOTREACHED(); | 795 NOTREACHED(); |
| 796 return; | 796 return; |
| 797 } | 797 } |
| 798 | 798 |
| 799 DCHECK_LE(memory->mapped_size(), size); | 799 DCHECK_LE(memory->mapped_size(), size); |
| 800 Set(WrapUnique( | 800 Set(WrapUnique( |
| 801 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( | 801 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( |
| 802 std::move(memory), 0, StringPiece(), /*readonly=*/false)))); | 802 std::move(memory), id, name, /*readonly=*/false)))); |
| 803 } | 803 } |
| 804 | 804 |
| 805 // static | 805 // static |
| 806 void GlobalHistogramAllocator::CreateWithSharedMemoryHandle( | 806 void GlobalHistogramAllocator::CreateWithSharedMemoryHandle( |
| 807 const SharedMemoryHandle& handle, | 807 const SharedMemoryHandle& handle, |
| 808 size_t size) { | 808 size_t size) { |
| 809 std::unique_ptr<SharedMemory> shm( | 809 std::unique_ptr<SharedMemory> shm( |
| 810 new SharedMemory(handle, /*readonly=*/false)); | 810 new SharedMemory(handle, /*readonly=*/false)); |
| 811 if (!shm->Map(size) || | 811 CreateWithSharedMemory(std::move(shm), size, 0, StringPiece()); |
| 812 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*shm)) { | |
| 813 NOTREACHED(); | |
| 814 return; | |
| 815 } | |
| 816 | |
| 817 Set(WrapUnique( | |
| 818 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( | |
| 819 std::move(shm), 0, StringPiece(), /*readonly=*/false)))); | |
| 820 } | 812 } |
| 821 | 813 |
| 822 // static | 814 // static |
| 823 void GlobalHistogramAllocator::Set( | 815 void GlobalHistogramAllocator::Set( |
| 824 std::unique_ptr<GlobalHistogramAllocator> allocator) { | 816 std::unique_ptr<GlobalHistogramAllocator> allocator) { |
| 825 // Releasing or changing an allocator is extremely dangerous because it | 817 // Releasing or changing an allocator is extremely dangerous because it |
| 826 // likely has histograms stored within it. If the backing memory is also | 818 // likely has histograms stored within it. If the backing memory is also |
| 827 // also released, future accesses to those histograms will seg-fault. | 819 // also released, future accesses to those histograms will seg-fault. |
| 828 CHECK(!subtle::NoBarrier_Load(&g_allocator)); | 820 CHECK(!subtle::NoBarrier_Load(&g_allocator)); |
| 829 subtle::Release_Store(&g_allocator, | 821 subtle::Release_Store(&g_allocator, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 while (true) { | 938 while (true) { |
| 947 std::unique_ptr<HistogramBase> histogram = | 939 std::unique_ptr<HistogramBase> histogram = |
| 948 import_iterator_.GetNextWithIgnore(record_to_ignore); | 940 import_iterator_.GetNextWithIgnore(record_to_ignore); |
| 949 if (!histogram) | 941 if (!histogram) |
| 950 break; | 942 break; |
| 951 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 943 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
| 952 } | 944 } |
| 953 } | 945 } |
| 954 | 946 |
| 955 } // namespace base | 947 } // namespace base |
| OLD | NEW |