Chromium Code Reviews| Index: components/offline_pages/offline_page_model_impl.cc |
| diff --git a/components/offline_pages/offline_page_model_impl.cc b/components/offline_pages/offline_page_model_impl.cc |
| index e16d547580b89d4f61dc38ace7730f3bad5a1066..ecd714d54284225e2ff43b27168c3f54c0e395f0 100644 |
| --- a/components/offline_pages/offline_page_model_impl.cc |
| +++ b/components/offline_pages/offline_page_model_impl.cc |
| @@ -305,7 +305,10 @@ void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, |
| // protected |
| OfflinePageModelImpl::OfflinePageModelImpl() |
| - : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} |
| + : OfflinePageModel(), |
| + is_loaded_(false), |
| + store_reset_attempts_left_(3), |
| + weak_ptr_factory_(this) {} |
| OfflinePageModelImpl::OfflinePageModelImpl( |
| std::unique_ptr<OfflinePageMetadataStore> store, |
| @@ -316,6 +319,7 @@ OfflinePageModelImpl::OfflinePageModelImpl( |
| is_loaded_(false), |
| policy_controller_(new ClientPolicyController()), |
| archive_manager_(new ArchiveManager(archives_dir, task_runner)), |
| + store_reset_attempts_left_(3), |
| testing_clock_(nullptr), |
| weak_ptr_factory_(this) { |
| archive_manager_->EnsureArchivesDirCreated( |
| @@ -777,25 +781,35 @@ void OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone( |
| UMA_HISTOGRAM_TIMES("OfflinePages.Model.ArchiveDirCreationTime", |
| base::TimeTicks::Now() - start_time); |
| - store_->GetOfflinePages(base::Bind(&OfflinePageModelImpl::OnLoadDone, |
| - weak_ptr_factory_.GetWeakPtr(), |
| - start_time)); |
| + store_->GetOfflinePages( |
| + base::Bind(&OfflinePageModelImpl::OnGetOfflinePagesDoneForInit, |
| + weak_ptr_factory_.GetWeakPtr(), start_time)); |
| } |
| -void OfflinePageModelImpl::OnLoadDone( |
| +void OfflinePageModelImpl::OnGetOfflinePagesDoneForInit( |
| const base::TimeTicks& start_time, |
| - OfflinePageMetadataStore::LoadStatus load_status, |
| + StoreState store_state, |
| const std::vector<OfflinePageItem>& offline_pages) { |
| DCHECK(!is_loaded_); |
| - is_loaded_ = true; |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "OfflinePages.StoreState", static_cast<int32_t>(store_state), |
| + static_cast<int32_t>(StoreState::STORE_STATE_COUNT)); |
| - // TODO(jianli): rebuild the store upon failure. |
| + if (store_state != StoreState::LOADED) { |
| + DVLOG(1) << "Offline pages database loading failed: " |
| + << static_cast<int32_t>(store_state); |
| + } |
| - if (load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED) |
| - CacheLoadedData(offline_pages); |
| + if (store_state == StoreState::FAILED_LOADING && MaybeResetStore(start_time)) |
| + return; |
| UMA_HISTOGRAM_TIMES("OfflinePages.Model.ConstructionToLoadedEventTime", |
| base::TimeTicks::Now() - start_time); |
| + UMA_HISTOGRAM_COUNTS("OfflinePages.SavedPageCount", |
| + static_cast<int32_t>(offline_pages.size())); |
| + |
| + CacheLoadedData(offline_pages); |
| + is_loaded_ = true; |
| // Create Storage Manager. |
| storage_manager_.reset(new OfflinePageStorageManager( |
| @@ -818,6 +832,39 @@ void OfflinePageModelImpl::OnLoadDone( |
| kStorageManagerStartingDelay); |
| } |
| +bool OfflinePageModelImpl::MaybeResetStore(const base::TimeTicks& start_time) { |
| + if (store_reset_attempts_left_ <= 0) |
| + return false; |
| + |
| + store_reset_attempts_left_--; |
| + store_->Reset(base::Bind(&OfflinePageModelImpl::OnStoreResetDone, |
| + weak_ptr_factory_.GetWeakPtr(), start_time)); |
| + return true; |
| +} |
| + |
| +void OfflinePageModelImpl::OnStoreResetDone(const base::TimeTicks& start_time, |
| + bool reset_success) { |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "OfflinePages.StoreState", static_cast<int32_t>(store_->state()), |
|
Dmitry Titov
2016/11/15 20:23:46
There is also another point of logging same UMA in
|
| + static_cast<int32_t>(StoreState::STORE_STATE_COUNT)); |
| + |
| + if (reset_success) { |
| + store_->GetOfflinePages( |
| + base::Bind(&OfflinePageModelImpl::OnGetOfflinePagesDoneForInit, |
| + weak_ptr_factory_.GetWeakPtr(), start_time)); |
| + return; |
| + } |
| + |
| + if (store_->state() == StoreState::FAILED_RESET && |
| + MaybeResetStore(start_time)) { |
| + return; |
| + } |
| + |
| + // Reset failed enough times. Simply initialize the model with no items. |
| + OnGetOfflinePagesDoneForInit(start_time, store_->state(), |
| + std::vector<OfflinePageItem>()); |
| +} |
| + |
| void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, |
| SavePageResult result, |
| const ClientId& client_id, |