Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 GURL& url, | |
| 70 const std::string& registration_id, | |
| 71 const std::string& title, | |
| 72 int64_t total_download_size) { | |
| 73 // Construct an OfflineItem to pass to the Observers. | |
| 74 OfflineItem item(ContentId(namespace_, registration_id)); | |
| 75 item.title = title; | |
| 76 item.is_transient = true; | |
| 77 item.total_size_bytes = total_download_size; | |
| 78 item.is_openable = false; | |
| 79 // Set the origin of the service worker as the url for attribution. | |
| 80 item.page_url = url; | |
| 81 item.is_off_the_record = profile_->IsOffTheRecord(); | |
| 82 item.state = offline_items_collection::OfflineItemState::IN_PROGRESS; | |
| 83 item.is_resumable = true; | |
| 84 item.allow_metered = false; | |
| 85 item.received_bytes = 0; | |
| 86 item.percent_completed = 0; | |
| 87 item.time_remaining_ms = -1; | |
| 88 // TODO(harkness): Should BackgroundFetch set a description or filter? | |
| 89 // TODO(harkness): Should BackgroundFetch expose creation/access times? | |
| 90 | |
| 91 OfflineContentProvider::OfflineItemList added_items; | |
|
Peter Beverloo
2017/04/24 14:39:15
; -> {item};
| |
| 92 added_items.push_back(item); | |
| 93 | |
| 94 for (auto& observer : observers_) | |
| 95 observer.OnItemsAdded(added_items); | |
| 63 } | 96 } |
| 64 | 97 |
| 65 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) { | 98 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) { |
| 66 DCHECK_EQ(content_id.name_space, namespace_); | 99 DCHECK_EQ(content_id.name_space, namespace_); |
| 67 | 100 |
| 68 if (!delegate_) | 101 if (!delegate_) |
| 69 return; | 102 return; |
| 70 | 103 |
| 71 delegate_->CancelDownload(content_id.id); | 104 delegate_->CancelDownload(content_id.id); |
| 72 } | 105 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 95 } | 128 } |
| 96 | 129 |
| 97 void BackgroundFetchClientImpl::GetVisualsForItem( | 130 void BackgroundFetchClientImpl::GetVisualsForItem( |
| 98 const ContentId& id, | 131 const ContentId& id, |
| 99 const VisualsCallback& callback) { | 132 const VisualsCallback& callback) { |
| 100 // TODO(harkness): Update with icons. | 133 // TODO(harkness): Update with icons. |
| 101 callback.Run(id, nullptr); | 134 callback.Run(id, nullptr); |
| 102 } | 135 } |
| 103 | 136 |
| 104 void BackgroundFetchClientImpl::AddObserver(Observer* observer) { | 137 void BackgroundFetchClientImpl::AddObserver(Observer* observer) { |
| 105 // TODO(harkness): Add a path for the OfflineContentProvider to observe | 138 DCHECK(observer); |
| 106 // changes in available BackgroundFetch items. | 139 observers_.AddObserver(observer); |
| 140 | |
| 141 // If the Delegate has been set then it is assumed to be ready for queries. | |
| 142 if (delegate_) | |
| 143 observer->OnItemsAvailable(this); | |
|
David Trainor- moved to gerrit
2017/04/25 03:24:43
Could we post this?
| |
| 107 } | 144 } |
| 108 | 145 |
| 109 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} | 146 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) { |
| 147 DCHECK(observer); | |
| 148 if (!observers_.HasObserver(observer)) | |
| 149 return; | |
| 150 | |
| 151 observers_.RemoveObserver(observer); | |
| 152 } | |
| 110 | 153 |
| 111 bool BackgroundFetchClientImpl::AreItemsAvailable() { | 154 bool BackgroundFetchClientImpl::AreItemsAvailable() { |
| 112 // TODO(harkness): Follow up with dtrainor about what action to take for this. | 155 // If there is a delegate, it is assumed to be ready for query. |
| 113 return false; | 156 return delegate_; |
| 114 } | 157 } |
| 115 | 158 |
| 116 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) { | 159 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) { |
| 117 // Not applicable for Background Fetch, since offline items don't exist in the | 160 // Not applicable for Background Fetch, since offline items don't exist in the |
| 118 // offline content system beyond the duration of the download. | 161 // offline content system beyond the duration of the download. |
| 119 } | 162 } |
| 120 | 163 |
| 121 const OfflineItem* BackgroundFetchClientImpl::GetItemById( | 164 const OfflineItem* BackgroundFetchClientImpl::GetItemById( |
| 122 const ContentId& content_id) { | 165 const ContentId& content_id) { |
| 123 // TODO(harkness): Follow up with dtrainor about what action to take for this. | 166 // TODO(harkness): Follow up with dtrainor about what action to take for this. |
| 124 return nullptr; | 167 return nullptr; |
| 125 } | 168 } |
| 126 | 169 |
| 127 OfflineContentProvider::OfflineItemList | 170 OfflineContentProvider::OfflineItemList |
| 128 BackgroundFetchClientImpl::GetAllItems() { | 171 BackgroundFetchClientImpl::GetAllItems() { |
| 129 // TODO(harkness): Follow up with dtrainor about what action to take for this. | 172 // TODO(harkness): Follow up with dtrainor about what action to take for this. |
| 130 return OfflineContentProvider::OfflineItemList(); | 173 return OfflineContentProvider::OfflineItemList(); |
| 131 } | 174 } |
| OLD | NEW |