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

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2343743002: [Offline pages] Updating the UpdateCallback in OPMStoreSQL (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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/offline_pages/offline_page_model_impl.h" 5 #include "components/offline_pages/offline_page_model_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 base::TimeDelta::FromSeconds(1).InSeconds(), 229 base::TimeDelta::FromSeconds(1).InSeconds(),
230 base::TimeDelta::FromDays(7).InSeconds(), 50); 230 base::TimeDelta::FromDays(7).InSeconds(), 50);
231 } 231 }
232 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DownloadSavedPageDuplicateCount", 232 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DownloadSavedPageDuplicateCount",
233 matching_url_count, 1, 20, 10); 233 matching_url_count, 1, 20, 10);
234 } 234 }
235 } 235 }
236 236
237 void ReportPageHistogramsAfterDelete( 237 void ReportPageHistogramsAfterDelete(
238 const std::map<int64_t, OfflinePageItem>& offline_pages, 238 const std::map<int64_t, OfflinePageItem>& offline_pages,
239 const std::vector<int64_t>& deleted_offline_ids, 239 const std::vector<OfflinePageItem>& deleted_pages,
240 const base::Time& delete_time) { 240 const base::Time& delete_time) {
241 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); 241 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes();
242 int64_t total_size = 0; 242 int64_t total_size = 0;
243 for (int64_t offline_id : deleted_offline_ids) {
244 auto iter = offline_pages.find(offline_id);
245 if (iter == offline_pages.end())
246 continue;
247 243
248 total_size += iter->second.file_size; 244 for (const auto& page : deleted_pages) {
Pete Williamson 2016/09/15 18:05:43 Nice change, this is much more readable than iter-
fgorski 2016/09/19 23:24:30 Acknowledged.
249 ClientId client_id = iter->second.client_id; 245 total_size += page.file_size;
246 ClientId client_id = page.client_id;
250 247
251 if (client_id.name_space == kDownloadNamespace) { 248 if (client_id.name_space == kDownloadNamespace) {
252 int remaining_pages_with_url; 249 int remaining_pages_with_url;
253 GetMatchingURLCountAndMostRecentCreationTime( 250 GetMatchingURLCountAndMostRecentCreationTime(
254 offline_pages, iter->second.client_id.name_space, iter->second.url, 251 offline_pages, page.client_id.name_space, page.url, base::Time::Max(),
255 base::Time::Max(), &remaining_pages_with_url, nullptr); 252 &remaining_pages_with_url, nullptr);
256 UMA_HISTOGRAM_CUSTOM_COUNTS( 253 UMA_HISTOGRAM_CUSTOM_COUNTS(
257 "OfflinePages.DownloadDeletedPageDuplicateCount", 254 "OfflinePages.DownloadDeletedPageDuplicateCount",
258 remaining_pages_with_url, 1, 20, 10); 255 remaining_pages_with_url, 1, 20, 10);
259 } 256 }
260 257
261 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 258 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
262 // macro adapted to allow for a dynamically suffixed histogram name. 259 // macro adapted to allow for a dynamically suffixed histogram name.
263 // Note: The factory creates and owns the histogram. 260 // Note: The factory creates and owns the histogram.
264 base::HistogramBase* histogram = base::Histogram::FactoryGet( 261 base::HistogramBase* histogram = base::Histogram::FactoryGet(
265 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), 262 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"),
266 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 263 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
267 histogram->Add((delete_time - iter->second.creation_time).InMinutes()); 264 histogram->Add((delete_time - page.creation_time).InMinutes());
268 265
269 histogram = base::Histogram::FactoryGet( 266 histogram = base::Histogram::FactoryGet(
270 AddHistogramSuffix( 267 AddHistogramSuffix(
271 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), 268 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"),
272 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 269 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
273 histogram->Add((delete_time - iter->second.last_access_time).InMinutes()); 270 histogram->Add((delete_time - page.last_access_time).InMinutes());
274 271
275 histogram = base::Histogram::FactoryGet( 272 histogram = base::Histogram::FactoryGet(
276 AddHistogramSuffix( 273 AddHistogramSuffix(
277 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), 274 client_id, "OfflinePages.DeletePage.LastOpenToCreated"),
278 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 275 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
279 histogram->Add( 276 histogram->Add((page.last_access_time - page.creation_time).InMinutes());
280 (iter->second.last_access_time - iter->second.creation_time).
281 InMinutes());
282 277
283 // Reported as Kb between 1Kb and 10Mb. 278 // Reported as Kb between 1Kb and 10Mb.
284 histogram = base::Histogram::FactoryGet( 279 histogram = base::Histogram::FactoryGet(
285 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), 280 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"),
286 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); 281 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
287 histogram->Add(iter->second.file_size / 1024); 282 histogram->Add(page.file_size / 1024);
288 283
289 histogram = base::Histogram::FactoryGet( 284 histogram = base::Histogram::FactoryGet(
290 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), 285 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"),
291 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); 286 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
292 histogram->Add(iter->second.access_count); 287 histogram->Add(page.access_count);
293 } 288 }
294 289
295 if (deleted_offline_ids.size() > 1) { 290 if (deleted_pages.size() > 1) {
296 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", 291 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
297 static_cast<int32_t>(deleted_offline_ids.size())); 292 static_cast<int32_t>(deleted_pages.size()));
298 UMA_HISTOGRAM_MEMORY_KB( 293 UMA_HISTOGRAM_MEMORY_KB(
299 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); 294 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024);
300 } 295 }
301 } 296 }
302 297
303 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, 298 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item,
304 const base::Time& access_time) { 299 const base::Time& access_time) {
305 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 300 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
306 // macro adapted to allow for a dynamically suffixed histogram name. 301 // macro adapted to allow for a dynamically suffixed histogram name.
307 // Note: The factory creates and owns the histogram. 302 // Note: The factory creates and owns the histogram.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 if (iter == offline_pages_.end()) 677 if (iter == offline_pages_.end())
683 continue; 678 continue;
684 679
685 OfflinePageItem offline_page = iter->second; 680 OfflinePageItem offline_page = iter->second;
686 paths_to_delete.push_back(offline_page.file_path); 681 paths_to_delete.push_back(offline_page.file_path);
687 offline_page.expiration_time = expiration_time; 682 offline_page.expiration_time = expiration_time;
688 683
689 items_to_update.push_back(offline_page); 684 items_to_update.push_back(offline_page);
690 } 685 }
691 686
692 store_->UpdateOfflinePages(items_to_update, 687 store_->UpdateOfflinePages(
693 base::Bind(&OfflinePageModelImpl::OnExpirePageDone, 688 items_to_update,
694 weak_ptr_factory_.GetWeakPtr(), 689 base::Bind(&OfflinePageModelImpl::OnExpirePageDone,
695 items_to_update, expiration_time)); 690 weak_ptr_factory_.GetWeakPtr(), expiration_time));
696 691
697 if (paths_to_delete.empty()) { 692 if (paths_to_delete.empty()) {
698 callback.Run(true); 693 callback.Run(true);
699 return; 694 return;
700 } 695 }
701 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); 696 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback);
702 } 697 }
703 698
704 void OfflinePageModelImpl::OnExpirePageDone( 699 void OfflinePageModelImpl::OnExpirePageDone(
705 const std::vector<OfflinePageItem>& expired_pages,
706 const base::Time& expiration_time, 700 const base::Time& expiration_time,
707 bool success) { 701 const std::map<int64_t, OfflinePageMetadataStore::ItemActionStatus>&
708 UMA_HISTOGRAM_BOOLEAN("OfflinePages.ExpirePage.StoreUpdateResult", success); 702 failed_results,
709 if (!success) 703 const std::vector<OfflinePageItem>& expired_pages) {
710 return; 704 UMA_HISTOGRAM_BOOLEAN("OfflinePages.ExpirePage.StoreUpdateResult",
705 failed_results.size() > 0);
711 for (auto& expired_page : expired_pages) { 706 for (auto& expired_page : expired_pages) {
712 const auto& iter = offline_pages_.find(expired_page.offline_id); 707 const auto& iter = offline_pages_.find(expired_page.offline_id);
713 if (iter == offline_pages_.end()) 708 if (iter == offline_pages_.end())
714 continue; 709 continue;
715 710
716 iter->second.expiration_time = expiration_time; 711 iter->second.expiration_time = expiration_time;
717 ClientId client_id = iter->second.client_id; 712 ClientId client_id = iter->second.client_id;
718 offline_event_logger_.RecordPageExpired( 713 offline_event_logger_.RecordPageExpired(
719 std::to_string(expired_page.offline_id)); 714 std::to_string(expired_page.offline_id));
720 base::HistogramBase* histogram = base::Histogram::FactoryGet( 715 base::HistogramBase* histogram = base::Histogram::FactoryGet(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } else { 809 } else {
815 PostClearStorageIfNeededTask(); 810 PostClearStorageIfNeededTask();
816 } 811 }
817 812
818 DeletePendingArchiver(archiver); 813 DeletePendingArchiver(archiver);
819 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); 814 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this));
820 } 815 }
821 816
822 void OfflinePageModelImpl::OnMarkPageAccesseDone( 817 void OfflinePageModelImpl::OnMarkPageAccesseDone(
823 const OfflinePageItem& offline_page_item, 818 const OfflinePageItem& offline_page_item,
824 bool success) { 819 const std::map<int64_t, OfflinePageMetadataStore::ItemActionStatus>&
820 failed_results,
821 const std::vector<OfflinePageItem>& updated_items) {
825 // Update the item in the cache only upon success. 822 // Update the item in the cache only upon success.
826 if (success) 823 if (updated_items.size() > 0)
827 offline_pages_[offline_page_item.offline_id] = offline_page_item; 824 offline_pages_[offline_page_item.offline_id] = offline_page_item;
828 825
829 // No need to fire OfflinePageModelChanged event since updating access info 826 // No need to fire OfflinePageModelChanged event since updating access info
830 // should not have any impact to the UI. 827 // should not have any impact to the UI.
831 } 828 }
832 829
833 void OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone( 830 void OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone(
834 const base::TimeTicks& start_time) { 831 const base::TimeTicks& start_time) {
835 UMA_HISTOGRAM_TIMES("OfflinePages.Model.ArchiveDirCreationTime", 832 UMA_HISTOGRAM_TIMES("OfflinePages.Model.ArchiveDirCreationTime",
836 base::TimeTicks::Now() - start_time); 833 base::TimeTicks::Now() - start_time);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 void OfflinePageModelImpl::OnDeleteArchiveFilesDone( 941 void OfflinePageModelImpl::OnDeleteArchiveFilesDone(
945 const std::vector<int64_t>& offline_ids, 942 const std::vector<int64_t>& offline_ids,
946 const DeletePageCallback& callback, 943 const DeletePageCallback& callback,
947 bool success) { 944 bool success) {
948 if (!success) { 945 if (!success) {
949 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE); 946 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE);
950 return; 947 return;
951 } 948 }
952 949
953 store_->RemoveOfflinePages( 950 store_->RemoveOfflinePages(
954 offline_ids, 951 offline_ids, base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone,
955 base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, 952 weak_ptr_factory_.GetWeakPtr(), callback));
956 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
957 } 953 }
958 954
959 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( 955 void OfflinePageModelImpl::OnRemoveOfflinePagesDone(
960 const std::vector<int64_t>& offline_ids,
961 const DeletePageCallback& callback, 956 const DeletePageCallback& callback,
962 bool success) { 957 const std::map<int64_t, OfflinePageMetadataStore::ItemActionStatus>&
963 ReportPageHistogramsAfterDelete( 958 failed_items,
964 offline_pages_, offline_ids, GetCurrentTime()); 959 const std::vector<OfflinePageItem>& removed_pages) {
960 ReportPageHistogramsAfterDelete(offline_pages_, removed_pages,
961 GetCurrentTime());
965 962
966 for (int64_t offline_id : offline_ids) { 963 // This pat of the loop is explicitly broken out, as it should be gone in
964 // fully asynchronous code.
965 for (const auto& page : removed_pages) {
966 int64_t offline_id = page.offline_id;
967 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); 967 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id));
968 auto iter = offline_pages_.find(offline_id); 968 auto iter = offline_pages_.find(offline_id);
969 if (iter == offline_pages_.end()) 969 if (iter == offline_pages_.end())
970 continue; 970 continue;
971 FOR_EACH_OBSERVER(
972 Observer, observers_,
973 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id));
974 offline_pages_.erase(iter); 971 offline_pages_.erase(iter);
975 } 972 }
976 973
977 // Deleting multiple pages always succeeds when it gets to this point. 974 for (const auto& page : removed_pages) {
978 InformDeletePageDone(callback, (success || offline_ids.size() > 1) 975 FOR_EACH_OBSERVER(Observer, observers_,
979 ? DeletePageResult::SUCCESS 976 OfflinePageDeleted(page.offline_id, page.client_id));
980 : DeletePageResult::STORE_FAILURE); 977 }
978
979 DeletePageResult result = DeletePageResult::SUCCESS;
980 if (failed_items.size() > 0 &&
981 failed_items.begin()->second == OfflinePageMetadataStore::STORE_ERROR) {
982 result = DeletePageResult::STORE_FAILURE;
983 }
984 InformDeletePageDone(callback, result);
981 } 985 }
982 986
983 void OfflinePageModelImpl::InformDeletePageDone( 987 void OfflinePageModelImpl::InformDeletePageDone(
984 const DeletePageCallback& callback, 988 const DeletePageCallback& callback,
985 DeletePageResult result) { 989 DeletePageResult result) {
986 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult", 990 UMA_HISTOGRAM_ENUMERATION("OfflinePages.DeletePageResult",
987 static_cast<int>(result), 991 static_cast<int>(result),
988 static_cast<int>(DeletePageResult::RESULT_COUNT)); 992 static_cast<int>(DeletePageResult::RESULT_COUNT));
989 archive_manager_->GetStorageStats( 993 archive_manager_->GetStorageStats(
990 base::Bind(&ReportStorageHistogramsAfterDelete)); 994 base::Bind(&ReportStorageHistogramsAfterDelete));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 } 1145 }
1142 1146
1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1147 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1144 } 1148 }
1145 1149
1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1150 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1151 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1148 } 1152 }
1149 1153
1150 } // namespace offline_pages 1154 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698