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

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

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Fixed incognito check and added tests 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 <sstream>
6 #include <string>
7
8 #include "chrome/browser/background_fetch/background_fetch_client_impl.h"
9
10 #include "chrome/browser/offline_items_collection/offline_content_aggregator_fac tory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "components/offline_items_collection/core/offline_content_aggregator.h"
13 #include "components/offline_items_collection/core/offline_item.h"
14
15 namespace {
16
17 const char kBackgroundFetchNamespace[] = "BackgroundFetchNamespace";
18
19 } // namespace
20
21 using offline_items_collection::ContentId;
22 using offline_items_collection::OfflineContentAggregator;
23 using offline_items_collection::OfflineContentAggregatorFactory;
24 using offline_items_collection::OfflineContentProvider;
25 using offline_items_collection::OfflineItem;
26
27 BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile)
28 : profile_(profile), namespace_(kBackgroundFetchNamespace) {
29 DCHECK(profile_);
30 if (profile->IsOffTheRecord()) {
31 // There can be multiple incognito namespaces, so append the memory address
32 // of this client to provide a guaranteed unique namespace.
33 std::ostringstream suffix;
34 suffix << "Incognito" << this;
35 namespace_ += suffix.str();
36 }
37
38 OfflineContentAggregator* aggregator =
39 OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
40 if (!aggregator)
41 return;
42 aggregator->RegisterProvider(namespace_, this);
43 }
44
45 BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default;
46
47 void BackgroundFetchClientImpl::Shutdown() {
48 OfflineContentAggregator* aggregator =
49 OfflineContentAggregatorFactory::GetForBrowserContext(profile_);
50 if (!aggregator)
51 return;
52
53 aggregator->UnregisterProvider(namespace_);
54
55 // If the profile is an incognito profile, clean up all data.
56 if (delegate_ && namespace_ != kBackgroundFetchNamespace)
57 delegate_->CleanupAllTasks();
58 }
59
60 void BackgroundFetchClientImpl::SetDelegate(
61 content::BackgroundFetchClient::Delegate* delegate) {
62 delegate_ = delegate;
63 }
64
65 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) {
66 DCHECK_EQ(content_id.name_space, namespace_);
67
68 if (!delegate_)
69 return;
70
71 delegate_->CancelDownload(content_id.id);
72 }
73
74 void BackgroundFetchClientImpl::PauseDownload(const ContentId& content_id) {
75 DCHECK_EQ(content_id.name_space, namespace_);
76
77 if (!delegate_)
78 return;
79
80 delegate_->PauseDownload(content_id.id);
81 }
82
83 void BackgroundFetchClientImpl::ResumeDownload(const ContentId& content_id) {
84 DCHECK_EQ(content_id.name_space, namespace_);
85
86 if (!delegate_)
87 return;
88
89 delegate_->ResumeDownload(content_id.id);
90 }
91
92 void BackgroundFetchClientImpl::OpenItem(const ContentId& content_id) {
93 // TODO(harkness): Add another call to BackgroundFetchClient::Delegate and
94 // plumb this to 'onclickevent' to the ServiceWorker.
95 }
96
97 void BackgroundFetchClientImpl::GetVisualsForItem(
98 const ContentId& id,
99 const VisualsCallback& callback) {
100 // TODO(harkness): Update with icons.
101 callback.Run(id, nullptr);
David Trainor- moved to gerrit 2017/04/19 22:45:12 Can you post this for consistent behavior? Just p
102 }
103
104 void BackgroundFetchClientImpl::AddObserver(Observer* observer) {
105 // TODO(harkness): Add a path for the OfflineContentProvider to observe
106 // changes in available BackgroundFetch items.
107 }
108
109 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {}
110
111 bool BackgroundFetchClientImpl::AreItemsAvailable() {
112 // TODO(harkness): Follow up with dtrainor about what action to take for this.
113 return false;
114 }
115
116 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) {
117 // Not applicable for Background Fetch, since offline items don't exist in the
118 // offline content system beyond the duration of the download.
119 }
120
121 const OfflineItem* BackgroundFetchClientImpl::GetItemById(
122 const ContentId& content_id) {
123 // TODO(harkness): Follow up with dtrainor about what action to take for this.
124 return nullptr;
125 }
126
127 OfflineContentProvider::OfflineItemList
128 BackgroundFetchClientImpl::GetAllItems() {
129 // TODO(harkness): Follow up with dtrainor about what action to take for this.
130 return OfflineContentProvider::OfflineItemList();
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698