| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "components/offline_pages/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (client_id.name_space.empty()) { | 84 if (client_id.name_space.empty()) { |
| 85 NOTREACHED(); | 85 NOTREACHED(); |
| 86 return histogram_name; | 86 return histogram_name; |
| 87 } | 87 } |
| 88 std::string adjusted_histogram_name(histogram_name); | 88 std::string adjusted_histogram_name(histogram_name); |
| 89 adjusted_histogram_name += "."; | 89 adjusted_histogram_name += "."; |
| 90 adjusted_histogram_name += client_id.name_space; | 90 adjusted_histogram_name += client_id.name_space; |
| 91 return adjusted_histogram_name; | 91 return adjusted_histogram_name; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ReportStorageHistogramsAfterSave( |
| 95 const ArchiveManager::StorageStats& storage_stats) { |
| 96 const int kMB = 1024 * 1024; |
| 97 int free_disk_space_mb = |
| 98 static_cast<int>(storage_stats.free_disk_space / kMB); |
| 99 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.SavePage.FreeSpaceMB", |
| 100 free_disk_space_mb, 1, 500000, 50); |
| 101 |
| 102 int total_page_size_mb = |
| 103 static_cast<int>(storage_stats.total_archives_size / kMB); |
| 104 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); |
| 105 } |
| 106 |
| 107 void ReportStorageHistogramsAfterDelete( |
| 108 const ArchiveManager::StorageStats& storage_stats) { |
| 109 const int kMB = 1024 * 1024; |
| 110 int free_disk_space_mb = |
| 111 static_cast<int>(storage_stats.free_disk_space / kMB); |
| 112 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DeletePage.FreeSpaceMB", |
| 113 free_disk_space_mb, 1, 500000, 50); |
| 114 |
| 115 int total_page_size_mb = |
| 116 static_cast<int>(storage_stats.total_archives_size / kMB); |
| 117 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); |
| 118 |
| 119 if (storage_stats.free_disk_space > 0) { |
| 120 int percentage_of_free = static_cast<int>( |
| 121 1.0 * storage_stats.total_archives_size / |
| 122 (storage_stats.total_archives_size + storage_stats.free_disk_space) * |
| 123 100); |
| 124 UMA_HISTOGRAM_PERCENTAGE( |
| 125 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", |
| 126 percentage_of_free); |
| 127 } |
| 128 } |
| 129 |
| 94 } // namespace | 130 } // namespace |
| 95 | 131 |
| 96 // static | 132 // static |
| 97 bool OfflinePageModel::CanSavePage(const GURL& url) { | 133 bool OfflinePageModel::CanSavePage(const GURL& url) { |
| 98 return url.SchemeIsHTTPOrHTTPS(); | 134 return url.SchemeIsHTTPOrHTTPS(); |
| 99 } | 135 } |
| 100 | 136 |
| 101 // protected | 137 // protected |
| 102 OfflinePageModel::OfflinePageModel() | 138 OfflinePageModel::OfflinePageModel() |
| 103 : is_loaded_(false), weak_ptr_factory_(this) {} | 139 : is_loaded_(false), weak_ptr_factory_(this) {} |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 505 } |
| 470 | 506 |
| 471 void OfflinePageModel::CheckForExternalFileDeletion() { | 507 void OfflinePageModel::CheckForExternalFileDeletion() { |
| 472 DCHECK(is_loaded_); | 508 DCHECK(is_loaded_); |
| 473 | 509 |
| 474 archive_manager_->GetAllArchives( | 510 archive_manager_->GetAllArchives( |
| 475 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, | 511 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, |
| 476 weak_ptr_factory_.GetWeakPtr())); | 512 weak_ptr_factory_.GetWeakPtr())); |
| 477 } | 513 } |
| 478 | 514 |
| 479 void OfflinePageModel::RecordStorageHistograms(int64_t total_space_bytes, | |
| 480 int64_t free_space_bytes, | |
| 481 bool reporting_after_delete) { | |
| 482 // Total space taken by offline pages. | |
| 483 int64_t total_page_size = 0; | |
| 484 for (const auto& id_page_pair : offline_pages_) { | |
| 485 total_page_size += id_page_pair.second.file_size; | |
| 486 } | |
| 487 | |
| 488 int total_page_size_mb = static_cast<int>(total_page_size / (1024 * 1024)); | |
| 489 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); | |
| 490 | |
| 491 // How much of the total space the offline pages take. | |
| 492 int total_page_size_percentage = | |
| 493 static_cast<int>(1.0 * total_page_size / total_space_bytes * 100); | |
| 494 UMA_HISTOGRAM_PERCENTAGE("OfflinePages.TotalPageSizePercentage", | |
| 495 total_page_size_percentage); | |
| 496 | |
| 497 // If the user is deleting the pages, perhaps they are running out of free | |
| 498 // space. Report the size before the operation, where a base for calculation | |
| 499 // of total free space includes space taken by offline pages. | |
| 500 if (reporting_after_delete && free_space_bytes > 0) { | |
| 501 int percentage_of_free = static_cast<int>( | |
| 502 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100); | |
| 503 UMA_HISTOGRAM_PERCENTAGE( | |
| 504 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", | |
| 505 percentage_of_free); | |
| 506 } | |
| 507 } | |
| 508 | |
| 509 ClientPolicyController* OfflinePageModel::GetPolicyController() { | 515 ClientPolicyController* OfflinePageModel::GetPolicyController() { |
| 510 return policy_controller_.get(); | 516 return policy_controller_.get(); |
| 511 } | 517 } |
| 512 | 518 |
| 513 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { | 519 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { |
| 514 return store_.get(); | 520 return store_.get(); |
| 515 } | 521 } |
| 516 | 522 |
| 517 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { | 523 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { |
| 518 return storage_manager_.get(); | 524 return storage_manager_.get(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 } | 638 } |
| 633 | 639 |
| 634 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, | 640 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, |
| 635 SavePageResult result, | 641 SavePageResult result, |
| 636 const ClientId& client_id, | 642 const ClientId& client_id, |
| 637 int64_t offline_id) { | 643 int64_t offline_id) { |
| 638 UMA_HISTOGRAM_ENUMERATION( | 644 UMA_HISTOGRAM_ENUMERATION( |
| 639 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(), | 645 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(), |
| 640 static_cast<int>(result), | 646 static_cast<int>(result), |
| 641 static_cast<int>(SavePageResult::RESULT_COUNT)); | 647 static_cast<int>(SavePageResult::RESULT_COUNT)); |
| 648 archive_manager_->GetStorageStats( |
| 649 base::Bind(&ReportStorageHistogramsAfterSave)); |
| 642 callback.Run(result, offline_id); | 650 callback.Run(result, offline_id); |
| 643 } | 651 } |
| 644 | 652 |
| 645 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { | 653 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { |
| 646 pending_archivers_.erase(std::find( | 654 pending_archivers_.erase(std::find( |
| 647 pending_archivers_.begin(), pending_archivers_.end(), archiver)); | 655 pending_archivers_.begin(), pending_archivers_.end(), archiver)); |
| 648 } | 656 } |
| 649 | 657 |
| 650 void OfflinePageModel::OnDeleteArchiveFilesDone( | 658 void OfflinePageModel::OnDeleteArchiveFilesDone( |
| 651 const std::vector<int64_t>& offline_ids, | 659 const std::vector<int64_t>& offline_ids, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 ? DeletePageResult::SUCCESS | 728 ? DeletePageResult::SUCCESS |
| 721 : DeletePageResult::STORE_FAILURE); | 729 : DeletePageResult::STORE_FAILURE); |
| 722 } | 730 } |
| 723 | 731 |
| 724 void OfflinePageModel::InformDeletePageDone(const DeletePageCallback& callback, | 732 void OfflinePageModel::InformDeletePageDone(const DeletePageCallback& callback, |
| 725 DeletePageResult result) { | 733 DeletePageResult result) { |
| 726 UMA_HISTOGRAM_ENUMERATION( | 734 UMA_HISTOGRAM_ENUMERATION( |
| 727 "OfflinePages.DeletePageResult", | 735 "OfflinePages.DeletePageResult", |
| 728 static_cast<int>(result), | 736 static_cast<int>(result), |
| 729 static_cast<int>(DeletePageResult::RESULT_COUNT)); | 737 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
| 738 archive_manager_->GetStorageStats( |
| 739 base::Bind(&ReportStorageHistogramsAfterDelete)); |
| 730 if (!callback.is_null()) | 740 if (!callback.is_null()) |
| 731 callback.Run(result); | 741 callback.Run(result); |
| 732 } | 742 } |
| 733 | 743 |
| 734 void OfflinePageModel::ScanForMissingArchiveFiles( | 744 void OfflinePageModel::ScanForMissingArchiveFiles( |
| 735 const std::set<base::FilePath>& archive_paths) { | 745 const std::set<base::FilePath>& archive_paths) { |
| 736 std::vector<int64_t> ids_of_pages_missing_archive_file; | 746 std::vector<int64_t> ids_of_pages_missing_archive_file; |
| 737 std::vector<std::pair<int64_t, ClientId>> offline_client_id_pairs; | 747 std::vector<std::pair<int64_t, ClientId>> offline_client_id_pairs; |
| 738 for (const auto& id_page_pair : offline_pages_) { | 748 for (const auto& id_page_pair : offline_pages_) { |
| 739 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) { | 749 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { | 830 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { |
| 821 if (!is_loaded_) { | 831 if (!is_loaded_) { |
| 822 delayed_tasks_.push_back(task); | 832 delayed_tasks_.push_back(task); |
| 823 return; | 833 return; |
| 824 } | 834 } |
| 825 | 835 |
| 826 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 836 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 827 } | 837 } |
| 828 | 838 |
| 829 } // namespace offline_pages | 839 } // namespace offline_pages |
| OLD | NEW |