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 <functional> | 7 #include <functional> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 SystemProfileProto profile; | 590 SystemProfileProto profile; |
591 EXPECT_TRUE(ProvideIndependentMetrics(&profile, &snapshot_manager)); | 591 EXPECT_TRUE(ProvideIndependentMetrics(&profile, &snapshot_manager)); |
592 EXPECT_FALSE(ProvideIndependentMetrics(&profile, &snapshot_manager)); | 592 EXPECT_FALSE(ProvideIndependentMetrics(&profile, &snapshot_manager)); |
593 } | 593 } |
594 EXPECT_TRUE(base::PathExists(metrics_file())); | 594 EXPECT_TRUE(base::PathExists(metrics_file())); |
595 OnDidCreateMetricsLog(); | 595 OnDidCreateMetricsLog(); |
596 RunTasks(); | 596 RunTasks(); |
597 EXPECT_FALSE(base::PathExists(metrics_file())); | 597 EXPECT_FALSE(base::PathExists(metrics_file())); |
598 } | 598 } |
599 | 599 |
| 600 TEST_P(FileMetricsProviderTest, AccessEmbeddedProfileMetricsFromDir) { |
| 601 const int file_count = 3; |
| 602 base::Time file_base_time = base::Time::Now(); |
| 603 std::vector<base::FilePath> file_names; |
| 604 for (int i = 0; i < file_count; ++i) { |
| 605 CreateMetricsFileWithHistograms( |
| 606 2, [](base::PersistentHistogramAllocator* allocator) { |
| 607 SystemProfileProto profile_proto; |
| 608 SystemProfileProto::FieldTrial* trial = |
| 609 profile_proto.add_field_trial(); |
| 610 trial->set_name_id(123); |
| 611 trial->set_group_id(456); |
| 612 |
| 613 PersistentSystemProfile persistent_profile; |
| 614 persistent_profile.RegisterPersistentAllocator( |
| 615 allocator->memory_allocator()); |
| 616 persistent_profile.SetSystemProfile(profile_proto, true); |
| 617 }); |
| 618 ASSERT_TRUE(PathExists(metrics_file())); |
| 619 char new_name[] = "hX"; |
| 620 new_name[1] = '1' + i; |
| 621 base::FilePath file_name = temp_dir().AppendASCII(new_name).AddExtension( |
| 622 base::PersistentMemoryAllocator::kFileExtension); |
| 623 base::Time file_time = |
| 624 file_base_time - base::TimeDelta::FromMinutes(file_count - i); |
| 625 base::TouchFile(metrics_file(), file_time, file_time); |
| 626 base::Move(metrics_file(), file_name); |
| 627 file_names.push_back(std::move(file_name)); |
| 628 } |
| 629 |
| 630 // Register the file and allow the "checker" task to run. |
| 631 provider()->RegisterSource( |
| 632 temp_dir(), FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, |
| 633 FileMetricsProvider::ASSOCIATE_INTERNAL_PROFILE, ""); |
| 634 |
| 635 OnDidCreateMetricsLog(); |
| 636 RunTasks(); |
| 637 |
| 638 // A read of metrics with internal profiles should return one result. |
| 639 HistogramFlattenerDeltaRecorder flattener; |
| 640 base::HistogramSnapshotManager snapshot_manager(&flattener); |
| 641 SystemProfileProto profile; |
| 642 for (int i = 0; i < file_count; ++i) { |
| 643 EXPECT_TRUE(ProvideIndependentMetrics(&profile, &snapshot_manager)) << i; |
| 644 RunTasks(); |
| 645 } |
| 646 EXPECT_FALSE(ProvideIndependentMetrics(&profile, &snapshot_manager)); |
| 647 |
| 648 OnDidCreateMetricsLog(); |
| 649 RunTasks(); |
| 650 for (const auto& file_name : file_names) |
| 651 EXPECT_FALSE(base::PathExists(file_name)); |
| 652 } |
| 653 |
600 } // namespace metrics | 654 } // namespace metrics |
OLD | NEW |