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 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 5 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 // exist, the allocator will use and add to its contents, ignoring the passed | 397 // exist, the allocator will use and add to its contents, ignoring the passed |
398 // size in favor of the existing size. Returns whether the global allocator | 398 // size in favor of the existing size. Returns whether the global allocator |
399 // was set. | 399 // was set. |
400 static bool CreateWithFile(const FilePath& file_path, | 400 static bool CreateWithFile(const FilePath& file_path, |
401 size_t size, | 401 size_t size, |
402 uint64_t id, | 402 uint64_t id, |
403 StringPiece name); | 403 StringPiece name); |
404 | 404 |
405 // Creates a new file at |active_path|. If it already exists, it will first be | 405 // Creates a new file at |active_path|. If it already exists, it will first be |
406 // moved to |base_path|. In all cases, any old file at |base_path| will be | 406 // moved to |base_path|. In all cases, any old file at |base_path| will be |
407 // removed. The file will be created using the given size, id, and name. | 407 // removed. If |spare_path| is non-empty and exists, that will be renamed and |
408 // Returns whether the global allocator was set. | 408 // used as the active file. Otherwise, the file will be created using the |
409 // given size, id, and name. Returns whether the global allocator was set. | |
409 static bool CreateWithActiveFile(const FilePath& base_path, | 410 static bool CreateWithActiveFile(const FilePath& base_path, |
410 const FilePath& active_path, | 411 const FilePath& active_path, |
412 const FilePath& spare_path, | |
411 size_t size, | 413 size_t size, |
412 uint64_t id, | 414 uint64_t id, |
413 StringPiece name); | 415 StringPiece name); |
414 | 416 |
415 // Uses ConstructBaseActivePairFilePaths() to build a pair of file names which | 417 // Uses ConstructBaseActivePairFilePaths() to build a pair of file names which |
416 // are then used for CreateWithActiveFile(). |name| is used for both the | 418 // are then used for CreateWithActiveFile(). |name| is used for both the |
417 // internal name for the allocator and also for the name of the file inside | 419 // internal name for the allocator and also for the name of the file inside |
418 // |dir|. | 420 // |dir|. |
419 static bool CreateWithActiveFileInDir(const FilePath& dir, | 421 static bool CreateWithActiveFileInDir(const FilePath& dir, |
420 size_t size, | 422 size_t size, |
421 uint64_t id, | 423 uint64_t id, |
422 StringPiece name); | 424 StringPiece name); |
423 | 425 |
424 // Constructs a pair of names in |dir| based on name that can be used for a | 426 // Constructs a set of names in |dir| based on name that can be used for a |
425 // base + active persistent memory mapped location for CreateWithActiveFile(). | 427 // base + active persistent memory mapped location for CreateWithActiveFile(). |
426 // |name| will be used as the basename of the file inside |dir|. | 428 // The spare path is a file that can be pre-created and moved to be active |
427 // |out_base_path| or |out_active_path| may be null if not needed. | 429 // without any startup penalty that comes from constructing the file. |name| |
430 // will be used as the basename of the file inside |dir|. |out_base_path|, | |
431 // |out_active_path|, or |out_spare_path| may be null if not needed. | |
428 static void ConstructFilePaths(const FilePath& dir, | 432 static void ConstructFilePaths(const FilePath& dir, |
429 StringPiece name, | 433 StringPiece name, |
430 FilePath* out_base_path, | 434 FilePath* out_base_path, |
431 FilePath* out_active_path); | 435 FilePath* out_active_path, |
436 FilePath* out_spare_path); | |
437 | |
438 // Create a "spare" file that can later be made the "active" file. This | |
439 // should be done on a background thread if possible. | |
440 static bool CreateSpareFile(const FilePath& spare_path, size_t size); | |
441 | |
442 // Same as above but uses standard names. | |
443 static bool CreateSpareFileInDir(const FilePath& dir_path, | |
444 size_t size, | |
445 StringPiece name); | |
Alexei Svitkine (slow)
2017/05/23 17:27:58
Nit: name -> file_name if this is the intention of
bcwhite
2017/05/24 17:01:49
It's the name of the allocator as with all the oth
| |
432 #endif | 446 #endif |
433 | 447 |
434 // Create a global allocator using a block of shared memory accessed | 448 // Create a global allocator using a block of shared memory accessed |
435 // through the given |handle| and |size|. The allocator takes ownership | 449 // through the given |handle| and |size|. The allocator takes ownership |
436 // of the handle and closes it upon destruction, though the memory will | 450 // of the handle and closes it upon destruction, though the memory will |
437 // continue to live if other processes have access to it. | 451 // continue to live if other processes have access to it. |
438 static void CreateWithSharedMemoryHandle(const SharedMemoryHandle& handle, | 452 static void CreateWithSharedMemoryHandle(const SharedMemoryHandle& handle, |
439 size_t size); | 453 size_t size); |
440 | 454 |
441 // Sets a GlobalHistogramAllocator for globally storing histograms in | 455 // Sets a GlobalHistogramAllocator for globally storing histograms in |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 | 509 |
496 // The location to which the data should be persisted. | 510 // The location to which the data should be persisted. |
497 FilePath persistent_location_; | 511 FilePath persistent_location_; |
498 | 512 |
499 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); | 513 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); |
500 }; | 514 }; |
501 | 515 |
502 } // namespace base | 516 } // namespace base |
503 | 517 |
504 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 518 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
OLD | NEW |