Commit 3c54e2a8 authored by olivierrobin's avatar olivierrobin Committed by Commit bot

Only distill unread items

BUG=672774

Review-Url: https://codereview.chromium.org/2565753002
Cr-Commit-Position: refs/heads/master@{#437534}
parent 00af5e1d
...@@ -170,8 +170,11 @@ ReadingListEntry* ReadingListModelImpl::SyncMergeEntry( ...@@ -170,8 +170,11 @@ ReadingListEntry* ReadingListModelImpl::SyncMergeEntry(
} else { } else {
unread_entry_count_++; unread_entry_count_++;
} }
for (auto& observer : observers_) for (auto& observer : observers_) {
observer.ReadingListDidMoveEntry(this, url);
observer.ReadingListDidApplyChanges(this); observer.ReadingListDidApplyChanges(this);
}
return existing_entry; return existing_entry;
} }
...@@ -263,6 +266,7 @@ void ReadingListModelImpl::SetReadStatus(const GURL& url, bool read) { ...@@ -263,6 +266,7 @@ void ReadingListModelImpl::SetReadStatus(const GURL& url, bool read) {
storage_layer_->SaveEntry(entry); storage_layer_->SaveEntry(entry);
} }
for (ReadingListModelObserver& observer : observers_) { for (ReadingListModelObserver& observer : observers_) {
observer.ReadingListDidMoveEntry(this, url);
observer.ReadingListDidApplyChanges(this); observer.ReadingListDidApplyChanges(this);
} }
} }
......
...@@ -45,6 +45,12 @@ class ReadingListModelObserver { ...@@ -45,6 +45,12 @@ class ReadingListModelObserver {
virtual void ReadingListWillMoveEntry(const ReadingListModel* model, virtual void ReadingListWillMoveEntry(const ReadingListModel* model,
const GURL& url) {} const GURL& url) {}
// Invoked when elements |MarkEntryUpdated| has been called on an entry. This
// means that the order of the entry may have changed and read/unread list may
// have changed too.
virtual void ReadingListDidMoveEntry(const ReadingListModel* model,
const GURL& url) {}
// Invoked when elements are added. // Invoked when elements are added.
virtual void ReadingListWillAddEntry(const ReadingListModel* model, virtual void ReadingListWillAddEntry(const ReadingListModel* model,
const ReadingListEntry& entry) {} const ReadingListEntry& entry) {}
......
...@@ -84,7 +84,23 @@ void ReadingListDownloadService::ReadingListDidAddEntry( ...@@ -84,7 +84,23 @@ void ReadingListDownloadService::ReadingListDidAddEntry(
const ReadingListModel* model, const ReadingListModel* model,
const GURL& url) { const GURL& url) {
DCHECK_EQ(reading_list_model_, model); DCHECK_EQ(reading_list_model_, model);
ScheduleDownloadEntry(url); ProcessNewEntry(url);
}
void ReadingListDownloadService::ReadingListDidMoveEntry(
const ReadingListModel* model,
const GURL& url) {
DCHECK_EQ(reading_list_model_, model);
ProcessNewEntry(url);
}
void ReadingListDownloadService::ProcessNewEntry(const GURL& url) {
const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
if (!entry || entry->IsRead()) {
url_downloader_->CancelDownloadOfflineURL(url);
} else {
ScheduleDownloadEntry(url);
}
} }
void ReadingListDownloadService::DownloadAllEntries() { void ReadingListDownloadService::DownloadAllEntries() {
...@@ -98,7 +114,7 @@ void ReadingListDownloadService::ScheduleDownloadEntry(const GURL& url) { ...@@ -98,7 +114,7 @@ void ReadingListDownloadService::ScheduleDownloadEntry(const GURL& url) {
DCHECK(reading_list_model_->loaded()); DCHECK(reading_list_model_->loaded());
const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
if (!entry || entry->DistilledState() == ReadingListEntry::ERROR || if (!entry || entry->DistilledState() == ReadingListEntry::ERROR ||
entry->DistilledState() == ReadingListEntry::PROCESSED) entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead())
return; return;
GURL local_url(url); GURL local_url(url);
web::WebThread::PostDelayedTask( web::WebThread::PostDelayedTask(
...@@ -112,7 +128,7 @@ void ReadingListDownloadService::DownloadEntry(const GURL& url) { ...@@ -112,7 +128,7 @@ void ReadingListDownloadService::DownloadEntry(const GURL& url) {
DCHECK(reading_list_model_->loaded()); DCHECK(reading_list_model_->loaded());
const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url);
if (!entry || entry->DistilledState() == ReadingListEntry::ERROR || if (!entry || entry->DistilledState() == ReadingListEntry::ERROR ||
entry->DistilledState() == ReadingListEntry::PROCESSED) entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead())
return; return;
if (net::NetworkChangeNotifier::IsOffline()) { if (net::NetworkChangeNotifier::IsOffline()) {
......
...@@ -50,11 +50,15 @@ class ReadingListDownloadService ...@@ -50,11 +50,15 @@ class ReadingListDownloadService
const GURL& url) override; const GURL& url) override;
void ReadingListDidAddEntry(const ReadingListModel* model, void ReadingListDidAddEntry(const ReadingListModel* model,
const GURL& url) override; const GURL& url) override;
void ReadingListDidMoveEntry(const ReadingListModel* model,
const GURL& url) override;
private: private:
// Tries to save offline versions of all entries in the reading list that are // Tries to save offline versions of all entries in the reading list that are
// not yet saved. Must only be called after reading list model is loaded. // not yet saved. Must only be called after reading list model is loaded.
void DownloadAllEntries(); void DownloadAllEntries();
// Processes a new entry and schedule a download if needed.
void ProcessNewEntry(const GURL& url);
// Schedule a download of an offline version of the reading list entry, // Schedule a download of an offline version of the reading list entry,
// according to the delay of the entry. Must only be called after reading list // according to the delay of the entry. Must only be called after reading list
// model is loaded. // model is loaded.
......
...@@ -50,9 +50,7 @@ void URLDownloader::OfflineURLExists(const GURL& url, ...@@ -50,9 +50,7 @@ void URLDownloader::OfflineURLExists(const GURL& url,
void URLDownloader::RemoveOfflineURL(const GURL& url) { void URLDownloader::RemoveOfflineURL(const GURL& url) {
// Remove all download tasks for this url as it would be pointless work. // Remove all download tasks for this url as it would be pointless work.
tasks_.erase( CancelDownloadOfflineURL(url);
std::remove(tasks_.begin(), tasks_.end(), std::make_pair(DOWNLOAD, url)),
tasks_.end());
tasks_.push_back(std::make_pair(DELETE, url)); tasks_.push_back(std::make_pair(DELETE, url));
HandleNextTask(); HandleNextTask();
} }
...@@ -65,6 +63,12 @@ void URLDownloader::DownloadOfflineURL(const GURL& url) { ...@@ -65,6 +63,12 @@ void URLDownloader::DownloadOfflineURL(const GURL& url) {
} }
} }
void URLDownloader::CancelDownloadOfflineURL(const GURL& url) {
tasks_.erase(
std::remove(tasks_.begin(), tasks_.end(), std::make_pair(DOWNLOAD, url)),
tasks_.end());
}
void URLDownloader::DownloadCompletionHandler(const GURL& url, void URLDownloader::DownloadCompletionHandler(const GURL& url,
const std::string& title, const std::string& title,
SuccessState success) { SuccessState success) {
......
...@@ -68,6 +68,9 @@ class URLDownloader { ...@@ -68,6 +68,9 @@ class URLDownloader {
// Asynchronously download an offline version of the URL. // Asynchronously download an offline version of the URL.
void DownloadOfflineURL(const GURL& url); void DownloadOfflineURL(const GURL& url);
// Cancels the download job an offline version of the URL.
void CancelDownloadOfflineURL(const GURL& url);
// Asynchronously remove the offline version of the URL if it exists. // Asynchronously remove the offline version of the URL if it exists.
void RemoveOfflineURL(const GURL& url); void RemoveOfflineURL(const GURL& url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment