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

Unified Diff: components/offline_pages/offline_page_model.cc

Issue 1487913002: [Offline pages] Fixing crashes caused by access to offline pages marked for deletion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/offline_page_model.cc
diff --git a/components/offline_pages/offline_page_model.cc b/components/offline_pages/offline_page_model.cc
index 242ade295c21c5ffb70575f1147708045042b194..60a9b2e4a01cc2f1edbdf8730bc85b5944df228e 100644
--- a/components/offline_pages/offline_page_model.cc
+++ b/components/offline_pages/offline_page_model.cc
@@ -253,7 +253,13 @@ void OfflinePageModel::ClearAll(const base::Closure& callback) {
bool OfflinePageModel::HasOfflinePages() const {
DCHECK(is_loaded_);
- return !offline_pages_.empty();
+ // Check that at least one page is not marked for deletion. Because we have
+ // pages marked for deletion, we cannot simply invert result of |empty()|.
+ for (const auto& id_page_pair : offline_pages_) {
+ if (!id_page_pair.second.IsMarkedForDeletion())
+ return true;
+ }
+ return false;
}
const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const {
@@ -283,7 +289,9 @@ const std::vector<OfflinePageItem> OfflinePageModel::GetPagesToCleanUp() const {
const OfflinePageItem* OfflinePageModel::GetPageByBookmarkId(
int64 bookmark_id) const {
const auto iter = offline_pages_.find(bookmark_id);
- return iter != offline_pages_.end() ? &(iter->second) : nullptr;
+ return iter != offline_pages_.end() && !iter->second.IsMarkedForDeletion()
+ ? &(iter->second)
+ : nullptr;
}
const OfflinePageItem* OfflinePageModel::GetPageByOfflineURL(
@@ -291,8 +299,10 @@ const OfflinePageItem* OfflinePageModel::GetPageByOfflineURL(
for (auto iter = offline_pages_.begin();
iter != offline_pages_.end();
++iter) {
- if (iter->second.GetOfflineURL() == offline_url)
+ if (iter->second.GetOfflineURL() == offline_url &&
+ !iter->second.IsMarkedForDeletion()) {
return &(iter->second);
+ }
}
return nullptr;
}
@@ -301,7 +311,7 @@ const OfflinePageItem* OfflinePageModel::GetPageByOnlineURL(
const GURL& online_url) const {
for (auto iter = offline_pages_.begin(); iter != offline_pages_.end();
++iter) {
- if (iter->second.url == online_url)
+ if (iter->second.url == online_url && !iter->second.IsMarkedForDeletion())
return &(iter->second);
}
return nullptr;
« no previous file with comments | « no previous file | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698