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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 837 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
831 } | 838 } |
832 | 839 |
833 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 840 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
834 const std::vector<int64_t>& offline_ids, | 841 const std::vector<int64_t>& offline_ids, |
835 const DeletePageCallback& callback, | 842 const DeletePageCallback& callback, |
836 bool success) { | 843 bool success) { |
837 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); | 844 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); |
838 | 845 |
839 for (int64_t offline_id : offline_ids) { | 846 for (int64_t offline_id : offline_ids) { |
| 847 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); |
840 auto iter = offline_pages_.find(offline_id); | 848 auto iter = offline_pages_.find(offline_id); |
841 if (iter == offline_pages_.end()) | 849 if (iter == offline_pages_.end()) |
842 continue; | 850 continue; |
843 FOR_EACH_OBSERVER( | 851 FOR_EACH_OBSERVER( |
844 Observer, observers_, | 852 Observer, observers_, |
845 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); | 853 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); |
846 offline_pages_.erase(iter); | 854 offline_pages_.erase(iter); |
847 } | 855 } |
848 | 856 |
849 // Deleting multiple pages always succeeds when it gets to this point. | 857 // Deleting multiple pages always succeeds when it gets to this point. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 DeletePageResult result) { | 937 DeletePageResult result) { |
930 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, | 938 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, |
931 weak_ptr_factory_.GetWeakPtr(), callback)); | 939 weak_ptr_factory_.GetWeakPtr(), callback)); |
932 } | 940 } |
933 | 941 |
934 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( | 942 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( |
935 const base::Closure& callback, | 943 const base::Closure& callback, |
936 bool success) { | 944 bool success) { |
937 DCHECK(success); | 945 DCHECK(success); |
938 if (!success) { | 946 if (!success) { |
| 947 offline_event_logger_.RecordStoreClearError(); |
939 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", | 948 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", |
940 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); | 949 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); |
941 } | 950 } |
942 | 951 |
943 offline_pages_.clear(); | 952 offline_pages_.clear(); |
944 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, | 953 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, |
945 weak_ptr_factory_.GetWeakPtr(), callback)); | 954 weak_ptr_factory_.GetWeakPtr(), callback)); |
946 } | 955 } |
947 | 956 |
948 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( | 957 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( |
949 const base::Closure& callback, | 958 const base::Closure& callback, |
950 OfflinePageMetadataStore::LoadStatus load_status, | 959 OfflinePageMetadataStore::LoadStatus load_status, |
951 const std::vector<OfflinePageItem>& offline_pages) { | 960 const std::vector<OfflinePageItem>& offline_pages) { |
952 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); | 961 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); |
953 UMA_HISTOGRAM_ENUMERATION( | 962 UMA_HISTOGRAM_ENUMERATION( |
954 "OfflinePages.ClearAllStatus2", | 963 "OfflinePages.ClearAllStatus2", |
955 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED | 964 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED |
956 ? CLEAR_ALL_SUCCEEDED | 965 ? CLEAR_ALL_SUCCEEDED |
957 : STORE_RELOAD_FAILED, | 966 : STORE_RELOAD_FAILED, |
958 CLEAR_ALL_STATUS_COUNT); | 967 CLEAR_ALL_STATUS_COUNT); |
959 | 968 |
| 969 if (load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED) |
| 970 offline_event_logger_.RecordStoreCleared(); |
| 971 else |
| 972 offline_event_logger_.RecordStoreReloadError(); |
| 973 |
960 CacheLoadedData(offline_pages); | 974 CacheLoadedData(offline_pages); |
961 callback.Run(); | 975 callback.Run(); |
962 } | 976 } |
963 | 977 |
964 void OfflinePageModelImpl::CacheLoadedData( | 978 void OfflinePageModelImpl::CacheLoadedData( |
965 const std::vector<OfflinePageItem>& offline_pages) { | 979 const std::vector<OfflinePageItem>& offline_pages) { |
966 offline_pages_.clear(); | 980 offline_pages_.clear(); |
967 for (const auto& offline_page : offline_pages) | 981 for (const auto& offline_page : offline_pages) |
968 offline_pages_[offline_page.offline_id] = offline_page; | 982 offline_pages_[offline_page.offline_id] = offline_page; |
969 } | 983 } |
(...skipping 17 matching lines...) Expand all Loading... |
987 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1001 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
988 if (!is_loaded_) { | 1002 if (!is_loaded_) { |
989 delayed_tasks_.push_back(task); | 1003 delayed_tasks_.push_back(task); |
990 return; | 1004 return; |
991 } | 1005 } |
992 | 1006 |
993 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1007 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
994 } | 1008 } |
995 | 1009 |
996 } // namespace offline_pages | 1010 } // namespace offline_pages |
OLD | NEW |