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

Unified Diff: chrome/browser/background_fetch/background_fetch_client_impl.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Add GetVisualsForItem support Created 3 years, 8 months 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
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..d438976ad18709706970019136b341d8d0f2e934
--- /dev/null
+++ b/chrome/browser/background_fetch/background_fetch_client_impl.cc
@@ -0,0 +1,129 @@
+// 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 <sstream>
+#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
+
+using offline_items_collection::ContentId;
+using offline_items_collection::OfflineContentAggregator;
+using offline_items_collection::OfflineContentAggregatorFactory;
+using offline_items_collection::OfflineContentProvider;
+using offline_items_collection::OfflineItem;
+
+BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile)
+ : profile_(profile), registered_namespace_name_(kBackgroundFetchNamespace) {
Peter Beverloo 2017/04/18 23:12:08 optional nit: I'd s/registered_namespace_name_/nam
harkness 2017/04/19 09:03:40 Done.
+ DCHECK(profile_);
+ if (profile->IsOffTheRecord()) {
+ std::ostringstream suffix;
+ suffix << "Incognito" << this;
Peter Beverloo 2017/04/18 23:12:08 This needs a comment to explain what's going on he
harkness 2017/04/19 09:03:41 Done.
+ registered_namespace_name_ += suffix.str();
David Trainor- moved to gerrit 2017/04/18 22:15:55 I think this will work with the UI. The UI tracks
harkness 2017/04/19 09:03:41 Acknowledged.
+ }
+
+ OfflineContentAggregator* aggregator =
+ OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
+ if (!aggregator)
+ return;
+ aggregator->RegisterProvider(registered_namespace_name_, this);
+}
+
+BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default;
+
+void BackgroundFetchClientImpl::Shutdown() {
+ OfflineContentAggregator* aggregator =
+ OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
+ if (!aggregator)
+ return;
+
+ aggregator->UnregisterProvider(registered_namespace_name_);
+
+ // If the profile is an incognito profile, clean up all data.
+ if (delegate_ &&
+ registered_namespace_name_.compare(kBackgroundFetchNamespace))
Peter Beverloo 2017/04/18 23:12:08 Just use operator==. Adding an IsIncognito() helpe
harkness 2017/04/19 09:03:40 Updated to use ==, but since it's the only place i
+ delegate_->CleanupAllTasks();
+}
+
+void BackgroundFetchClientImpl::SetDelegate(
+ content::BackgroundFetchClient::Delegate* delegate) {
+ delegate_ = delegate;
+}
+
+void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) {
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
Peter Beverloo 2017/04/18 23:12:08 But these are not correct anymore, right? We need
harkness 2017/04/19 09:03:40 Good catch, I totally overlooked this. Done.
+
+ if (!delegate_)
+ return;
+
+ delegate_->CancelDownload(content_id.id);
+}
+
+void BackgroundFetchClientImpl::PauseDownload(const ContentId& content_id) {
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
+
+ if (!delegate_)
+ return;
+
+ delegate_->PauseDownload(content_id.id);
+}
+
+void BackgroundFetchClientImpl::ResumeDownload(const ContentId& content_id) {
+ DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
+
+ if (!delegate_)
+ return;
+
+ delegate_->ResumeDownload(content_id.id);
+}
+
+void BackgroundFetchClientImpl::OpenItem(const ContentId& content_id) {
+ // TODO(harkness): Add another call to BackgroundFetchClient::Delegate and
+ // plumb this to 'onclickevent' to the ServiceWorker.
+}
+
+void BackgroundFetchClientImpl::GetVisualsForItem(
+ const ContentId& id,
+ const VisualsCallback& callback) {
David Trainor- moved to gerrit 2017/04/18 22:15:55 We cache the icons in the Java layer for now. Not
Peter Beverloo 2017/04/18 23:12:08 I guess we should add the following then (until ic
harkness 2017/04/19 09:03:40 The second argument is a const OfflineItemVisuals*
harkness 2017/04/19 09:03:41 Acknowledged.
+ // TODO(harkness): Either cache the icons here or call into the delegate to
+ // get the icons.
+}
+
+void BackgroundFetchClientImpl::AddObserver(Observer* observer) {
+ // TODO(harkness): Add a path for the OfflineContentProvider to observe
David Trainor- moved to gerrit 2017/04/18 22:15:55 Save an base::ObserverList<> of the observers and
harkness 2017/04/19 09:03:40 I'm going to do this and the other observer calls
David Trainor- moved to gerrit 2017/04/19 22:45:12 Acknowledged.
+ // changes in available BackgroundFetch items.
+}
+
+void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {}
+
+bool BackgroundFetchClientImpl::AreItemsAvailable() {
+ // TODO(harkness): Follow up with dtrainor about what action to take for this.
David Trainor- moved to gerrit 2017/04/18 22:15:55 When it's possible to talk to your delegate_, this
harkness 2017/04/19 09:03:40 Acknowledged.
+ return false;
+}
+
+void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) {
+ // TODO(harkness): Follow up with dtrainor about what action to take for this.
David Trainor- moved to gerrit 2017/04/18 22:15:55 N/A for your case probably, since the item shouldn
harkness 2017/04/19 09:03:41 Done.
+}
+
+const OfflineItem* BackgroundFetchClientImpl::GetItemById(
+ const ContentId& content_id) {
+ // TODO(harkness): Follow up with dtrainor about what action to take for this.
David Trainor- moved to gerrit 2017/04/18 22:15:55 Return the OfflineItem that represents the backgro
harkness 2017/04/19 09:03:40 Acknowledged.
+ return nullptr;
+}
+
+OfflineContentProvider::OfflineItemList
+BackgroundFetchClientImpl::GetAllItems() {
+ // TODO(harkness): Follow up with dtrainor about what action to take for this.
+ return OfflineContentProvider::OfflineItemList();
+}

Powered by Google App Engine
This is Rietveld 408576698