OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 5 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
9 #include <atomic> | 10 #include <atomic> |
| 11 #include <memory> |
10 | 12 |
11 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
12 #include "base/base_export.h" | 14 #include "base/base_export.h" |
13 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 16 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 class HistogramBase; | 21 class HistogramBase; |
21 class MemoryMappedFile; | 22 class MemoryMappedFile; |
22 class SharedMemory; | 23 class SharedMemory; |
23 | 24 |
24 // Simple allocator for pieces of a memory block that may be persistent | 25 // Simple allocator for pieces of a memory block that may be persistent |
25 // to some storage or shared across multiple processes. This class resides | 26 // to some storage or shared across multiple processes. This class resides |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 DISALLOW_COPY_AND_ASSIGN(LocalPersistentMemoryAllocator); | 315 DISALLOW_COPY_AND_ASSIGN(LocalPersistentMemoryAllocator); |
315 }; | 316 }; |
316 | 317 |
317 | 318 |
318 // This allocator takes a shared-memory object and performs allocation from | 319 // This allocator takes a shared-memory object and performs allocation from |
319 // it. The memory must be previously mapped via Map() or MapAt(). The allocator | 320 // it. The memory must be previously mapped via Map() or MapAt(). The allocator |
320 // takes ownership of the memory object. | 321 // takes ownership of the memory object. |
321 class BASE_EXPORT SharedPersistentMemoryAllocator | 322 class BASE_EXPORT SharedPersistentMemoryAllocator |
322 : public PersistentMemoryAllocator { | 323 : public PersistentMemoryAllocator { |
323 public: | 324 public: |
324 SharedPersistentMemoryAllocator(scoped_ptr<SharedMemory> memory, uint64_t id, | 325 SharedPersistentMemoryAllocator(std::unique_ptr<SharedMemory> memory, |
325 base::StringPiece name, bool read_only); | 326 uint64_t id, |
| 327 base::StringPiece name, |
| 328 bool read_only); |
326 ~SharedPersistentMemoryAllocator() override; | 329 ~SharedPersistentMemoryAllocator() override; |
327 | 330 |
328 SharedMemory* shared_memory() { return shared_memory_.get(); } | 331 SharedMemory* shared_memory() { return shared_memory_.get(); } |
329 | 332 |
330 // Ensure that the memory isn't so invalid that it won't crash when passing it | 333 // Ensure that the memory isn't so invalid that it won't crash when passing it |
331 // to the allocator. This doesn't guarantee the data is valid, just that it | 334 // to the allocator. This doesn't guarantee the data is valid, just that it |
332 // won't cause the program to abort. The existing IsCorrupt() call will handle | 335 // won't cause the program to abort. The existing IsCorrupt() call will handle |
333 // the rest. | 336 // the rest. |
334 static bool IsSharedMemoryAcceptable(const SharedMemory& memory); | 337 static bool IsSharedMemoryAcceptable(const SharedMemory& memory); |
335 | 338 |
336 private: | 339 private: |
337 scoped_ptr<SharedMemory> shared_memory_; | 340 std::unique_ptr<SharedMemory> shared_memory_; |
338 | 341 |
339 DISALLOW_COPY_AND_ASSIGN(SharedPersistentMemoryAllocator); | 342 DISALLOW_COPY_AND_ASSIGN(SharedPersistentMemoryAllocator); |
340 }; | 343 }; |
341 | 344 |
342 | 345 |
343 // This allocator takes a memory-mapped file object and performs allocation | 346 // This allocator takes a memory-mapped file object and performs allocation |
344 // from it. The allocator takes ownership of the file object. Only read access | 347 // from it. The allocator takes ownership of the file object. Only read access |
345 // is provided due to limitions of the MemoryMappedFile class. | 348 // is provided due to limitions of the MemoryMappedFile class. |
346 class BASE_EXPORT FilePersistentMemoryAllocator | 349 class BASE_EXPORT FilePersistentMemoryAllocator |
347 : public PersistentMemoryAllocator { | 350 : public PersistentMemoryAllocator { |
348 public: | 351 public: |
349 FilePersistentMemoryAllocator(scoped_ptr<MemoryMappedFile> file, uint64_t id, | 352 FilePersistentMemoryAllocator(std::unique_ptr<MemoryMappedFile> file, |
| 353 uint64_t id, |
350 base::StringPiece name); | 354 base::StringPiece name); |
351 ~FilePersistentMemoryAllocator() override; | 355 ~FilePersistentMemoryAllocator() override; |
352 | 356 |
353 // Ensure that the file isn't so invalid that it won't crash when passing it | 357 // Ensure that the file isn't so invalid that it won't crash when passing it |
354 // to the allocator. This doesn't guarantee the file is valid, just that it | 358 // to the allocator. This doesn't guarantee the file is valid, just that it |
355 // won't cause the program to abort. The existing IsCorrupt() call will handle | 359 // won't cause the program to abort. The existing IsCorrupt() call will handle |
356 // the rest. | 360 // the rest. |
357 static bool IsFileAcceptable(const MemoryMappedFile& file); | 361 static bool IsFileAcceptable(const MemoryMappedFile& file); |
358 | 362 |
359 private: | 363 private: |
360 scoped_ptr<MemoryMappedFile> mapped_file_; | 364 std::unique_ptr<MemoryMappedFile> mapped_file_; |
361 | 365 |
362 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); | 366 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
363 }; | 367 }; |
364 | 368 |
365 } // namespace base | 369 } // namespace base |
366 | 370 |
367 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 371 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
OLD | NEW |