OLD | NEW |
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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 } | 677 } |
678 | 678 |
679 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { | 679 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { |
680 return storage_manager_.get(); | 680 return storage_manager_.get(); |
681 } | 681 } |
682 | 682 |
683 bool OfflinePageModelImpl::is_loaded() const { | 683 bool OfflinePageModelImpl::is_loaded() const { |
684 return is_loaded_; | 684 return is_loaded_; |
685 } | 685 } |
686 | 686 |
| 687 OfflineEventLogger* OfflinePageModelImpl::GetLogger() { |
| 688 return &offline_event_logger_; |
| 689 } |
| 690 |
687 void OfflinePageModelImpl::OnCreateArchiveDone(const GURL& requested_url, | 691 void OfflinePageModelImpl::OnCreateArchiveDone(const GURL& requested_url, |
688 int64_t offline_id, | 692 int64_t offline_id, |
689 const ClientId& client_id, | 693 const ClientId& client_id, |
690 const base::Time& start_time, | 694 const base::Time& start_time, |
691 const SavePageCallback& callback, | 695 const SavePageCallback& callback, |
692 OfflinePageArchiver* archiver, | 696 OfflinePageArchiver* archiver, |
693 ArchiverResult archiver_result, | 697 ArchiverResult archiver_result, |
694 const GURL& url, | 698 const GURL& url, |
695 const base::FilePath& file_path, | 699 const base::FilePath& file_path, |
696 int64_t file_size) { | 700 int64_t file_size) { |
(...skipping 24 matching lines...) Expand all Loading... |
721 void OfflinePageModelImpl::OnAddOfflinePageDone( | 725 void OfflinePageModelImpl::OnAddOfflinePageDone( |
722 OfflinePageArchiver* archiver, | 726 OfflinePageArchiver* archiver, |
723 const SavePageCallback& callback, | 727 const SavePageCallback& callback, |
724 const OfflinePageItem& offline_page, | 728 const OfflinePageItem& offline_page, |
725 bool success) { | 729 bool success) { |
726 SavePageResult result; | 730 SavePageResult result; |
727 if (success) { | 731 if (success) { |
728 offline_pages_[offline_page.offline_id] = offline_page; | 732 offline_pages_[offline_page.offline_id] = offline_page; |
729 result = SavePageResult::SUCCESS; | 733 result = SavePageResult::SUCCESS; |
730 ReportPageHistogramAfterSave(offline_page); | 734 ReportPageHistogramAfterSave(offline_page); |
| 735 offline_event_logger_.RecordPageSaved( |
| 736 offline_page.client_id.name_space, offline_page.url.spec(), |
| 737 std::to_string(offline_page.offline_id)); |
731 } else { | 738 } else { |
732 result = SavePageResult::STORE_FAILURE; | 739 result = SavePageResult::STORE_FAILURE; |
733 } | 740 } |
734 InformSavePageDone(callback, result, offline_page.client_id, | 741 InformSavePageDone(callback, result, offline_page.client_id, |
735 offline_page.offline_id); | 742 offline_page.offline_id); |
736 DeletePendingArchiver(archiver); | 743 DeletePendingArchiver(archiver); |
737 | 744 |
738 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); | 745 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); |
739 } | 746 } |
740 | 747 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 880 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
874 } | 881 } |
875 | 882 |
876 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 883 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
877 const std::vector<int64_t>& offline_ids, | 884 const std::vector<int64_t>& offline_ids, |
878 const DeletePageCallback& callback, | 885 const DeletePageCallback& callback, |
879 bool success) { | 886 bool success) { |
880 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); | 887 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); |
881 | 888 |
882 for (int64_t offline_id : offline_ids) { | 889 for (int64_t offline_id : offline_ids) { |
| 890 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); |
883 auto iter = offline_pages_.find(offline_id); | 891 auto iter = offline_pages_.find(offline_id); |
884 if (iter == offline_pages_.end()) | 892 if (iter == offline_pages_.end()) |
885 continue; | 893 continue; |
886 FOR_EACH_OBSERVER( | 894 FOR_EACH_OBSERVER( |
887 Observer, observers_, | 895 Observer, observers_, |
888 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); | 896 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); |
889 offline_pages_.erase(iter); | 897 offline_pages_.erase(iter); |
890 } | 898 } |
891 | 899 |
892 // Deleting multiple pages always succeeds when it gets to this point. | 900 // Deleting multiple pages always succeeds when it gets to this point. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 DeletePageResult result) { | 980 DeletePageResult result) { |
973 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, | 981 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, |
974 weak_ptr_factory_.GetWeakPtr(), callback)); | 982 weak_ptr_factory_.GetWeakPtr(), callback)); |
975 } | 983 } |
976 | 984 |
977 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( | 985 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( |
978 const base::Closure& callback, | 986 const base::Closure& callback, |
979 bool success) { | 987 bool success) { |
980 DCHECK(success); | 988 DCHECK(success); |
981 if (!success) { | 989 if (!success) { |
| 990 offline_event_logger_.RecordStoreClearError(); |
982 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", | 991 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", |
983 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); | 992 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); |
984 } | 993 } |
985 | 994 |
986 offline_pages_.clear(); | 995 offline_pages_.clear(); |
987 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, | 996 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, |
988 weak_ptr_factory_.GetWeakPtr(), callback)); | 997 weak_ptr_factory_.GetWeakPtr(), callback)); |
989 } | 998 } |
990 | 999 |
991 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( | 1000 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( |
992 const base::Closure& callback, | 1001 const base::Closure& callback, |
993 OfflinePageMetadataStore::LoadStatus load_status, | 1002 OfflinePageMetadataStore::LoadStatus load_status, |
994 const std::vector<OfflinePageItem>& offline_pages) { | 1003 const std::vector<OfflinePageItem>& offline_pages) { |
995 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); | 1004 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); |
996 UMA_HISTOGRAM_ENUMERATION( | 1005 UMA_HISTOGRAM_ENUMERATION( |
997 "OfflinePages.ClearAllStatus2", | 1006 "OfflinePages.ClearAllStatus2", |
998 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED | 1007 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED |
999 ? CLEAR_ALL_SUCCEEDED | 1008 ? CLEAR_ALL_SUCCEEDED |
1000 : STORE_RELOAD_FAILED, | 1009 : STORE_RELOAD_FAILED, |
1001 CLEAR_ALL_STATUS_COUNT); | 1010 CLEAR_ALL_STATUS_COUNT); |
1002 | 1011 |
| 1012 if (load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED) { |
| 1013 offline_event_logger_.RecordStoreCleared(); |
| 1014 } else { |
| 1015 offline_event_logger_.RecordStoreReloadError(); |
| 1016 } |
| 1017 |
1003 CacheLoadedData(offline_pages); | 1018 CacheLoadedData(offline_pages); |
1004 callback.Run(); | 1019 callback.Run(); |
1005 } | 1020 } |
1006 | 1021 |
1007 void OfflinePageModelImpl::CacheLoadedData( | 1022 void OfflinePageModelImpl::CacheLoadedData( |
1008 const std::vector<OfflinePageItem>& offline_pages) { | 1023 const std::vector<OfflinePageItem>& offline_pages) { |
1009 offline_pages_.clear(); | 1024 offline_pages_.clear(); |
1010 for (const auto& offline_page : offline_pages) | 1025 for (const auto& offline_page : offline_pages) |
1011 offline_pages_[offline_page.offline_id] = offline_page; | 1026 offline_pages_[offline_page.offline_id] = offline_page; |
1012 } | 1027 } |
(...skipping 25 matching lines...) Expand all Loading... |
1038 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1053 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
1039 if (!is_loaded_) { | 1054 if (!is_loaded_) { |
1040 delayed_tasks_.push_back(task); | 1055 delayed_tasks_.push_back(task); |
1041 return; | 1056 return; |
1042 } | 1057 } |
1043 | 1058 |
1044 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1059 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1045 } | 1060 } |
1046 | 1061 |
1047 } // namespace offline_pages | 1062 } // namespace offline_pages |
OLD | NEW |