Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 215 |
| 216 void MdDownloadsDOMHandler::HandlePause(const base::ListValue* args) { | 216 void MdDownloadsDOMHandler::HandlePause(const base::ListValue* args) { |
| 217 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); | 217 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); |
| 218 content::DownloadItem* file = GetDownloadByValue(args); | 218 content::DownloadItem* file = GetDownloadByValue(args); |
| 219 if (file) | 219 if (file) |
| 220 file->Pause(); | 220 file->Pause(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void MdDownloadsDOMHandler::HandleResume(const base::ListValue* args) { | 223 void MdDownloadsDOMHandler::HandleResume(const base::ListValue* args) { |
| 224 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RESUME); | 224 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RESUME); |
| 225 content::DownloadItem* file = GetDownloadByValue(args); | 225 RemoveDownloadInArgs(args); |
| 226 if (file) | |
| 227 file->Resume(); | |
|
Dan Beam
2016/06/23 01:21:13
damn, maybe i'll require a test after all...
| |
| 228 } | 226 } |
| 229 | 227 |
| 230 void MdDownloadsDOMHandler::HandleRemove(const base::ListValue* args) { | 228 void MdDownloadsDOMHandler::HandleRemove(const base::ListValue* args) { |
| 231 if (!IsDeletingHistoryAllowed()) | 229 if (!IsDeletingHistoryAllowed()) |
| 232 return; | 230 return; |
| 233 | 231 |
| 234 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); | 232 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); |
| 235 content::DownloadItem* file = GetDownloadByValue(args); | 233 RemoveDownloadInArgs(args); |
| 236 if (!file) | |
| 237 return; | |
| 238 | |
| 239 DownloadVector downloads; | |
| 240 downloads.push_back(file); | |
| 241 RemoveDownloads(downloads); | |
| 242 } | 234 } |
| 243 | 235 |
| 244 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { | 236 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { |
| 245 // TODO(dbeam): handle more than removed downloads someday? | 237 // TODO(dbeam): handle more than removed downloads someday? |
| 246 if (removals_.empty()) | 238 if (removals_.empty()) |
| 247 return; | 239 return; |
| 248 | 240 |
| 249 const IdSet last_removed_ids = removals_.back(); | 241 const IdSet last_removed_ids = removals_.back(); |
| 250 removals_.pop_back(); | 242 removals_.pop_back(); |
| 251 | 243 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 GetOriginalNotifierManager()->GetAllDownloads(&downloads); | 290 GetOriginalNotifierManager()->GetAllDownloads(&downloads); |
| 299 RemoveDownloads(downloads); | 291 RemoveDownloads(downloads); |
| 300 | 292 |
| 301 list_tracker_.StartAndSendChunk(); | 293 list_tracker_.StartAndSendChunk(); |
| 302 } | 294 } |
| 303 | 295 |
| 304 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { | 296 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { |
| 305 IdSet ids; | 297 IdSet ids; |
| 306 | 298 |
| 307 for (auto* download : to_remove) { | 299 for (auto* download : to_remove) { |
| 300 if (download->IsDangerous()) { | |
| 301 // Don't allow users to revive dangerous downloads; just nuke 'em. | |
| 302 download->Remove(); | |
| 303 continue; | |
| 304 } | |
| 305 | |
| 308 DownloadItemModel item_model(download); | 306 DownloadItemModel item_model(download); |
| 309 if (!item_model.ShouldShowInShelf() || | 307 if (!item_model.ShouldShowInShelf() || |
| 310 download->GetState() == content::DownloadItem::IN_PROGRESS) { | 308 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
| 311 continue; | 309 continue; |
| 312 } | 310 } |
| 313 | 311 |
| 314 item_model.SetShouldShowInShelf(false); | 312 item_model.SetShouldShowInShelf(false); |
| 315 ids.insert(download->GetId()); | 313 ids.insert(download->GetId()); |
| 316 download->UpdateObservers(); | 314 download->UpdateObservers(); |
| 317 } | 315 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { | 418 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { |
| 421 return web_ui()->GetWebContents(); | 419 return web_ui()->GetWebContents(); |
| 422 } | 420 } |
| 423 | 421 |
| 424 void MdDownloadsDOMHandler::CheckForRemovedFiles() { | 422 void MdDownloadsDOMHandler::CheckForRemovedFiles() { |
| 425 if (GetMainNotifierManager()) | 423 if (GetMainNotifierManager()) |
| 426 GetMainNotifierManager()->CheckForHistoryFilesRemoval(); | 424 GetMainNotifierManager()->CheckForHistoryFilesRemoval(); |
| 427 if (GetOriginalNotifierManager()) | 425 if (GetOriginalNotifierManager()) |
| 428 GetOriginalNotifierManager()->CheckForHistoryFilesRemoval(); | 426 GetOriginalNotifierManager()->CheckForHistoryFilesRemoval(); |
| 429 } | 427 } |
| 428 | |
| 429 void MdDownloadsDOMHandler::RemoveDownloadInArgs(const base::ListValue* args) { | |
| 430 content::DownloadItem* file = GetDownloadByValue(args); | |
| 431 if (!file) | |
| 432 return; | |
| 433 | |
| 434 DownloadVector downloads; | |
| 435 downloads.push_back(file); | |
| 436 RemoveDownloads(downloads); | |
| 437 } | |
| OLD | NEW |