| 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 "components/metrics/file_metrics_provider.h" | 5 #include "components/metrics/file_metrics_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // Ensure any problems below don't occur repeatedly. | 328 // Ensure any problems below don't occur repeatedly. |
| 329 source->last_seen = info.last_modified; | 329 source->last_seen = info.last_modified; |
| 330 | 330 |
| 331 // Test the validity of the file contents. | 331 // Test the validity of the file contents. |
| 332 const bool read_only = kSourceOptions[source->type].is_read_only; | 332 const bool read_only = kSourceOptions[source->type].is_read_only; |
| 333 if (!base::FilePersistentMemoryAllocator::IsFileAcceptable(*mapped, | 333 if (!base::FilePersistentMemoryAllocator::IsFileAcceptable(*mapped, |
| 334 read_only)) { | 334 read_only)) { |
| 335 return ACCESS_RESULT_INVALID_CONTENTS; | 335 return ACCESS_RESULT_INVALID_CONTENTS; |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Map the file and validate it. |
| 339 std::unique_ptr<base::PersistentMemoryAllocator> memory_allocator = |
| 340 base::MakeUnique<base::FilePersistentMemoryAllocator>( |
| 341 std::move(mapped), 0, 0, base::StringPiece(), read_only); |
| 342 if (memory_allocator->GetMemoryState() == |
| 343 base::PersistentMemoryAllocator::MEMORY_DELETED) { |
| 344 return ACCESS_RESULT_MEMORY_DELETED; |
| 345 } |
| 346 |
| 338 // Create an allocator for the mapped file. Ownership passes to the allocator. | 347 // Create an allocator for the mapped file. Ownership passes to the allocator. |
| 339 source->allocator.reset(new base::PersistentHistogramAllocator( | 348 source->allocator = base::MakeUnique<base::PersistentHistogramAllocator>( |
| 340 base::MakeUnique<base::FilePersistentMemoryAllocator>( | 349 std::move(memory_allocator)); |
| 341 std::move(mapped), 0, 0, base::StringPiece(), read_only))); | |
| 342 | 350 |
| 343 return ACCESS_RESULT_SUCCESS; | 351 return ACCESS_RESULT_SUCCESS; |
| 344 } | 352 } |
| 345 | 353 |
| 346 // static | 354 // static |
| 347 void FileMetricsProvider::MergeHistogramDeltasFromSource(SourceInfo* source) { | 355 void FileMetricsProvider::MergeHistogramDeltasFromSource(SourceInfo* source) { |
| 348 DCHECK(source->allocator); | 356 DCHECK(source->allocator); |
| 349 base::PersistentHistogramAllocator::Iterator histogram_iter( | 357 base::PersistentHistogramAllocator::Iterator histogram_iter( |
| 350 source->allocator.get()); | 358 source->allocator.get()); |
| 351 | 359 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // important to know how much total "jank" may be introduced. | 568 // important to know how much total "jank" may be introduced. |
| 561 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); | 569 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); |
| 562 | 570 |
| 563 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { | 571 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { |
| 564 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); | 572 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); |
| 565 MergeHistogramDeltasFromSource(source.get()); | 573 MergeHistogramDeltasFromSource(source.get()); |
| 566 } | 574 } |
| 567 } | 575 } |
| 568 | 576 |
| 569 } // namespace metrics | 577 } // namespace metrics |
| OLD | NEW |