| 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/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Add ourself to all download items as an observer. | 357 // Add ourself to all download items as an observer. |
| 358 for (OrderedDownloads::iterator it = download_items_.begin(); | 358 for (OrderedDownloads::iterator it = download_items_.begin(); |
| 359 it != download_items_.end(); ++it) { | 359 it != download_items_.end(); ++it) { |
| 360 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) | 360 if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads) |
| 361 break; | 361 break; |
| 362 | 362 |
| 363 // We should never see anything that isn't already in the history. | 363 // We should never see anything that isn't already in the history. |
| 364 DCHECK(*it); | 364 DCHECK(*it); |
| 365 DCHECK((*it)->IsPersisted()); | |
| 366 | 365 |
| 367 (*it)->AddObserver(this); | 366 (*it)->AddObserver(this); |
| 368 } | 367 } |
| 369 | 368 |
| 370 SendCurrentDownloads(); | 369 SendCurrentDownloads(); |
| 371 } | 370 } |
| 372 | 371 |
| 373 void DownloadsDOMHandler::ManagerGoingDown(content::DownloadManager* manager) { | 372 void DownloadsDOMHandler::ManagerGoingDown(content::DownloadManager* manager) { |
| 374 // This should never happen. The lifetime of the DownloadsDOMHandler | 373 // This should never happen. The lifetime of the DownloadsDOMHandler |
| 375 // is tied to the tab in which downloads.html is displayed, which cannot | 374 // is tied to the tab in which downloads.html is displayed, which cannot |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); | 442 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); |
| 444 content::DownloadItem* file = GetDownloadByValue(args); | 443 content::DownloadItem* file = GetDownloadByValue(args); |
| 445 if (file) | 444 if (file) |
| 446 file->TogglePause(); | 445 file->TogglePause(); |
| 447 } | 446 } |
| 448 | 447 |
| 449 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { | 448 void DownloadsDOMHandler::HandleRemove(const ListValue* args) { |
| 450 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); | 449 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); |
| 451 content::DownloadItem* file = GetDownloadByValue(args); | 450 content::DownloadItem* file = GetDownloadByValue(args); |
| 452 if (file) { | 451 if (file) { |
| 453 DCHECK(file->IsPersisted()); | |
| 454 file->Remove(); | 452 file->Remove(); |
| 455 } | 453 } |
| 456 } | 454 } |
| 457 | 455 |
| 458 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { | 456 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { |
| 459 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); | 457 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); |
| 460 content::DownloadItem* file = GetDownloadByValue(args); | 458 content::DownloadItem* file = GetDownloadByValue(args); |
| 461 if (file) | 459 if (file) |
| 462 file->Cancel(true); | 460 file->Cancel(true); |
| 463 } | 461 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 539 } |
| 542 | 540 |
| 543 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 541 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 544 const ListValue* args) { | 542 const ListValue* args) { |
| 545 int id; | 543 int id; |
| 546 if (ExtractIntegerValue(args, &id)) { | 544 if (ExtractIntegerValue(args, &id)) { |
| 547 return GetDownloadById(id); | 545 return GetDownloadById(id); |
| 548 } | 546 } |
| 549 return NULL; | 547 return NULL; |
| 550 } | 548 } |
| OLD | NEW |