Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 case ArchiverResult::ERROR_SECURITY_CERTIFICATE: | 72 case ArchiverResult::ERROR_SECURITY_CERTIFICATE: |
| 73 result = SavePageResult::SECURITY_CERTIFICATE_ERROR; | 73 result = SavePageResult::SECURITY_CERTIFICATE_ERROR; |
| 74 break; | 74 break; |
| 75 default: | 75 default: |
| 76 NOTREACHED(); | 76 NOTREACHED(); |
| 77 result = SavePageResult::CONTENT_UNAVAILABLE; | 77 result = SavePageResult::CONTENT_UNAVAILABLE; |
| 78 } | 78 } |
| 79 return result; | 79 return result; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ReportStorageUMAAfterSave( | |
|
jianli
2016/05/18 00:06:00
ReportStorageHistogramsAfterSave
fgorski
2016/05/18 18:14:59
Done.
| |
| 83 const ArchiveManager::StorageSizes storage_sizes) { | |
|
jianli
2016/05/18 00:06:00
nit: add &
fgorski
2016/05/18 18:14:59
Done.
| |
| 84 int mb = 1024 * 1024; | |
|
jianli
2016/05/18 00:06:00
nit: const int or inline it
fgorski
2016/05/18 18:14:59
Done.
| |
| 85 int free_disk_space_mb = static_cast<int>(storage_sizes.free_disk_space / mb); | |
| 86 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.SavePage.FreeSpaceMB", | |
| 87 free_disk_space_mb, 1, 500000, 50); | |
| 88 | |
| 89 int total_page_size_mb = | |
| 90 static_cast<int>(storage_sizes.total_archives_size / mb); | |
| 91 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); | |
| 92 } | |
| 93 | |
| 94 void ReportStorageUMAAfterDelete( | |
| 95 const ArchiveManager::StorageSizes storage_sizes) { | |
| 96 int mb = 1024 * 1024; | |
| 97 int free_disk_space_mb = static_cast<int>(storage_sizes.free_disk_space / mb); | |
| 98 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DeletePage.FreeSpaceMB", | |
| 99 free_disk_space_mb, 1, 500000, 50); | |
| 100 | |
| 101 int total_page_size_mb = | |
| 102 static_cast<int>(storage_sizes.total_archives_size / mb); | |
| 103 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); | |
| 104 | |
| 105 if (storage_sizes.free_disk_space > 0) { | |
| 106 int percentage_of_free = static_cast<int>( | |
| 107 1.0 * storage_sizes.total_archives_size / | |
| 108 (storage_sizes.total_archives_size + storage_sizes.free_disk_space) * | |
| 109 100); | |
| 110 UMA_HISTOGRAM_PERCENTAGE( | |
| 111 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", | |
| 112 percentage_of_free); | |
| 113 } | |
| 114 } | |
| 115 | |
| 82 } // namespace | 116 } // namespace |
| 83 | 117 |
| 84 // static | 118 // static |
| 85 bool OfflinePageModel::CanSavePage(const GURL& url) { | 119 bool OfflinePageModel::CanSavePage(const GURL& url) { |
| 86 return url.SchemeIsHTTPOrHTTPS(); | 120 return url.SchemeIsHTTPOrHTTPS(); |
| 87 } | 121 } |
| 88 | 122 |
| 89 // protected | 123 // protected |
| 90 OfflinePageModel::OfflinePageModel() | 124 OfflinePageModel::OfflinePageModel() |
| 91 : is_loaded_(false), weak_ptr_factory_(this) {} | 125 : is_loaded_(false), weak_ptr_factory_(this) {} |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } | 486 } |
| 453 | 487 |
| 454 void OfflinePageModel::CheckForExternalFileDeletion() { | 488 void OfflinePageModel::CheckForExternalFileDeletion() { |
| 455 DCHECK(is_loaded_); | 489 DCHECK(is_loaded_); |
| 456 | 490 |
| 457 archive_manager_->GetAllArchives( | 491 archive_manager_->GetAllArchives( |
| 458 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, | 492 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, |
| 459 weak_ptr_factory_.GetWeakPtr())); | 493 weak_ptr_factory_.GetWeakPtr())); |
| 460 } | 494 } |
| 461 | 495 |
| 462 void OfflinePageModel::RecordStorageHistograms(int64_t total_space_bytes, | |
| 463 int64_t free_space_bytes, | |
| 464 bool reporting_after_delete) { | |
| 465 // Total space taken by offline pages. | |
| 466 int64_t total_page_size = 0; | |
| 467 for (const auto& id_page_pair : offline_pages_) { | |
| 468 total_page_size += id_page_pair.second.file_size; | |
| 469 } | |
| 470 | |
| 471 int total_page_size_mb = static_cast<int>(total_page_size / (1024 * 1024)); | |
| 472 UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb); | |
| 473 | |
| 474 // How much of the total space the offline pages take. | |
| 475 int total_page_size_percentage = | |
| 476 static_cast<int>(1.0 * total_page_size / total_space_bytes * 100); | |
| 477 UMA_HISTOGRAM_PERCENTAGE("OfflinePages.TotalPageSizePercentage", | |
| 478 total_page_size_percentage); | |
| 479 | |
| 480 // If the user is deleting the pages, perhaps they are running out of free | |
| 481 // space. Report the size before the operation, where a base for calculation | |
| 482 // of total free space includes space taken by offline pages. | |
| 483 if (reporting_after_delete && free_space_bytes > 0) { | |
| 484 int percentage_of_free = static_cast<int>( | |
| 485 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100); | |
| 486 UMA_HISTOGRAM_PERCENTAGE( | |
| 487 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", | |
| 488 percentage_of_free); | |
| 489 } | |
| 490 } | |
| 491 | |
| 492 ClientPolicyController* OfflinePageModel::GetPolicyController() { | 496 ClientPolicyController* OfflinePageModel::GetPolicyController() { |
| 493 return policy_controller_.get(); | 497 return policy_controller_.get(); |
| 494 } | 498 } |
| 495 | 499 |
| 496 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { | 500 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { |
| 497 return store_.get(); | 501 return store_.get(); |
| 498 } | 502 } |
| 499 | 503 |
| 500 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { | 504 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { |
| 501 return storage_manager_.get(); | 505 return storage_manager_.get(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 CheckForExternalFileDeletion(); | 614 CheckForExternalFileDeletion(); |
| 611 } | 615 } |
| 612 | 616 |
| 613 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, | 617 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, |
| 614 SavePageResult result, | 618 SavePageResult result, |
| 615 int64_t offline_id) { | 619 int64_t offline_id) { |
| 616 UMA_HISTOGRAM_ENUMERATION( | 620 UMA_HISTOGRAM_ENUMERATION( |
| 617 "OfflinePages.SavePageResult", | 621 "OfflinePages.SavePageResult", |
| 618 static_cast<int>(result), | 622 static_cast<int>(result), |
| 619 static_cast<int>(SavePageResult::RESULT_COUNT)); | 623 static_cast<int>(SavePageResult::RESULT_COUNT)); |
| 624 archive_manager_->GetStorageSizes(base::Bind(&ReportStorageUMAAfterSave)); | |
| 620 callback.Run(result, offline_id); | 625 callback.Run(result, offline_id); |
| 621 } | 626 } |
| 622 | 627 |
| 623 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { | 628 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { |
| 624 pending_archivers_.erase(std::find( | 629 pending_archivers_.erase(std::find( |
| 625 pending_archivers_.begin(), pending_archivers_.end(), archiver)); | 630 pending_archivers_.begin(), pending_archivers_.end(), archiver)); |
| 626 } | 631 } |
| 627 | 632 |
| 628 void OfflinePageModel::OnDeleteArchiveFilesDone( | 633 void OfflinePageModel::OnDeleteArchiveFilesDone( |
| 629 const std::vector<int64_t>& offline_ids, | 634 const std::vector<int64_t>& offline_ids, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 ? DeletePageResult::SUCCESS | 696 ? DeletePageResult::SUCCESS |
| 692 : DeletePageResult::STORE_FAILURE); | 697 : DeletePageResult::STORE_FAILURE); |
| 693 } | 698 } |
| 694 | 699 |
| 695 void OfflinePageModel::InformDeletePageDone(const DeletePageCallback& callback, | 700 void OfflinePageModel::InformDeletePageDone(const DeletePageCallback& callback, |
| 696 DeletePageResult result) { | 701 DeletePageResult result) { |
| 697 UMA_HISTOGRAM_ENUMERATION( | 702 UMA_HISTOGRAM_ENUMERATION( |
| 698 "OfflinePages.DeletePageResult", | 703 "OfflinePages.DeletePageResult", |
| 699 static_cast<int>(result), | 704 static_cast<int>(result), |
| 700 static_cast<int>(DeletePageResult::RESULT_COUNT)); | 705 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
| 706 archive_manager_->GetStorageSizes(base::Bind(&ReportStorageUMAAfterDelete)); | |
| 701 if (!callback.is_null()) | 707 if (!callback.is_null()) |
| 702 callback.Run(result); | 708 callback.Run(result); |
| 703 } | 709 } |
| 704 | 710 |
| 705 void OfflinePageModel::ScanForMissingArchiveFiles( | 711 void OfflinePageModel::ScanForMissingArchiveFiles( |
| 706 const std::set<base::FilePath>& archive_paths) { | 712 const std::set<base::FilePath>& archive_paths) { |
| 707 std::vector<int64_t> ids_of_pages_missing_archive_file; | 713 std::vector<int64_t> ids_of_pages_missing_archive_file; |
| 708 std::vector<std::pair<int64_t, ClientId>> offline_client_id_pairs; | 714 std::vector<std::pair<int64_t, ClientId>> offline_client_id_pairs; |
| 709 for (const auto& id_page_pair : offline_pages_) { | 715 for (const auto& id_page_pair : offline_pages_) { |
| 710 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) { | 716 if (archive_paths.count(id_page_pair.second.file_path) == 0UL) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { | 797 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { |
| 792 if (!is_loaded_) { | 798 if (!is_loaded_) { |
| 793 delayed_tasks_.push_back(task); | 799 delayed_tasks_.push_back(task); |
| 794 return; | 800 return; |
| 795 } | 801 } |
| 796 | 802 |
| 797 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 803 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 798 } | 804 } |
| 799 | 805 |
| 800 } // namespace offline_pages | 806 } // namespace offline_pages |
| OLD | NEW |