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

Side by Side Diff: components/offline_pages/downloads/download_ui_adapter.cc

Issue 2221293002: Implement deleteItem and openItem on OfflinePageDownloadBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/offline_pages/downloads/download_ui_adapter.h" 5 #include "components/offline_pages/downloads/download_ui_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 const DownloadUIItem* 90 const DownloadUIItem*
91 DownloadUIAdapter::GetItem(const std::string& guid) const { 91 DownloadUIAdapter::GetItem(const std::string& guid) const {
92 DownloadUIItemsMap::const_iterator it = items_.find(guid); 92 DownloadUIItemsMap::const_iterator it = items_.find(guid);
93 if (it == items_.end()) 93 if (it == items_.end())
94 return nullptr; 94 return nullptr;
95 return (*it).second.get(); 95 return (*it).second.get();
96 } 96 }
97 97
98 void DownloadUIAdapter::DeleteItem(const std::string& guid) {
99 // TODO(dimich): Also remove pending request from RequestQueue.
100 model_->GetAllPages(
fgorski 2016/08/09 04:00:50 On an off chance that you didn't consider it yet.
Dmitry Titov 2016/08/12 04:01:39 Done, by adding ItemInfo internal struct of whihc
101 base::Bind(&DownloadUIAdapter::OnDeleteItemByGuid,
102 weak_ptr_factory_.GetWeakPtr(),
103 guid));
104 }
105
106 std::string DownloadUIAdapter::GetOfflineUrlByGuid(
107 const std::string& guid) const {
108 std::string offline_url;
109 // TODO(dimich): when requests are also in the cache, filter them out.
110 DownloadUIItemsMap::const_iterator it = items_.find(guid);
111 if (it != items_.end())
112 offline_url = (*it).second->offline_url;
fgorski 2016/08/09 04:00:50 How about dropping the internal variable and doing
Dmitry Titov 2016/08/12 04:01:39 Done.
113 return offline_url;
114 }
115
98 void DownloadUIAdapter::LoadCache() { 116 void DownloadUIAdapter::LoadCache() {
99 DCHECK(!is_loaded_); 117 DCHECK(!is_loaded_);
100 // TODO(dimich): Add fetching from RequestQueue as well. 118 // TODO(dimich): Add fetching from RequestQueue as well.
101 model_->AddObserver(this); 119 model_->AddObserver(this);
102 model_->GetAllPages( 120 model_->GetAllPages(
103 base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded, 121 base::Bind(&DownloadUIAdapter::OnOfflinePagesLoaded,
104 weak_ptr_factory_.GetWeakPtr())); 122 weak_ptr_factory_.GetWeakPtr()));
105 } 123 }
106 124
107 void DownloadUIAdapter::ClearCache() { 125 void DownloadUIAdapter::ClearCache() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 added_guids.push_back(guid); 164 added_guids.push_back(guid);
147 } 165 }
148 // Only one added page 166 // Only one added page
149 CHECK(added_guids.size() <= 1); 167 CHECK(added_guids.size() <= 1);
150 for (auto& guid : added_guids) { 168 for (auto& guid : added_guids) {
151 const DownloadUIItem& item = *(items_.find(guid)->second.get()); 169 const DownloadUIItem& item = *(items_.find(guid)->second.get());
152 FOR_EACH_OBSERVER(Observer, observers_, ItemAdded(item)); 170 FOR_EACH_OBSERVER(Observer, observers_, ItemAdded(item));
153 } 171 }
154 } 172 }
155 173
174 void DownloadUIAdapter::OnDeleteItemByGuid(
fgorski 2016/08/09 04:00:50 this method needs git cl format. Please run it.
Dmitry Titov 2016/08/12 04:01:39 Done.
175 const MultipleOfflinePageItemResult& pages, const std::string& guid) {
176 OfflinePageItem* page = FindPageByGuid(pages, guid);
177 if (!page)
178 return;
179 std::vector<int64_t> page_ids;
180 page_ids.push_back(page.offline_id);
181 // TODO(dimich): This should be ExpirePages(...Now()..) when Expire is
182 // firing Observer method. The resulting Observer notification will update
183 // local cache.
184 model_->DeletePagesByOfflineId(
185 page_ids,
186 base::Bind(&DownloadUIAdapter::OnDeletePagesDone,
187 weak_ptr_factory_.GetWeakPtr()));
188 }
189
190 void DownloadUIAdapter::OnDeletePagesDone(bool success) {
191 // Do nothing here.
fgorski 2016/08/09 04:00:50 TODO: Add UMA for Download UI actions.
Dmitry Titov 2016/08/12 04:01:39 Done.
192 }
193
194 OfflinePageItem* DownloadUIAdapter::FindPageByGuid(
195 const MultipleOfflinePageItemResult& pages, const std::string& guid) {
196 for (const auto& page : pages) {
197 if (IsVisibleInUI(page) && page.client_id.id == guid)
198 return page;
199 }
200 return nullptr;
201 }
202
156 bool DownloadUIAdapter::IsVisibleInUI(const OfflinePageItem& page) { 203 bool DownloadUIAdapter::IsVisibleInUI(const OfflinePageItem& page) {
157 // TODO(dimich): set up the right filter here. 204 // TODO(dimich): set up the right filter here.
158 return page.client_id.name_space == kAsyncNamespace && 205 return page.client_id.name_space == kAsyncNamespace &&
159 base::IsValidGUID(page.client_id.id); 206 base::IsValidGUID(page.client_id.id);
160 } 207 }
161 208
162 } // namespace offline_pages 209 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698