Chromium Code Reviews| 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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 } | 673 } |
| 674 | 674 |
| 675 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { | 675 OfflinePageStorageManager* OfflinePageModelImpl::GetStorageManager() { |
| 676 return storage_manager_.get(); | 676 return storage_manager_.get(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 bool OfflinePageModelImpl::is_loaded() const { | 679 bool OfflinePageModelImpl::is_loaded() const { |
| 680 return is_loaded_; | 680 return is_loaded_; |
| 681 } | 681 } |
| 682 | 682 |
| 683 void OfflinePageModelImpl::GetLogs(std::vector<std::string>& storage_vector) { | |
|
fgorski
2016/06/23 16:34:07
I think a cleaner way would be to expose GetOfflin
chili
2016/06/24 02:45:52
My original thought was that then people can add a
| |
| 684 offline_event_logger_.GetLogs(storage_vector); | |
| 685 } | |
| 686 | |
| 687 void OfflinePageModelImpl::SetIsLogging(bool should_log) { | |
| 688 offline_event_logger_.SetIsLogging(should_log); | |
| 689 } | |
| 690 | |
| 683 void OfflinePageModelImpl::OnCreateArchiveDone(const GURL& requested_url, | 691 void OfflinePageModelImpl::OnCreateArchiveDone(const GURL& requested_url, |
| 684 int64_t offline_id, | 692 int64_t offline_id, |
| 685 const ClientId& client_id, | 693 const ClientId& client_id, |
| 686 const base::Time& start_time, | 694 const base::Time& start_time, |
| 687 const SavePageCallback& callback, | 695 const SavePageCallback& callback, |
| 688 OfflinePageArchiver* archiver, | 696 OfflinePageArchiver* archiver, |
| 689 ArchiverResult archiver_result, | 697 ArchiverResult archiver_result, |
| 690 const GURL& url, | 698 const GURL& url, |
| 691 const base::FilePath& file_path, | 699 const base::FilePath& file_path, |
| 692 int64_t file_size) { | 700 int64_t file_size) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 717 void OfflinePageModelImpl::OnAddOfflinePageDone( | 725 void OfflinePageModelImpl::OnAddOfflinePageDone( |
| 718 OfflinePageArchiver* archiver, | 726 OfflinePageArchiver* archiver, |
| 719 const SavePageCallback& callback, | 727 const SavePageCallback& callback, |
| 720 const OfflinePageItem& offline_page, | 728 const OfflinePageItem& offline_page, |
| 721 bool success) { | 729 bool success) { |
| 722 SavePageResult result; | 730 SavePageResult result; |
| 723 if (success) { | 731 if (success) { |
| 724 offline_pages_[offline_page.offline_id] = offline_page; | 732 offline_pages_[offline_page.offline_id] = offline_page; |
| 725 result = SavePageResult::SUCCESS; | 733 result = SavePageResult::SUCCESS; |
| 726 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)); | |
| 727 } else { | 738 } else { |
| 728 result = SavePageResult::STORE_FAILURE; | 739 result = SavePageResult::STORE_FAILURE; |
| 729 } | 740 } |
| 730 InformSavePageDone(callback, result, offline_page.client_id, | 741 InformSavePageDone(callback, result, offline_page.client_id, |
| 731 offline_page.offline_id); | 742 offline_page.offline_id); |
| 732 DeletePendingArchiver(archiver); | 743 DeletePendingArchiver(archiver); |
| 733 | 744 |
| 734 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); | 745 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); |
| 735 } | 746 } |
| 736 | 747 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 837 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
| 827 } | 838 } |
| 828 | 839 |
| 829 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 840 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
| 830 const std::vector<int64_t>& offline_ids, | 841 const std::vector<int64_t>& offline_ids, |
| 831 const DeletePageCallback& callback, | 842 const DeletePageCallback& callback, |
| 832 bool success) { | 843 bool success) { |
| 833 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); | 844 ReportPageHistogramsAfterDelete(offline_pages_, offline_ids); |
| 834 | 845 |
| 835 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)); | |
| 836 auto iter = offline_pages_.find(offline_id); | 848 auto iter = offline_pages_.find(offline_id); |
| 837 if (iter == offline_pages_.end()) | 849 if (iter == offline_pages_.end()) |
| 838 continue; | 850 continue; |
| 839 FOR_EACH_OBSERVER( | 851 FOR_EACH_OBSERVER( |
| 840 Observer, observers_, | 852 Observer, observers_, |
| 841 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); | 853 OfflinePageDeleted(iter->second.offline_id, iter->second.client_id)); |
| 842 offline_pages_.erase(iter); | 854 offline_pages_.erase(iter); |
| 843 } | 855 } |
| 844 | 856 |
| 845 // 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... | |
| 925 DeletePageResult result) { | 937 DeletePageResult result) { |
| 926 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, | 938 store_->Reset(base::Bind(&OfflinePageModelImpl::OnResetStoreDoneForClearAll, |
| 927 weak_ptr_factory_.GetWeakPtr(), callback)); | 939 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 928 } | 940 } |
| 929 | 941 |
| 930 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( | 942 void OfflinePageModelImpl::OnResetStoreDoneForClearAll( |
| 931 const base::Closure& callback, | 943 const base::Closure& callback, |
| 932 bool success) { | 944 bool success) { |
| 933 DCHECK(success); | 945 DCHECK(success); |
| 934 if (!success) { | 946 if (!success) { |
| 947 offline_event_logger_.RecordStoreClearError(); | |
| 935 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", | 948 UMA_HISTOGRAM_ENUMERATION("OfflinePages.ClearAllStatus2", |
| 936 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); | 949 STORE_RESET_FAILED, CLEAR_ALL_STATUS_COUNT); |
| 937 } | 950 } |
| 938 | 951 |
| 939 offline_pages_.clear(); | 952 offline_pages_.clear(); |
| 940 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, | 953 store_->Load(base::Bind(&OfflinePageModelImpl::OnReloadStoreDoneForClearAll, |
| 941 weak_ptr_factory_.GetWeakPtr(), callback)); | 954 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 942 } | 955 } |
| 943 | 956 |
| 944 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( | 957 void OfflinePageModelImpl::OnReloadStoreDoneForClearAll( |
| 945 const base::Closure& callback, | 958 const base::Closure& callback, |
| 946 OfflinePageMetadataStore::LoadStatus load_status, | 959 OfflinePageMetadataStore::LoadStatus load_status, |
| 947 const std::vector<OfflinePageItem>& offline_pages) { | 960 const std::vector<OfflinePageItem>& offline_pages) { |
| 948 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); | 961 DCHECK_EQ(OfflinePageMetadataStore::LOAD_SUCCEEDED, load_status); |
| 949 UMA_HISTOGRAM_ENUMERATION( | 962 UMA_HISTOGRAM_ENUMERATION( |
| 950 "OfflinePages.ClearAllStatus2", | 963 "OfflinePages.ClearAllStatus2", |
| 951 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED | 964 load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED |
| 952 ? CLEAR_ALL_SUCCEEDED | 965 ? CLEAR_ALL_SUCCEEDED |
| 953 : STORE_RELOAD_FAILED, | 966 : STORE_RELOAD_FAILED, |
| 954 CLEAR_ALL_STATUS_COUNT); | 967 CLEAR_ALL_STATUS_COUNT); |
| 955 | 968 |
| 969 if (load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED) | |
| 970 offline_event_logger_.RecordStoreCleared(); | |
| 971 else | |
| 972 offline_event_logger_.RecordStoreReloadError(); | |
| 973 | |
| 956 CacheLoadedData(offline_pages); | 974 CacheLoadedData(offline_pages); |
| 957 callback.Run(); | 975 callback.Run(); |
| 958 } | 976 } |
| 959 | 977 |
| 960 void OfflinePageModelImpl::CacheLoadedData( | 978 void OfflinePageModelImpl::CacheLoadedData( |
| 961 const std::vector<OfflinePageItem>& offline_pages) { | 979 const std::vector<OfflinePageItem>& offline_pages) { |
| 962 offline_pages_.clear(); | 980 offline_pages_.clear(); |
| 963 for (const auto& offline_page : offline_pages) | 981 for (const auto& offline_page : offline_pages) |
| 964 offline_pages_[offline_page.offline_id] = offline_page; | 982 offline_pages_[offline_page.offline_id] = offline_page; |
| 965 } | 983 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 983 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1001 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 984 if (!is_loaded_) { | 1002 if (!is_loaded_) { |
| 985 delayed_tasks_.push_back(task); | 1003 delayed_tasks_.push_back(task); |
| 986 return; | 1004 return; |
| 987 } | 1005 } |
| 988 | 1006 |
| 989 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1007 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 990 } | 1008 } |
| 991 | 1009 |
| 992 } // namespace offline_pages | 1010 } // namespace offline_pages |
| OLD | NEW |