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

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

Issue 2015793002: [Offline Pages] Linking storage manager and model with UMAs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wisp
Patch Set: Adding more UMAs and hooking up model and storage manager. Created 4 years, 6 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 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/optional.h" 15 #include "base/optional.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "components/offline_pages/archive_manager.h" 21 #include "components/offline_pages/archive_manager.h"
22 #include "components/offline_pages/client_policy_controller.h" 22 #include "components/offline_pages/client_policy_controller.h"
23 #include "components/offline_pages/offline_page_item.h" 23 #include "components/offline_pages/offline_page_item.h"
24 #include "components/offline_pages/offline_page_storage_manager.h" 24 #include "components/offline_pages/offline_page_storage_manager.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; 27 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult;
28 using ClearStorageCallback =
29 offline_pages::OfflinePageStorageManager::ClearStorageCallback;
30 using ClearStorageResult =
31 offline_pages::OfflinePageStorageManager::ClearStorageResult;
28 32
29 namespace offline_pages { 33 namespace offline_pages {
30 34
31 namespace { 35 namespace {
32 36
33 // This enum is used in an UMA histogram. Hence the entries here shouldn't 37 // This enum is used in an UMA histogram. Hence the entries here shouldn't
34 // be deleted or re-ordered and new ones should be added to the end. 38 // be deleted or re-ordered and new ones should be added to the end.
35 enum ClearAllStatus { 39 enum ClearAllStatus {
36 CLEAR_ALL_SUCCEEDED, 40 CLEAR_ALL_SUCCEEDED,
37 STORE_RESET_FAILED, 41 STORE_RESET_FAILED,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 if (paths_to_delete.empty()) { 532 if (paths_to_delete.empty()) {
529 callback.Run(true); 533 callback.Run(true);
530 return; 534 return;
531 } 535 }
532 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); 536 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback);
533 } 537 }
534 538
535 void OfflinePageModel::OnExpirePageDone(int64_t offline_id, 539 void OfflinePageModel::OnExpirePageDone(int64_t offline_id,
536 const base::Time& expiration_time, 540 const base::Time& expiration_time,
537 bool success) { 541 bool success) {
538 // TODO(romax): Report UMA about successful expiration. 542 UMA_HISTOGRAM_COUNTS("OfflinePages.ExpirePage.StoreUpdateResult",
jianli 2016/05/27 19:16:12 You should use UMA_HISTOGRAM_BOOLEAN.
romax 2016/05/27 20:36:02 Done.
539 if (success) { 543 success ? 0 : 1);
540 auto iter = offline_pages_.find(offline_id); 544 if (!success)
541 if (iter != offline_pages_.end()) 545 return;
542 iter->second.expiration_time = expiration_time; 546 auto iter = offline_pages_.find(offline_id);
jianli 2016/05/27 19:16:12 nit: add const&
romax 2016/05/27 20:36:02 Done.
547 if (iter != offline_pages_.end()) {
548 iter->second.expiration_time = expiration_time;
549 ClientId client_id = iter->second.client_id;
550 UMA_HISTOGRAM_CUSTOM_COUNTS(
551 AddHistogramSuffix(client_id, "OfflinePages.ExpirePage.PageLifetime")
552 .c_str(),
553 (expiration_time - iter->second.creation_time).InMinutes(), 1,
554 base::TimeDelta::FromDays(30).InMinutes(), 120);
jianli 2016/05/27 19:16:12 I think 50 buckets should be enough.
romax 2016/05/27 20:36:01 I don't have a strong opinion here, but can you el
jianli 2016/05/27 20:46:21 We should only try to use as many buckets as neede
555 UMA_HISTOGRAM_CUSTOM_COUNTS(
556 AddHistogramSuffix(client_id,
557 "OfflinePages.ExpirePage.TimeSinceLastAccess")
558 .c_str(),
559 (expiration_time - iter->second.last_access_time).InMinutes(), 1,
560 base::TimeDelta::FromDays(30).InMinutes(), 120);
jianli 2016/05/27 19:16:12 ditto
romax 2016/05/27 20:36:01 Done.
543 } 561 }
544 } 562 }
545 563
546 ClientPolicyController* OfflinePageModel::GetPolicyController() { 564 ClientPolicyController* OfflinePageModel::GetPolicyController() {
547 return policy_controller_.get(); 565 return policy_controller_.get();
548 } 566 }
549 567
550 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { 568 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() {
551 return store_.get(); 569 return store_.get();
552 } 570 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 674
657 // Create Storage Manager. 675 // Create Storage Manager.
658 storage_manager_.reset(new OfflinePageStorageManager( 676 storage_manager_.reset(new OfflinePageStorageManager(
659 this, GetPolicyController(), archive_manager_.get())); 677 this, GetPolicyController(), archive_manager_.get()));
660 678
661 // Run all the delayed tasks. 679 // Run all the delayed tasks.
662 for (const auto& delayed_task : delayed_tasks_) 680 for (const auto& delayed_task : delayed_tasks_)
663 delayed_task.Run(); 681 delayed_task.Run();
664 delayed_tasks_.clear(); 682 delayed_tasks_.clear();
665 683
684 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
jianli 2016/05/27 19:16:12 It just seems to be more natural to put this at th
romax 2016/05/27 20:36:02 Done.
685 FROM_HERE, base::Bind(&OfflinePageModel::ClearStorageIfNeeded,
686 weak_ptr_factory_.GetWeakPtr(),
687 base::Bind(&OfflinePageModel::OnStorageCleared,
688 weak_ptr_factory_.GetWeakPtr())),
689 base::TimeDelta::FromSeconds(20));
jianli 2016/05/27 19:16:12 Better define this as constant.
romax 2016/05/27 20:36:02 Done.
690
666 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelLoaded(this)); 691 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelLoaded(this));
667 692
668 CheckForExternalFileDeletion(); 693 CheckForExternalFileDeletion();
jianli 2016/05/27 19:16:13 Do we have the plan to move this to StorageManager
romax 2016/05/27 20:36:02 I think that would be the plan... I'll do that in
669 } 694 }
670 695
671 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, 696 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback,
672 SavePageResult result, 697 SavePageResult result,
673 const ClientId& client_id, 698 const ClientId& client_id,
674 int64_t offline_id) { 699 int64_t offline_id) {
675 UMA_HISTOGRAM_ENUMERATION( 700 UMA_HISTOGRAM_ENUMERATION(
676 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(), 701 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
677 static_cast<int>(result), 702 static_cast<int>(result),
678 static_cast<int>(SavePageResult::RESULT_COUNT)); 703 static_cast<int>(SavePageResult::RESULT_COUNT));
679 archive_manager_->GetStorageStats( 704 archive_manager_->GetStorageStats(
680 base::Bind(&ReportStorageHistogramsAfterSave)); 705 base::Bind(&ReportStorageHistogramsAfterSave));
706 base::ThreadTaskRunnerHandle::Get()->PostTask(
707 FROM_HERE, base::Bind(&OfflinePageModel::ClearStorageIfNeeded,
708 weak_ptr_factory_.GetWeakPtr(),
709 base::Bind(&OfflinePageModel::OnStorageCleared,
710 weak_ptr_factory_.GetWeakPtr())));
681 callback.Run(result, offline_id); 711 callback.Run(result, offline_id);
682 } 712 }
683 713
684 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { 714 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) {
685 pending_archivers_.erase(std::find( 715 pending_archivers_.erase(std::find(
686 pending_archivers_.begin(), pending_archivers_.end(), archiver)); 716 pending_archivers_.begin(), pending_archivers_.end(), archiver));
687 } 717 }
688 718
689 void OfflinePageModel::OnDeleteArchiveFilesDone( 719 void OfflinePageModel::OnDeleteArchiveFilesDone(
690 const std::vector<int64_t>& offline_ids, 720 const std::vector<int64_t>& offline_ids,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 callback.Run(); 878 callback.Run();
849 } 879 }
850 880
851 void OfflinePageModel::CacheLoadedData( 881 void OfflinePageModel::CacheLoadedData(
852 const std::vector<OfflinePageItem>& offline_pages) { 882 const std::vector<OfflinePageItem>& offline_pages) {
853 offline_pages_.clear(); 883 offline_pages_.clear();
854 for (const auto& offline_page : offline_pages) 884 for (const auto& offline_page : offline_pages)
855 offline_pages_[offline_page.offline_id] = offline_page; 885 offline_pages_[offline_page.offline_id] = offline_page;
856 } 886 }
857 887
888 void OfflinePageModel::ClearStorageIfNeeded(
889 const ClearStorageCallback& callback) {
890 storage_manager_->ClearPagesIfNeeded(callback);
891 }
892
893 void OfflinePageModel::OnStorageCleared(const size_t expired_page_count,
jianli 2016/05/27 19:16:12 nit: add const before size_t is not needed
romax 2016/05/27 20:36:02 Done.
894 ClearStorageResult result) {
895 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ExpirePage.Result",
896 static_cast<int>(result),
897 static_cast<int>(ClearStorageResult::RESULT_COUNT));
898 if (expired_page_count > 0) {
899 UMA_HISTOGRAM_COUNTS("OfflinePages.ExpirePage.BatchSize",
900 static_cast<int32_t>(expired_page_count));
901 }
902 }
903
904 // static
858 int64_t OfflinePageModel::GenerateOfflineId() { 905 int64_t OfflinePageModel::GenerateOfflineId() {
859 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; 906 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
860 } 907 }
861 908
862 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 909 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
863 if (!is_loaded_) { 910 if (!is_loaded_) {
864 delayed_tasks_.push_back(task); 911 delayed_tasks_.push_back(task);
865 return; 912 return;
866 } 913 }
867 914
868 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 915 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
869 } 916 }
870 917
871 } // namespace offline_pages 918 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698