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 <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), registered_namespace_name_(kBackgroundFetchNamespace) { | |
|
Peter Beverloo
2017/04/18 23:12:08
optional nit: I'd s/registered_namespace_name_/nam
harkness
2017/04/19 09:03:40
Done.
| |
| 29 DCHECK(profile_); | |
| 30 if (profile->IsOffTheRecord()) { | |
| 31 std::ostringstream suffix; | |
| 32 suffix << "Incognito" << this; | |
|
Peter Beverloo
2017/04/18 23:12:08
This needs a comment to explain what's going on he
harkness
2017/04/19 09:03:41
Done.
| |
| 33 registered_namespace_name_ += suffix.str(); | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
I think this will work with the UI. The UI tracks
harkness
2017/04/19 09:03:41
Acknowledged.
| |
| 34 } | |
| 35 | |
| 36 OfflineContentAggregator* aggregator = | |
| 37 OfflineContentAggregatorFactory::GetForBrowserContext(profile_); | |
| 38 if (!aggregator) | |
| 39 return; | |
| 40 aggregator->RegisterProvider(registered_namespace_name_, this); | |
| 41 } | |
| 42 | |
| 43 BackgroundFetchClientImpl::~BackgroundFetchClientImpl() = default; | |
| 44 | |
| 45 void BackgroundFetchClientImpl::Shutdown() { | |
| 46 OfflineContentAggregator* aggregator = | |
| 47 OfflineContentAggregatorFactory::GetForBrowserContext(profile_); | |
| 48 if (!aggregator) | |
| 49 return; | |
| 50 | |
| 51 aggregator->UnregisterProvider(registered_namespace_name_); | |
| 52 | |
| 53 // If the profile is an incognito profile, clean up all data. | |
| 54 if (delegate_ && | |
| 55 registered_namespace_name_.compare(kBackgroundFetchNamespace)) | |
|
Peter Beverloo
2017/04/18 23:12:08
Just use operator==. Adding an IsIncognito() helpe
harkness
2017/04/19 09:03:40
Updated to use ==, but since it's the only place i
| |
| 56 delegate_->CleanupAllTasks(); | |
| 57 } | |
| 58 | |
| 59 void BackgroundFetchClientImpl::SetDelegate( | |
| 60 content::BackgroundFetchClient::Delegate* delegate) { | |
| 61 delegate_ = delegate; | |
| 62 } | |
| 63 | |
| 64 void BackgroundFetchClientImpl::CancelDownload(const ContentId& content_id) { | |
| 65 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
|
Peter Beverloo
2017/04/18 23:12:08
But these are not correct anymore, right? We need
harkness
2017/04/19 09:03:40
Good catch, I totally overlooked this. Done.
| |
| 66 | |
| 67 if (!delegate_) | |
| 68 return; | |
| 69 | |
| 70 delegate_->CancelDownload(content_id.id); | |
| 71 } | |
| 72 | |
| 73 void BackgroundFetchClientImpl::PauseDownload(const ContentId& content_id) { | |
| 74 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
| 75 | |
| 76 if (!delegate_) | |
| 77 return; | |
| 78 | |
| 79 delegate_->PauseDownload(content_id.id); | |
| 80 } | |
| 81 | |
| 82 void BackgroundFetchClientImpl::ResumeDownload(const ContentId& content_id) { | |
| 83 DCHECK_EQ(content_id.name_space, kBackgroundFetchNamespace); | |
| 84 | |
| 85 if (!delegate_) | |
| 86 return; | |
| 87 | |
| 88 delegate_->ResumeDownload(content_id.id); | |
| 89 } | |
| 90 | |
| 91 void BackgroundFetchClientImpl::OpenItem(const ContentId& content_id) { | |
| 92 // TODO(harkness): Add another call to BackgroundFetchClient::Delegate and | |
| 93 // plumb this to 'onclickevent' to the ServiceWorker. | |
| 94 } | |
| 95 | |
| 96 void BackgroundFetchClientImpl::GetVisualsForItem( | |
| 97 const ContentId& id, | |
| 98 const VisualsCallback& callback) { | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
We cache the icons in the Java layer for now. Not
Peter Beverloo
2017/04/18 23:12:08
I guess we should add the following then (until ic
harkness
2017/04/19 09:03:40
The second argument is a const OfflineItemVisuals*
harkness
2017/04/19 09:03:41
Acknowledged.
| |
| 99 // TODO(harkness): Either cache the icons here or call into the delegate to | |
| 100 // get the icons. | |
| 101 } | |
| 102 | |
| 103 void BackgroundFetchClientImpl::AddObserver(Observer* observer) { | |
| 104 // TODO(harkness): Add a path for the OfflineContentProvider to observe | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
Save an base::ObserverList<> of the observers and
harkness
2017/04/19 09:03:40
I'm going to do this and the other observer calls
David Trainor- moved to gerrit
2017/04/19 22:45:12
Acknowledged.
| |
| 105 // changes in available BackgroundFetch items. | |
| 106 } | |
| 107 | |
| 108 void BackgroundFetchClientImpl::RemoveObserver(Observer* observer) {} | |
| 109 | |
| 110 bool BackgroundFetchClientImpl::AreItemsAvailable() { | |
| 111 // TODO(harkness): Follow up with dtrainor about what action to take for this. | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
When it's possible to talk to your delegate_, this
harkness
2017/04/19 09:03:40
Acknowledged.
| |
| 112 return false; | |
| 113 } | |
| 114 | |
| 115 void BackgroundFetchClientImpl::RemoveItem(const ContentId& content_id) { | |
| 116 // TODO(harkness): Follow up with dtrainor about what action to take for this. | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
N/A for your case probably, since the item shouldn
harkness
2017/04/19 09:03:41
Done.
| |
| 117 } | |
| 118 | |
| 119 const OfflineItem* BackgroundFetchClientImpl::GetItemById( | |
| 120 const ContentId& content_id) { | |
| 121 // TODO(harkness): Follow up with dtrainor about what action to take for this. | |
|
David Trainor- moved to gerrit
2017/04/18 22:15:55
Return the OfflineItem that represents the backgro
harkness
2017/04/19 09:03:40
Acknowledged.
| |
| 122 return nullptr; | |
| 123 } | |
| 124 | |
| 125 OfflineContentProvider::OfflineItemList | |
| 126 BackgroundFetchClientImpl::GetAllItems() { | |
| 127 // TODO(harkness): Follow up with dtrainor about what action to take for this. | |
| 128 return OfflineContentProvider::OfflineItemList(); | |
| 129 } | |
| OLD | NEW |