| 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 |
| 10 #include <atomic> | 10 #include <atomic> |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 static bool IsSharedMemoryAcceptable(const SharedMemory& memory); | 379 static bool IsSharedMemoryAcceptable(const SharedMemory& memory); |
| 380 | 380 |
| 381 private: | 381 private: |
| 382 std::unique_ptr<SharedMemory> shared_memory_; | 382 std::unique_ptr<SharedMemory> shared_memory_; |
| 383 | 383 |
| 384 DISALLOW_COPY_AND_ASSIGN(SharedPersistentMemoryAllocator); | 384 DISALLOW_COPY_AND_ASSIGN(SharedPersistentMemoryAllocator); |
| 385 }; | 385 }; |
| 386 | 386 |
| 387 | 387 |
| 388 // This allocator takes a memory-mapped file object and performs allocation | 388 // This allocator takes a memory-mapped file object and performs allocation |
| 389 // from it. The allocator takes ownership of the file object. Only read access | 389 // from it. The allocator takes ownership of the file object. |
| 390 // is provided due to limitions of the MemoryMappedFile class. | |
| 391 class BASE_EXPORT FilePersistentMemoryAllocator | 390 class BASE_EXPORT FilePersistentMemoryAllocator |
| 392 : public PersistentMemoryAllocator { | 391 : public PersistentMemoryAllocator { |
| 393 public: | 392 public: |
| 393 // A |max_size| of zero will use the length of the file as the maximum |
| 394 // size. The |file| object must have been already created with sufficient |
| 395 // permissions (read, read/write, or read/write/extend). |
| 394 FilePersistentMemoryAllocator(std::unique_ptr<MemoryMappedFile> file, | 396 FilePersistentMemoryAllocator(std::unique_ptr<MemoryMappedFile> file, |
| 397 size_t max_size, |
| 395 uint64_t id, | 398 uint64_t id, |
| 396 base::StringPiece name); | 399 base::StringPiece name, |
| 400 bool read_only); |
| 397 ~FilePersistentMemoryAllocator() override; | 401 ~FilePersistentMemoryAllocator() override; |
| 398 | 402 |
| 399 // Ensure that the file isn't so invalid that it won't crash when passing it | 403 // Ensure that the file isn't so invalid that it won't crash when passing it |
| 400 // to the allocator. This doesn't guarantee the file is valid, just that it | 404 // to the allocator. This doesn't guarantee the file is valid, just that it |
| 401 // won't cause the program to abort. The existing IsCorrupt() call will handle | 405 // won't cause the program to abort. The existing IsCorrupt() call will handle |
| 402 // the rest. | 406 // the rest. |
| 403 static bool IsFileAcceptable(const MemoryMappedFile& file); | 407 static bool IsFileAcceptable(const MemoryMappedFile& file, bool read_only); |
| 404 | 408 |
| 405 private: | 409 private: |
| 406 std::unique_ptr<MemoryMappedFile> mapped_file_; | 410 std::unique_ptr<MemoryMappedFile> mapped_file_; |
| 407 | 411 |
| 408 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); | 412 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
| 409 }; | 413 }; |
| 410 | 414 |
| 411 } // namespace base | 415 } // namespace base |
| 412 | 416 |
| 413 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 417 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
| OLD | NEW |