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

Side by Side Diff: chrome/browser/background_fetch/background_fetch_client_impl.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Code review comments 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "chrome/browser/background_fetch/background_fetch_client_impl.h"
8
9 #include "chrome/browser/offline_items_collection/offline_content_aggregator_fac tory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/offline_items_collection/core/offline_content_aggregator.h"
12 #include "components/offline_items_collection/core/offline_item.h"
13
14 namespace {
15
16 const char kBackgroundFetchNamespace[] = "BackgroundFetchNamespace";
17
18 } // namespace
19
20 using offline_items_collection::ContentId;
21 using offline_items_collection::OfflineContentAggregator;
22 using offline_items_collection::OfflineContentAggregatorFactory;
23 using offline_items_collection::OfflineContentProvider;
24 using offline_items_collection::OfflineItem;
25
26 BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile)
27 : profile_(profile) {
28 DCHECK(profile_);
29 OfflineContentAggregator* aggregator =
30 OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
31 if (!aggregator)
32 return;
33 aggregator->RegisterProvider(kBackgroundFetchNamespace, this);
34 }
35
36 BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default;
37
38 void BackgroundFetchClientImpl::Shutdown() {
39 OfflineContentAggregator* aggregator =
40 OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
41 if (!aggregator)
42 return;
43 aggregator->UnregisterProvider(kBackgroundFetchNamespace);
44 }
45
46 void BackgroundFetchClientImpl::SetDelegate(
47 content::BackgroundFetchClient::Delegate* delegate) {
48 delegate_ = delegate;
49 }
50
51 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) {
52 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
53
54 if (!delegate_)
55 return;
56
57 delegate_->CancelDownload(content_id.id);
58 }
59
60 void BackgroundFetchClientImpl::PauseDownload(const ContentId& content_id) {
61 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
62
63 if (!delegate_)
64 return;
65
66 delegate_->PauseDownload(content_id.id);
67 }
68
69 void BackgroundFetchClientImpl::ResumeDownload(const ContentId& content_id) {
70 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace);
71
72 if (!delegate_)
73 return;
74
75 delegate_->ResumeDownload(content_id.id);
76 }
77
78 void BackgroundFetchClientImpl::OpenItem(const ContentId& content_id) {
79 // TODO(harkness): Add another call to BackgroundFetchClient::Delegate and
80 // plumb this to 'onclickevent' to the ServiceWorker.
81 }
82
83 void BackgroundFetchClientImpl::AddObserver(Observer* observer) {
84 // TODO(harkness): Add a path for the OfflineContentProvider to observe
85 // changes in available BackgroundFetch items.
86 }
87
88 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {}
89
90 bool BackgroundFetchClientImpl::AreItemsAvailable() {
91 // TODO(harkness): Follow up with dtrainor about what action to take for this.
92 return false;
93 }
94
95 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) {
96 // TODO(harkness): Follow up with dtrainor about what action to take for this.
97 }
98
99 const OfflineItem* BackgroundFetchClientImpl::GetItemById(
100 const ContentId& content_id) {
101 // TODO(harkness): Follow up with dtrainor about what action to take for this.
102 return nullptr;
103 }
104
105 OfflineContentProvider::OfflineItemList
106 BackgroundFetchClientImpl::GetAllItems() {
107 // TODO(harkness): Follow up with dtrainor about what action to take for this.
108 return OfflineContentProvider::OfflineItemList();
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698