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

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

Issue 2833793002: Added AddDownload communication path and observers
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <sstream> 5 #include <sstream>
6 #include <string> 6 #include <string>
7 7
8 #include "chrome/browser/background_fetch/background_fetch_client_impl.h" 8 #include "chrome/browser/background_fetch/background_fetch_client_impl.h"
9 9
10 #include "chrome/browser/offline_items_collection/offline_content_aggregator_fac tory.h" 10 #include "chrome/browser/offline_items_collection/offline_content_aggregator_fac tory.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 aggregator->UnregisterProvider(namespace_); 53 aggregator->UnregisterProvider(namespace_);
54 54
55 // If the profile is an incognito profile, clean up all data. 55 // If the profile is an incognito profile, clean up all data.
56 if (delegate_ && namespace_ == kBackgroundFetchNamespace) 56 if (delegate_ && namespace_ == kBackgroundFetchNamespace)
57 delegate_->CleanupAllTasks(); 57 delegate_->CleanupAllTasks();
58 } 58 }
59 59
60 void BackgroundFetchClientImpl::SetDelegate( 60 void BackgroundFetchClientImpl::SetDelegate(
61 content::BackgroundFetchClient::Delegate* delegate) { 61 content::BackgroundFetchClient::Delegate* delegate) {
62 delegate_ = delegate; 62 delegate_ = delegate;
63
64 // If there are any previously registered observers, notify them now.
65 for (auto& observer : observers_)
66 observer.OnItemsAvailable(this);
67 }
68
69 void BackgroundFetchClientImpl::AddDownload(const std::string& registration_id,
70 const std::string& title,
71 int64_t total_download_size) {
72 // Construct an OfflineItem to pass to the Observers.
73 offline_items_collection::OfflineItem item(
Peter Beverloo 2017/04/20 16:27:54 nit: drop offline_items_collection:: (you have a `
harkness 2017/04/21 14:55:20 Done.
74 ContentId(namespace_, registration_id));
75 item.title = title;
76 item.is_transient = true;
77 item.is_openable = false;
78 item.is_resumable = true;
79 item.percent_completed = 0;
80 item.total_size_bytes = total_download_size;
Peter Beverloo 2017/04/20 16:27:54 Should we set page_url or original_url for the ori
Peter Beverloo 2017/04/20 16:27:54 Need to set |is_off_the_record|?
harkness 2017/04/21 14:55:19 Done.
harkness 2017/04/21 14:55:19 hmm, I thought I had put a TODO in here to do a mo
81
82 offline_items_collection::OfflineContentProvider::OfflineItemList added_items;
Peter Beverloo 2017/04/20 16:27:54 nit: drop offline_items_collection:: (you have a `
harkness 2017/04/21 14:55:19 Done.
83 added_items.push_back(item);
84
85 for (auto& observer : observers_)
86 observer.OnItemsAdded(added_items);
63 } 87 }
64 88
65 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) { 89 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) {
66 DCHECK_EQ(content_id.name_space, namespace_); 90 DCHECK_EQ(content_id.name_space, namespace_);
67 91
68 if (!delegate_) 92 if (!delegate_)
69 return; 93 return;
70 94
71 delegate_->CancelDownload(content_id.id); 95 delegate_->CancelDownload(content_id.id);
72 } 96 }
(...skipping 22 matching lines...) Expand all
95 } 119 }
96 120
97 void BackgroundFetchClientImpl::GetVisualsForItem( 121 void BackgroundFetchClientImpl::GetVisualsForItem(
98 const ContentId& id, 122 const ContentId& id,
99 const VisualsCallback& callback) { 123 const VisualsCallback& callback) {
100 // TODO(harkness): Update with icons. 124 // TODO(harkness): Update with icons.
101 callback.Run(id, nullptr); 125 callback.Run(id, nullptr);
102 } 126 }
103 127
104 void BackgroundFetchClientImpl::AddObserver(Observer* observer) { 128 void BackgroundFetchClientImpl::AddObserver(Observer* observer) {
105 // TODO(harkness): Add a path for the OfflineContentProvider to observe 129 DCHECK(observer);
106 // changes in available BackgroundFetch items. 130 if (observers_.HasObserver(observer))
131 return;
132
133 observers_.AddObserver(observer);
134
135 // If the Delegate has been set then it is assumed to be ready for queries.
136 if (delegate_)
137 observer->OnItemsAvailable(this);
107 } 138 }
108 139
109 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} 140 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {
141 DCHECK(observer);
142 if (!observers_.HasObserver(observer))
143 return;
144
145 observers_.RemoveObserver(observer);
Peter Beverloo 2017/04/20 16:27:54 No need to check HasObserver() first, it's safe to
harkness 2017/04/21 14:55:19 Done.
Peter Beverloo 2017/04/24 14:39:14 Doesn't seem to be done?
146 }
110 147
111 bool BackgroundFetchClientImpl::AreItemsAvailable() { 148 bool BackgroundFetchClientImpl::AreItemsAvailable() {
112 // TODO(harkness): Follow up with dtrainor about what action to take for this. 149 // If there is a delegate, it is assumed to be ready for query.
150 if (delegate_)
151 return true;
152
113 return false; 153 return false;
Peter Beverloo 2017/04/20 16:27:54 return delegate_;
harkness 2017/04/21 14:55:19 Done.
114 } 154 }
115 155
116 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) { 156 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) {
117 // Not applicable for Background Fetch, since offline items don't exist in the 157 // Not applicable for Background Fetch, since offline items don't exist in the
118 // offline content system beyond the duration of the download. 158 // offline content system beyond the duration of the download.
119 } 159 }
120 160
121 const OfflineItem* BackgroundFetchClientImpl::GetItemById( 161 const OfflineItem* BackgroundFetchClientImpl::GetItemById(
122 const ContentId& content_id) { 162 const ContentId& content_id) {
123 // TODO(harkness): Follow up with dtrainor about what action to take for this. 163 // TODO(harkness): Follow up with dtrainor about what action to take for this.
124 return nullptr; 164 return nullptr;
125 } 165 }
126 166
127 OfflineContentProvider::OfflineItemList 167 OfflineContentProvider::OfflineItemList
128 BackgroundFetchClientImpl::GetAllItems() { 168 BackgroundFetchClientImpl::GetAllItems() {
129 // TODO(harkness): Follow up with dtrainor about what action to take for this. 169 // TODO(harkness): Follow up with dtrainor about what action to take for this.
130 return OfflineContentProvider::OfflineItemList(); 170 return OfflineContentProvider::OfflineItemList();
131 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698