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

Side by Side Diff: chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.cc

Issue 1492273002: MD Downloads: limit the amount of downloads we send (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-dl-data
Patch Set: asdf Created 5 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h" 5 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 base::Bind(&MdDownloadsDOMHandler::HandleClearAll, 129 base::Bind(&MdDownloadsDOMHandler::HandleClearAll,
130 weak_ptr_factory_.GetWeakPtr())); 130 weak_ptr_factory_.GetWeakPtr()));
131 web_ui()->RegisterMessageCallback("openDownloadsFolder", 131 web_ui()->RegisterMessageCallback("openDownloadsFolder",
132 base::Bind(&MdDownloadsDOMHandler::HandleOpenDownloadsFolder, 132 base::Bind(&MdDownloadsDOMHandler::HandleOpenDownloadsFolder,
133 weak_ptr_factory_.GetWeakPtr())); 133 weak_ptr_factory_.GetWeakPtr()));
134 } 134 }
135 135
136 void MdDownloadsDOMHandler::RenderViewReused( 136 void MdDownloadsDOMHandler::RenderViewReused(
137 content::RenderViewHost* render_view_host) { 137 content::RenderViewHost* render_view_host) {
138 list_tracker_.Stop(); 138 list_tracker_.Stop();
139 list_tracker_.Reset();
139 } 140 }
140 141
141 void MdDownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { 142 void MdDownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) {
142 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); 143 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS);
143 144
144 bool terms_changed = list_tracker_.SetSearchTerms(*args); 145 bool terms_changed = list_tracker_.SetSearchTerms(*args);
145 if (terms_changed) 146 if (terms_changed)
146 list_tracker_.CallClearAll(); 147 list_tracker_.Reset();
147 148
148 list_tracker_.Start(); 149 list_tracker_.StartAndSendChunk();
149 } 150 }
150 151
151 void MdDownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { 152 void MdDownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) {
152 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); 153 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE);
153 content::DownloadItem* file = GetDownloadByValue(args); 154 content::DownloadItem* file = GetDownloadByValue(args);
154 if (file) 155 if (file)
155 file->OpenDownload(); 156 file->OpenDownload();
156 } 157 }
157 158
158 void MdDownloadsDOMHandler::HandleDrag(const base::ListValue* args) { 159 void MdDownloadsDOMHandler::HandleDrag(const base::ListValue* args) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 232 }
232 233
233 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { 234 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) {
234 // TODO(dbeam): handle more than removed downloads someday? 235 // TODO(dbeam): handle more than removed downloads someday?
235 if (removals_.empty()) 236 if (removals_.empty())
236 return; 237 return;
237 238
238 const IdSet last_removed_ids = removals_.back(); 239 const IdSet last_removed_ids = removals_.back();
239 removals_.pop_back(); 240 removals_.pop_back();
240 241
242 const bool undoing_clear_all = last_removed_ids.size() > 1;
243 if (undoing_clear_all) {
244 list_tracker_.Reset();
245 list_tracker_.Stop();
246 }
247
241 for (auto id : last_removed_ids) { 248 for (auto id : last_removed_ids) {
242 content::DownloadItem* download = GetDownloadById(id); 249 content::DownloadItem* download = GetDownloadById(id);
243 if (!download) 250 if (!download)
244 continue; 251 continue;
245 252
246 DownloadItemModel model(download); 253 DownloadItemModel model(download);
247 model.SetShouldShowInShelf(true); 254 model.SetShouldShowInShelf(true);
248 model.SetIsBeingRevived(true); 255 model.SetIsBeingRevived(true);
249 256
250 download->UpdateObservers(); 257 download->UpdateObservers();
251 258
252 model.SetIsBeingRevived(false); 259 model.SetIsBeingRevived(false);
253 } 260 }
261
262 if (undoing_clear_all)
263 list_tracker_.StartAndSendChunk();
254 } 264 }
255 265
256 void MdDownloadsDOMHandler::HandleCancel(const base::ListValue* args) { 266 void MdDownloadsDOMHandler::HandleCancel(const base::ListValue* args) {
257 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); 267 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL);
258 content::DownloadItem* file = GetDownloadByValue(args); 268 content::DownloadItem* file = GetDownloadByValue(args);
259 if (file) 269 if (file)
260 file->Cancel(true); 270 file->Cancel(true);
261 } 271 }
262 272
263 void MdDownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { 273 void MdDownloadsDOMHandler::HandleClearAll(const base::ListValue* args) {
264 if (!IsDeletingHistoryAllowed()) { 274 if (!IsDeletingHistoryAllowed()) {
265 // This should only be reached during tests. 275 // This should only be reached during tests.
266 return; 276 return;
267 } 277 }
268 278
269 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); 279 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL);
270 280
271 list_tracker_.CallClearAll(); 281 list_tracker_.Reset();
272 list_tracker_.Stop(); 282 list_tracker_.Stop();
273 283
274 DownloadVector downloads; 284 DownloadVector downloads;
275 if (GetMainNotifierManager()) 285 if (GetMainNotifierManager())
276 GetMainNotifierManager()->GetAllDownloads(&downloads); 286 GetMainNotifierManager()->GetAllDownloads(&downloads);
277 if (GetOriginalNotifierManager()) 287 if (GetOriginalNotifierManager())
278 GetOriginalNotifierManager()->GetAllDownloads(&downloads); 288 GetOriginalNotifierManager()->GetAllDownloads(&downloads);
279 RemoveDownloads(downloads); 289 RemoveDownloads(downloads);
280 290
281 list_tracker_.Start(); 291 list_tracker_.StartAndSendChunk();
282 } 292 }
283 293
284 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { 294 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) {
285 IdSet ids; 295 IdSet ids;
286 296
287 for (auto* download : to_remove) { 297 for (auto* download : to_remove) {
288 DownloadItemModel item_model(download); 298 DownloadItemModel item_model(download);
289 if (!item_model.ShouldShowInShelf() || 299 if (!item_model.ShouldShowInShelf() ||
290 download->GetState() == content::DownloadItem::IN_PROGRESS) { 300 download->GetState() == content::DownloadItem::IN_PROGRESS) {
291 continue; 301 continue;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (GetMainNotifierManager()) 403 if (GetMainNotifierManager())
394 item = GetMainNotifierManager()->GetDownload(id); 404 item = GetMainNotifierManager()->GetDownload(id);
395 if (!item && GetOriginalNotifierManager()) 405 if (!item && GetOriginalNotifierManager())
396 item = GetOriginalNotifierManager()->GetDownload(id); 406 item = GetOriginalNotifierManager()->GetDownload(id);
397 return item; 407 return item;
398 } 408 }
399 409
400 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { 410 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() {
401 return web_ui()->GetWebContents(); 411 return web_ui()->GetWebContents();
402 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698