Chromium Code Reviews| Index: chrome/browser/background_fetch/background_fetch_client_impl.cc |
| diff --git a/chrome/browser/background_fetch/background_fetch_client_impl.cc b/chrome/browser/background_fetch/background_fetch_client_impl.cc |
| index ae1cef10842c192251d0a538b4c239882a75446b..273fcd01f80a76385d7ec2ae7c6a2439a4ddff22 100644 |
| --- a/chrome/browser/background_fetch/background_fetch_client_impl.cc |
| +++ b/chrome/browser/background_fetch/background_fetch_client_impl.cc |
| @@ -60,6 +60,39 @@ void BackgroundFetchClientImpl::Shutdown() { |
| void BackgroundFetchClientImpl::SetDelegate( |
| content::BackgroundFetchClient::Delegate* delegate) { |
| delegate_ = delegate; |
| + |
| + // If there are any previously registered observers, notify them now. |
| + for (auto& observer : observers_) |
| + observer.OnItemsAvailable(this); |
| +} |
| + |
| +void BackgroundFetchClientImpl::AddDownload(const GURL& url, |
| + const std::string& registration_id, |
| + const std::string& title, |
| + int64_t total_download_size) { |
| + // Construct an OfflineItem to pass to the Observers. |
| + OfflineItem item(ContentId(namespace_, registration_id)); |
| + item.title = title; |
| + item.is_transient = true; |
| + item.total_size_bytes = total_download_size; |
| + item.is_openable = false; |
| + // Set the origin of the service worker as the url for attribution. |
| + item.page_url = url; |
| + item.is_off_the_record = profile_->IsOffTheRecord(); |
| + item.state = offline_items_collection::OfflineItemState::IN_PROGRESS; |
| + item.is_resumable = true; |
| + item.allow_metered = false; |
| + item.received_bytes = 0; |
| + item.percent_completed = 0; |
| + item.time_remaining_ms = -1; |
| + // TODO(harkness): Should BackgroundFetch set a description or filter? |
| + // TODO(harkness): Should BackgroundFetch expose creation/access times? |
| + |
| + OfflineContentProvider::OfflineItemList added_items; |
|
Peter Beverloo
2017/04/24 14:39:15
; -> {item};
|
| + added_items.push_back(item); |
| + |
| + for (auto& observer : observers_) |
| + observer.OnItemsAdded(added_items); |
| } |
| void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) { |
| @@ -102,15 +135,25 @@ void BackgroundFetchClientImpl::GetVisualsForItem( |
| } |
| void BackgroundFetchClientImpl::AddObserver(Observer* observer) { |
| - // TODO(harkness): Add a path for the OfflineContentProvider to observe |
| - // changes in available BackgroundFetch items. |
| + DCHECK(observer); |
| + observers_.AddObserver(observer); |
| + |
| + // If the Delegate has been set then it is assumed to be ready for queries. |
| + if (delegate_) |
| + observer->OnItemsAvailable(this); |
|
David Trainor- moved to gerrit
2017/04/25 03:24:43
Could we post this?
|
| } |
| -void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} |
| +void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) { |
| + DCHECK(observer); |
| + if (!observers_.HasObserver(observer)) |
| + return; |
| + |
| + observers_.RemoveObserver(observer); |
| +} |
| bool BackgroundFetchClientImpl::AreItemsAvailable() { |
| - // TODO(harkness): Follow up with dtrainor about what action to take for this. |
| - return false; |
| + // If there is a delegate, it is assumed to be ready for query. |
| + return delegate_; |
| } |
| void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) { |