Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: components/offline_pages/offline_page_model.cc

Issue 1988973002: [Offline pages] Moving disk size related calls to Archive Manager, reorganizing UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@archive-manager
Patch Set: Addressing feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/offline_page_model.cc
diff --git a/components/offline_pages/offline_page_model.cc b/components/offline_pages/offline_page_model.cc
index b0455e89553ab05fc04b86452319758ba089ce5c..e61f2d670f3606c1fdf684273b25a45acf526c48 100644
--- a/components/offline_pages/offline_page_model.cc
+++ b/components/offline_pages/offline_page_model.cc
@@ -91,6 +91,42 @@ std::string AddHistogramSuffix(const ClientId& client_id,
return adjusted_histogram_name;
}
+void ReportStorageHistogramsAfterSave(
+ const ArchiveManager::StorageStats& storage_stats) {
+ const int kMB = 1024 * 1024;
+ int free_disk_space_mb =
+ static_cast<int>(storage_stats.free_disk_space / kMB);
+ UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.SavePage.FreeSpaceMB",
+ free_disk_space_mb, 1, 500000, 50);
+
+ int total_page_size_mb =
+ static_cast<int>(storage_stats.total_archives_size / kMB);
+ UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb);
+}
+
+void ReportStorageHistogramsAfterDelete(
+ const ArchiveManager::StorageStats& storage_stats) {
+ const int kMB = 1024 * 1024;
+ int free_disk_space_mb =
+ static_cast<int>(storage_stats.free_disk_space / kMB);
+ UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DeletePage.FreeSpaceMB",
+ free_disk_space_mb, 1, 500000, 50);
+
+ int total_page_size_mb =
+ static_cast<int>(storage_stats.total_archives_size / kMB);
+ UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb);
+
+ if (storage_stats.free_disk_space > 0) {
+ int percentage_of_free = static_cast<int>(
+ 1.0 * storage_stats.total_archives_size /
+ (storage_stats.total_archives_size + storage_stats.free_disk_space) *
+ 100);
+ UMA_HISTOGRAM_PERCENTAGE(
+ "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace",
+ percentage_of_free);
+ }
+}
+
} // namespace
// static
@@ -476,36 +512,6 @@ void OfflinePageModel::CheckForExternalFileDeletion() {
weak_ptr_factory_.GetWeakPtr()));
}
-void OfflinePageModel::RecordStorageHistograms(int64_t total_space_bytes,
- int64_t free_space_bytes,
- bool reporting_after_delete) {
- // Total space taken by offline pages.
- int64_t total_page_size = 0;
- for (const auto& id_page_pair : offline_pages_) {
- total_page_size += id_page_pair.second.file_size;
- }
-
- int total_page_size_mb = static_cast<int>(total_page_size / (1024 * 1024));
- UMA_HISTOGRAM_COUNTS_10000("OfflinePages.TotalPageSize", total_page_size_mb);
-
- // How much of the total space the offline pages take.
- int total_page_size_percentage =
- static_cast<int>(1.0 * total_page_size / total_space_bytes * 100);
- UMA_HISTOGRAM_PERCENTAGE("OfflinePages.TotalPageSizePercentage",
- total_page_size_percentage);
-
- // If the user is deleting the pages, perhaps they are running out of free
- // space. Report the size before the operation, where a base for calculation
- // of total free space includes space taken by offline pages.
- if (reporting_after_delete && free_space_bytes > 0) {
- int percentage_of_free = static_cast<int>(
- 1.0 * total_page_size / (total_page_size + free_space_bytes) * 100);
- UMA_HISTOGRAM_PERCENTAGE(
- "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace",
- percentage_of_free);
- }
-}
-
ClientPolicyController* OfflinePageModel::GetPolicyController() {
return policy_controller_.get();
}
@@ -639,6 +645,8 @@ void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback,
AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
static_cast<int>(result),
static_cast<int>(SavePageResult::RESULT_COUNT));
+ archive_manager_->GetStorageStats(
+ base::Bind(&ReportStorageHistogramsAfterSave));
callback.Run(result, offline_id);
}
@@ -727,6 +735,8 @@ void OfflinePageModel::InformDeletePageDone(const DeletePageCallback& callback,
"OfflinePages.DeletePageResult",
static_cast<int>(result),
static_cast<int>(DeletePageResult::RESULT_COUNT));
+ archive_manager_->GetStorageStats(
+ base::Bind(&ReportStorageHistogramsAfterDelete));
if (!callback.is_null())
callback.Run(result);
}
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698