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..764bfd9dfaeefc09dd40dd7463788c777d83022d |
--- /dev/null |
+++ b/chrome/browser/background_fetch/background_fetch_client_impl.cc |
@@ -0,0 +1,94 @@ |
+// 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 kBackgroundFetchProvider[] = "BackgroundFetchProvider"; |
Peter Beverloo
2017/03/29 14:32:12
Please check with David to see what sort of string
harkness
2017/03/30 12:42:35
Done.
|
+ |
+} // namespace |
+ |
+BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile) |
+ : profile_(profile) { |
+ DCHECK(profile_); |
+ offline_items_collection::OfflineContentAggregator* aggregator = |
+ offline_items_collection::OfflineContentAggregatorFactory:: |
+ GetForBrowserContext(profile_); |
+ if (!aggregator) |
+ return; |
+ aggregator->RegisterProvider(kBackgroundFetchProvider, this); |
+} |
+ |
+BackgroundFetchClientImpl::~BackgroundFetchClientImpl() { |
+ offline_items_collection::OfflineContentAggregator* aggregator = |
+ offline_items_collection::OfflineContentAggregatorFactory:: |
+ GetForBrowserContext(profile_); |
+ if (!aggregator) |
+ return; |
+ aggregator->UnregisterProvider(kBackgroundFetchProvider); |
+} |
+ |
+void BackgroundFetchClientImpl::SetDelegate( |
+ content::BackgroundFetchDelegate* delegate) { |
+ delegate_ = delegate; |
+} |
+ |
+content::BackgroundFetchDelegate* BackgroundFetchClientImpl::GetDelegate() |
+ const { |
+ return delegate_; |
+} |
+ |
+void BackgroundFetchClientImpl::CancelDownload(const ContentId& id) { |
+ if (id.name_space != kBackgroundFetchProvider) |
+ return; |
Peter Beverloo
2017/03/29 14:59:49
These should be DCHECK_EQs. (The OCA only forwards
harkness
2017/03/30 12:42:34
Done.
|
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->CancelDownload(id.id); |
Peter Beverloo
2017/03/29 14:32:12
I realize this will make it even longer, but unles
harkness
2017/03/30 12:42:34
Done.
|
+} |
+ |
+void BackgroundFetchClientImpl::PauseDownload(const ContentId& id) { |
+ if (id.name_space != kBackgroundFetchProvider) |
+ return; |
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->PauseDownload(id.id); |
+} |
+ |
+void BackgroundFetchClientImpl::ResumeDownload(const ContentId& id) { |
+ if (id.name_space != kBackgroundFetchProvider) |
+ return; |
+ |
+ if (!delegate_) |
+ return; |
+ |
+ delegate_->ResumeDownload(id.id); |
+} |
+ |
+// Not yet implemented. |
Peter Beverloo
2017/03/29 14:32:12
Will this be included in this CL? It would still b
harkness
2017/03/30 12:42:34
Done.
|
+bool BackgroundFetchClientImpl::AreItemsAvailable() { |
+ return false; |
+} |
Peter Beverloo
2017/03/29 14:32:12
micro nit: blank lines between the methods
harkness
2017/03/30 12:42:35
Done.
|
+void BackgroundFetchClientImpl::OpenItem(const ContentId& id) {} |
+void BackgroundFetchClientImpl::RemoveItem(const ContentId& id) {} |
+void BackgroundFetchClientImpl::AddObserver(Observer* observer) {} |
+void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} |
+const OfflineItem* BackgroundFetchClientImpl::GetItemById(const ContentId& id) { |
+ return nullptr; |
+} |
+OfflineContentProvider::OfflineItemList |
+BackgroundFetchClientImpl::GetAllItems() { |
+ return OfflineContentProvider::OfflineItemList(); |
+} |