Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 BackgroundFetchClientImpl::BackgroundFetchClientImpl(Profile* profile) | |
| 21 : profile_(profile) { | |
| 22 DCHECK(profile_); | |
| 23 offline_items_collection::OfflineContentAggregator* aggregator = | |
|
Peter Beverloo
2017/03/31 01:32:22
Could we have an GetAggregator() helper method tha
Peter Beverloo
2017/03/31 01:32:22
`using` declarations are allowed in .cc files, so
harkness
2017/03/31 10:11:43
It would only be called twice. I thought Chromium
harkness
2017/03/31 10:11:43
Done.
Peter Beverloo
2017/03/31 11:54:06
Fair enough.
| |
| 24 offline_items_collection::OfflineContentAggregatorFactory:: | |
| 25 GetForBrowserContext(profile_); | |
| 26 if (!aggregator) | |
| 27 return; | |
| 28 aggregator->RegisterProvider(kBackgroundFetchNamespace, this); | |
| 29 } | |
| 30 | |
| 31 BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default; | |
| 32 | |
| 33 void BackgroundFetchClientImpl::Shutdown() { | |
| 34 offline_items_collection::OfflineContentAggregator* aggregator = | |
| 35 offline_items_collection::OfflineContentAggregatorFactory:: | |
| 36 GetForBrowserContext(profile_); | |
| 37 if (!aggregator) | |
| 38 return; | |
| 39 aggregator->UnregisterProvider(kBackgroundFetchNamespace); | |
| 40 } | |
| 41 | |
| 42 void BackgroundFetchClientImpl::SetDelegate( | |
| 43 content::BackgroundFetchClient::Delegate* delegate) { | |
| 44 delegate_ = delegate; | |
| 45 } | |
| 46 | |
| 47 void BackgroundFetchClientImpl::CancelDownload( | |
| 48 const offline_items_collection::ContentId& content_id) { | |
| 49 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
| 50 | |
| 51 if (!delegate_) | |
| 52 return; | |
| 53 | |
| 54 delegate_->CancelDownload(content_id.id); | |
| 55 } | |
| 56 | |
| 57 void BackgroundFetchClientImpl::PauseDownload( | |
| 58 const offline_items_collection::ContentId& content_id) { | |
| 59 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
| 60 | |
| 61 if (!delegate_) | |
| 62 return; | |
| 63 | |
| 64 delegate_->PauseDownload(content_id.id); | |
| 65 } | |
| 66 | |
| 67 void BackgroundFetchClientImpl::ResumeDownload( | |
| 68 const offline_items_collection::ContentId& content_id) { | |
| 69 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
| 70 | |
| 71 if (!delegate_) | |
| 72 return; | |
| 73 | |
| 74 delegate_->ResumeDownload(content_id.id); | |
| 75 } | |
| 76 | |
| 77 void BackgroundFetchClientImpl::OpenItem( | |
| 78 const offline_items_collection::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 // This call has no meaning for BackgroundFetch, since items will be removed | |
| 92 // from the offline content listing as soon as the fetch is complete. | |
|
Peter Beverloo
2017/03/31 01:32:22
Yes, but the OIC may maintain a cache of its own.
harkness
2017/03/31 10:11:43
Updated to be a TODO.
| |
| 93 return false; | |
| 94 } | |
| 95 | |
| 96 void BackgroundFetchClientImpl::RemoveItem( | |
| 97 const offline_items_collection::ContentId& content_id) { | |
| 98 // This call has no meaning for BackgroundFetch, since items will be removed | |
| 99 // from the offline content listing as soon as the fetch is complete. | |
| 100 } | |
| 101 | |
| 102 const offline_items_collection::OfflineItem* | |
| 103 BackgroundFetchClientImpl::GetItemById( | |
| 104 const offline_items_collection::ContentId& content_id) { | |
| 105 // This call has no meaning for BackgroundFetch, since items will be removed | |
| 106 // from the offline content listing as soon as the fetch is complete. | |
| 107 return nullptr; | |
| 108 } | |
| 109 | |
| 110 offline_items_collection::OfflineContentProvider::OfflineItemList | |
| 111 BackgroundFetchClientImpl::GetAllItems() { | |
| 112 // This call has no meaning for BackgroundFetch, since items will be removed | |
| 113 // from the offline content listing as soon as the fetch is complete. | |
| 114 return offline_items_collection::OfflineContentProvider::OfflineItemList(); | |
| 115 } | |
| OLD | NEW |