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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..48d1655b0895cad1ea3b0801858b99fe63f3746d |
--- /dev/null |
+++ b/chrome/browser/background_fetch/background_fetch_client_impl.cc |
@@ -0,0 +1,115 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <string> |
+ |
+#include "chrome/browser/background_fetch/background_fetch_client_impl.h" |
+ |
+#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "components/offline_items_collection/core/offline_content_aggregator.h" |
+#include "components/offline_items_collection/core/offline_item.h" |
+ |
+namespace { |
+ |
+const char kBackgroundFetchNamespace[] = "BackgroundFetchNamespace"; |
+ |
+} // namespace |
+ |
+BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile) |
+ : profile_(profile) { |
+ DCHECK(profile_); |
+ offline_items_collection::OfflineContentAggregator* aggregator = |
Peter Beverloo
2017/03/31 01:32:22
Could we have an GetAggregator() helper method tha
Peter Beverloo
2017/03/31 01:32:22
`using` declarations are allowed in .cc files, so
harkness
2017/03/31 10:11:43
It would only be called twice. I thought Chromium
harkness
2017/03/31 10:11:43
Done.
Peter Beverloo
2017/03/31 11:54:06
Fair enough.
|
+ offline_items_collection::OfflineContentAggregatorFactory:: |
+ GetForBrowserContext(profile_); |
+ if (!aggregator) |
+ return; |
+ aggregator->RegisterProvider(kBackgroundFetchNamespace, this); |
+} |
+ |
+BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default; |
+ |
+void BackgroundFetchClientImpl::Shutdown() { |
+ offline_items_collection::OfflineContentAggregator* aggregator = |
+ offline_items_collection::OfflineContentAggregatorFactory:: |
+ GetForBrowserContext(profile_); |
+ if (!aggregator) |
+ return; |
+ aggregator->UnregisterProvider(kBackgroundFetchNamespace); |
+} |
+ |
+void BackgroundFetchClientImpl::SetDelegate( |
+ content::BackgroundFetchClient::Delegate* delegate) { |
+ delegate_ = delegate; |
+} |
+ |
+void BackgroundFetchClientImpl::CancelDownload( |
+ const offline_items_collection::ContentId& content_id) { |
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); |
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->CancelDownload(content_id.id); |
+} |
+ |
+void BackgroundFetchClientImpl::PauseDownload( |
+ const offline_items_collection::ContentId& content_id) { |
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); |
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->PauseDownload(content_id.id); |
+} |
+ |
+void BackgroundFetchClientImpl::ResumeDownload( |
+ const offline_items_collection::ContentId& content_id) { |
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); |
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->ResumeDownload(content_id.id); |
+} |
+ |
+void BackgroundFetchClientImpl::OpenItem( |
+ const offline_items_collection::ContentId& content_id) { |
+ // TODO(harkness): Add another call to BackgroundFetchClient::Delegate and |
+ // plumb this to 'onclickevent' to the ServiceWorker. |
+} |
+ |
+void BackgroundFetchClientImpl::AddObserver(Observer* observer) { |
+ // TODO(harkness): Add a path for the OfflineContentProvider to observe |
+ // changes in available BackgroundFetch items. |
+} |
+ |
+void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} |
+ |
+bool BackgroundFetchClientImpl::AreItemsAvailable() { |
+ // This call has no meaning for BackgroundFetch, since items will be removed |
+ // from the offline content listing as soon as the fetch is complete. |
Peter Beverloo
2017/03/31 01:32:22
Yes, but the OIC may maintain a cache of its own.
harkness
2017/03/31 10:11:43
Updated to be a TODO.
|
+ return false; |
+} |
+ |
+void BackgroundFetchClientImpl::RemoveItem( |
+ const offline_items_collection::ContentId& content_id) { |
+ // This call has no meaning for BackgroundFetch, since items will be removed |
+ // from the offline content listing as soon as the fetch is complete. |
+} |
+ |
+const offline_items_collection::OfflineItem* |
+BackgroundFetchClientImpl::GetItemById( |
+ const offline_items_collection::ContentId& content_id) { |
+ // This call has no meaning for BackgroundFetch, since items will be removed |
+ // from the offline content listing as soon as the fetch is complete. |
+ return nullptr; |
+} |
+ |
+offline_items_collection::OfflineContentProvider::OfflineItemList |
+BackgroundFetchClientImpl::GetAllItems() { |
+ // This call has no meaning for BackgroundFetch, since items will be removed |
+ // from the offline content listing as soon as the fetch is complete. |
+ return offline_items_collection::OfflineContentProvider::OfflineItemList(); |
+} |