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

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler.cc

Issue 977473002: downloads: break downloads.js into more classes/files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig@ review Created 5 years, 9 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 (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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/i18n/time_formatting.h" 14 #include "base/i18n/time_formatting.h"
15 #include "base/logging.h"
15 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
16 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/supports_user_data.h" 23 #include "base/supports_user_data.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/value_conversions.h" 25 #include "base/value_conversions.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 file_value->SetString("danger_type", danger_type_value); 193 file_value->SetString("danger_type", danger_type_value);
193 } else if (download_item->IsPaused()) { 194 } else if (download_item->IsPaused()) {
194 file_value->SetString("state", "PAUSED"); 195 file_value->SetString("state", "PAUSED");
195 } else { 196 } else {
196 file_value->SetString("state", "IN_PROGRESS"); 197 file_value->SetString("state", "IN_PROGRESS");
197 } 198 }
198 file_value->SetString("progress_status_text", 199 file_value->SetString("progress_status_text",
199 download_model.GetTabProgressStatusText()); 200 download_model.GetTabProgressStatusText());
200 201
201 file_value->SetInteger("percent", 202 file_value->SetInteger("percent",
202 static_cast<int>(download_item->PercentComplete())); 203 std::max(0, static_cast<int>(download_item->PercentComplete())));
203 file_value->SetInteger("received", 204 file_value->SetInteger("received",
204 static_cast<int>(download_item->GetReceivedBytes())); 205 static_cast<int>(download_item->GetReceivedBytes()));
205 break; 206 break;
206 207
207 case content::DownloadItem::INTERRUPTED: 208 case content::DownloadItem::INTERRUPTED:
208 file_value->SetString("state", "INTERRUPTED"); 209 file_value->SetString("state", "INTERRUPTED");
209 210
210 file_value->SetString("progress_status_text", 211 file_value->SetString("progress_status_text",
211 download_model.GetTabProgressStatusText()); 212 download_model.GetTabProgressStatusText());
212 213
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 weak_ptr_factory_.GetWeakPtr())); 318 weak_ptr_factory_.GetWeakPtr()));
318 web_ui()->RegisterMessageCallback("openDownloadsFolder", 319 web_ui()->RegisterMessageCallback("openDownloadsFolder",
319 base::Bind(&DownloadsDOMHandler::HandleOpenDownloadsFolder, 320 base::Bind(&DownloadsDOMHandler::HandleOpenDownloadsFolder,
320 weak_ptr_factory_.GetWeakPtr())); 321 weak_ptr_factory_.GetWeakPtr()));
321 } 322 }
322 323
323 void DownloadsDOMHandler::OnDownloadCreated( 324 void DownloadsDOMHandler::OnDownloadCreated(
324 content::DownloadManager* manager, content::DownloadItem* download_item) { 325 content::DownloadManager* manager, content::DownloadItem* download_item) {
325 if (IsDownloadDisplayable(*download_item)) 326 if (IsDownloadDisplayable(*download_item))
326 ScheduleSendCurrentDownloads(); 327 ScheduleSendCurrentDownloads();
328 else
329 new_downloads_.insert(download_item->GetId());
327 } 330 }
328 331
329 void DownloadsDOMHandler::OnDownloadUpdated( 332 void DownloadsDOMHandler::OnDownloadUpdated(
330 content::DownloadManager* manager, 333 content::DownloadManager* manager,
331 content::DownloadItem* download_item) { 334 content::DownloadItem* download_item) {
332 if (IsDownloadDisplayable(*download_item)) { 335 bool showing_new_item = false;
333 if (search_terms_ && !search_terms_->empty()) { 336
334 // Don't CallDownloadUpdated() if download_item doesn't match 337 if (new_downloads_.count(download_item->GetId())) {
335 // search_terms_. 338 // A new download (that the page doesn't know about yet) has been updated.
336 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function. 339 if (!IsDownloadDisplayable(*download_item)) {
337 content::DownloadManager::DownloadVector all_items, filtered_items; 340 // Item isn't ready to be displayed yet. Wait until it is.
338 all_items.push_back(download_item); 341 return;
339 DownloadQuery query;
340 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get());
341 query.Search(all_items.begin(), all_items.end(), &filtered_items);
342 if (filtered_items.empty())
343 return;
344 } 342 }
345 base::ListValue results_value; 343
346 results_value.Append(CreateDownloadItemValue( 344 new_downloads_.erase(download_item->GetId());
347 download_item, 345 showing_new_item = true;
348 (original_notifier_.get() && 346 }
349 (manager == main_notifier_.GetManager())))); 347
350 CallDownloadUpdated(results_value); 348 if (showing_new_item || DownloadItemModel(download_item).IsBeingRevived() ||
351 } else { 349 !IsDownloadDisplayable(*download_item)) {
350 // A download will be shown or hidden by this update. Resend the list.
352 ScheduleSendCurrentDownloads(); 351 ScheduleSendCurrentDownloads();
352 return;
353 } 353 }
354
355 if (search_terms_ && !search_terms_->empty()) {
356 // Don't CallUpdateItem() if download_item doesn't match
357 // search_terms_.
358 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function.
359 content::DownloadManager::DownloadVector all_items, filtered_items;
360 all_items.push_back(download_item);
361 DownloadQuery query;
362 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_);
363 query.Search(all_items.begin(), all_items.end(), &filtered_items);
364 if (filtered_items.empty())
365 return;
366 }
367
368 scoped_ptr<base::DictionaryValue> item(CreateDownloadItemValue(
369 download_item,
370 original_notifier_ && manager == main_notifier_.GetManager()));
371 CallUpdateItem(*item);
354 } 372 }
355 373
356 void DownloadsDOMHandler::OnDownloadRemoved( 374 void DownloadsDOMHandler::OnDownloadRemoved(
357 content::DownloadManager* manager, 375 content::DownloadManager* manager,
358 content::DownloadItem* download_item) { 376 content::DownloadItem* download_item) {
359 if (!DownloadItemModel(download_item).ShouldShowInShelf()) 377 if (!DownloadItemModel(download_item).ShouldShowInShelf())
360 return; 378 return;
361 379
362 // This relies on |download_item| being removed from DownloadManager in this 380 // This relies on |download_item| being removed from DownloadManager in this
363 // MessageLoop iteration. |download_item| may not have been removed from 381 // MessageLoop iteration. |download_item| may not have been removed from
364 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the 382 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the
365 // MessageLoop to give it a chance to be removed. SendCurrentDownloads() looks 383 // MessageLoop to give it a chance to be removed. SendCurrentDownloads() looks
366 // at all downloads, and we do not tell it that |download_item| is being 384 // at all downloads, and we do not tell it that |download_item| is being
367 // removed. If DownloadManager is ever changed to not immediately remove 385 // removed. If DownloadManager is ever changed to not immediately remove
368 // |download_item| from its map when OnDownloadRemoved is sent, then 386 // |download_item| from its map when OnDownloadRemoved is sent, then
369 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell 387 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell
370 // SendCurrentDownloads() that |download_item| was removed. A 388 // SendCurrentDownloads() that |download_item| was removed. A
371 // SupportsUserData::Data would be the correct way to do this. 389 // SupportsUserData::Data would be the correct way to do this.
372 ScheduleSendCurrentDownloads(); 390 ScheduleSendCurrentDownloads();
373 } 391 }
374 392
375 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { 393 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) {
376 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); 394 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS);
377 search_terms_.reset((args && !args->empty()) ? args->DeepCopy() : NULL); 395 search_terms_.reset(args && !args->empty() ? args->DeepCopy() : NULL);
378 SendCurrentDownloads(); 396 SendCurrentDownloads();
379 } 397 }
380 398
381 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { 399 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) {
382 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); 400 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE);
383 content::DownloadItem* file = GetDownloadByValue(args); 401 content::DownloadItem* file = GetDownloadByValue(args);
384 if (file) 402 if (file)
385 file->OpenDownload(); 403 file->OpenDownload();
386 } 404 }
387 405
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (removals_.empty()) 482 if (removals_.empty())
465 return; 483 return;
466 484
467 const std::set<uint32> last_removed_ids = removals_.back(); 485 const std::set<uint32> last_removed_ids = removals_.back();
468 removals_.pop_back(); 486 removals_.pop_back();
469 487
470 for (auto id : last_removed_ids) { 488 for (auto id : last_removed_ids) {
471 content::DownloadItem* download = GetDownloadById(id); 489 content::DownloadItem* download = GetDownloadById(id);
472 if (!download) 490 if (!download)
473 continue; 491 continue;
474 DownloadItemModel(download).SetShouldShowInShelf(true); 492
493 DownloadItemModel model(download);
494 model.SetShouldShowInShelf(true);
495 model.SetIsBeingRevived(true);
496
475 download->UpdateObservers(); 497 download->UpdateObservers();
498
499 model.SetIsBeingRevived(false);
476 } 500 }
477 } 501 }
478 502
479 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { 503 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) {
480 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); 504 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL);
481 content::DownloadItem* file = GetDownloadByValue(args); 505 content::DownloadItem* file = GetDownloadByValue(args);
482 if (file) 506 if (file)
483 file->Cancel(true); 507 file->Cancel(true);
484 } 508 }
485 509
486 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { 510 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) {
487 if (!IsDeletingHistoryAllowed()) 511 if (!IsDeletingHistoryAllowed()) {
512 // This should only be reached during tests.
488 return; 513 return;
514 }
489 515
490 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); 516 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL);
491 517
492 std::vector<content::DownloadItem*> downloads; 518 std::vector<content::DownloadItem*> downloads;
493 if (GetMainNotifierManager()) 519 if (GetMainNotifierManager())
494 GetMainNotifierManager()->GetAllDownloads(&downloads); 520 GetMainNotifierManager()->GetAllDownloads(&downloads);
495 if (original_notifier_ && original_notifier_->GetManager()) 521 if (original_notifier_ && original_notifier_->GetManager())
496 original_notifier_->GetManager()->GetAllDownloads(&downloads); 522 original_notifier_->GetManager()->GetAllDownloads(&downloads);
497 RemoveDownloads(downloads); 523 RemoveDownloads(downloads);
498 } 524 }
499 525
500 void DownloadsDOMHandler::RemoveDownloads( 526 void DownloadsDOMHandler::RemoveDownloads(
501 const std::vector<content::DownloadItem*>& to_remove) { 527 const std::vector<content::DownloadItem*>& to_remove) {
502 std::set<uint32> ids; 528 std::set<uint32> ids;
529
503 for (auto* download : to_remove) { 530 for (auto* download : to_remove) {
504 DownloadItemModel item_model(download); 531 DownloadItemModel item_model(download);
505 if (!item_model.ShouldShowInShelf() || 532 if (!item_model.ShouldShowInShelf() ||
506 download->GetState() == content::DownloadItem::IN_PROGRESS) { 533 download->GetState() == content::DownloadItem::IN_PROGRESS) {
507 continue; 534 continue;
508 } 535 }
509 536
510 item_model.SetShouldShowInShelf(false); 537 item_model.SetShouldShowInShelf(false);
511 ids.insert(download->GetId()); 538 ids.insert(download->GetId());
512 download->UpdateObservers(); 539 download->UpdateObservers();
513 } 540 }
541
514 if (!ids.empty()) 542 if (!ids.empty())
515 removals_.push_back(ids); 543 removals_.push_back(ids);
516 } 544 }
517 545
518 void DownloadsDOMHandler::HandleOpenDownloadsFolder( 546 void DownloadsDOMHandler::HandleOpenDownloadsFolder(
519 const base::ListValue* args) { 547 const base::ListValue* args) {
520 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); 548 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER);
521 content::DownloadManager* manager = main_notifier_.GetManager(); 549 content::DownloadManager* manager = main_notifier_.GetManager();
522 if (manager) { 550 if (manager) {
523 platform_util::OpenItem( 551 platform_util::OpenItem(
524 Profile::FromBrowserContext(manager->GetBrowserContext()), 552 Profile::FromBrowserContext(manager->GetBrowserContext()),
525 DownloadPrefs::FromDownloadManager(manager)->DownloadPath(), 553 DownloadPrefs::FromDownloadManager(manager)->DownloadPath(),
526 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback()); 554 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback());
527 } 555 }
528 } 556 }
529 557
530 // DownloadsDOMHandler, private: ---------------------------------------------- 558 // DownloadsDOMHandler, private: ----------------------------------------------
531 559
532 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() { 560 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() {
533 // Don't call SendCurrentDownloads() every time anything changes. Batch them 561 // Don't call SendCurrentDownloads() every time anything changes. Batch them
534 // together instead. This may handle hundreds of OnDownloadDestroyed() calls 562 // together instead. This may handle hundreds of OnDownloadDestroyed() calls
535 // in a single UI message loop iteration when the user Clears All downloads. 563 // in a single UI message loop iteration when the user Clears All downloads.
536 if (update_scheduled_) 564 if (update_scheduled_)
537 return; 565 return;
566
538 update_scheduled_ = true; 567 update_scheduled_ = true;
568
539 BrowserThread::PostTask( 569 BrowserThread::PostTask(
540 BrowserThread::UI, FROM_HERE, 570 BrowserThread::UI, FROM_HERE,
541 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, 571 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads,
542 weak_ptr_factory_.GetWeakPtr())); 572 weak_ptr_factory_.GetWeakPtr()));
543 } 573 }
544 574
545 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { 575 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() {
546 return main_notifier_.GetManager(); 576 return main_notifier_.GetManager();
547 } 577 }
548 578
549 void DownloadsDOMHandler::FinalizeRemovals() { 579 void DownloadsDOMHandler::FinalizeRemovals() {
550 while (!removals_.empty()) { 580 while (!removals_.empty()) {
551 const std::set<uint32> remove = removals_.back(); 581 const std::set<uint32> remove = removals_.back();
552 removals_.pop_back(); 582 removals_.pop_back();
553 583
554 for (const auto id : remove) { 584 for (const auto id : remove) {
555 content::DownloadItem* download = GetDownloadById(id); 585 content::DownloadItem* download = GetDownloadById(id);
556 if (download) 586 if (download)
557 download->Remove(); 587 download->Remove();
558 } 588 }
559 } 589 }
560 } 590 }
561 591
562 void DownloadsDOMHandler::SendCurrentDownloads() { 592 void DownloadsDOMHandler::SendCurrentDownloads() {
563 update_scheduled_ = false; 593 update_scheduled_ = false;
594
564 content::DownloadManager::DownloadVector all_items, filtered_items; 595 content::DownloadManager::DownloadVector all_items, filtered_items;
565 if (main_notifier_.GetManager()) { 596 if (main_notifier_.GetManager()) {
566 main_notifier_.GetManager()->GetAllDownloads(&all_items); 597 main_notifier_.GetManager()->GetAllDownloads(&all_items);
567 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); 598 main_notifier_.GetManager()->CheckForHistoryFilesRemoval();
568 } 599 }
569 if (original_notifier_.get() && original_notifier_->GetManager()) { 600 if (original_notifier_ && original_notifier_->GetManager()) {
570 original_notifier_->GetManager()->GetAllDownloads(&all_items); 601 original_notifier_->GetManager()->GetAllDownloads(&all_items);
571 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); 602 original_notifier_->GetManager()->CheckForHistoryFilesRemoval();
572 } 603 }
604
573 DownloadQuery query; 605 DownloadQuery query;
574 if (search_terms_ && !search_terms_->empty()) { 606 if (search_terms_ && !search_terms_->empty())
575 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get()); 607 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_);
576 }
577 query.AddFilter(base::Bind(&IsDownloadDisplayable)); 608 query.AddFilter(base::Bind(&IsDownloadDisplayable));
578 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); 609 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING);
579 query.Limit(kMaxDownloads); 610 query.Limit(kMaxDownloads);
580 query.Search(all_items.begin(), all_items.end(), &filtered_items); 611 query.Search(all_items.begin(), all_items.end(), &filtered_items);
612
581 base::ListValue results_value; 613 base::ListValue results_value;
582 for (content::DownloadManager::DownloadVector::iterator 614 for (auto* item : filtered_items) {
583 iter = filtered_items.begin(); iter != filtered_items.end(); ++iter) {
584 results_value.Append(CreateDownloadItemValue( 615 results_value.Append(CreateDownloadItemValue(
585 *iter, 616 item,
586 (original_notifier_.get() && 617 original_notifier_ && main_notifier_.GetManager() &&
587 main_notifier_.GetManager() && 618 main_notifier_.GetManager()->GetDownload(item->GetId()) == item));
588 (main_notifier_.GetManager()->GetDownload((*iter)->GetId()) ==
589 *iter))));
590 } 619 }
591 CallDownloadsList(results_value); 620 CallUpdateAll(results_value);
592 } 621 }
593 622
594 void DownloadsDOMHandler::ShowDangerPrompt( 623 void DownloadsDOMHandler::ShowDangerPrompt(
595 content::DownloadItem* dangerous_item) { 624 content::DownloadItem* dangerous_item) {
596 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( 625 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create(
597 dangerous_item, 626 dangerous_item,
598 GetWebUIWebContents(), 627 GetWebUIWebContents(),
599 false, 628 false,
600 base::Bind(&DownloadsDOMHandler::DangerPromptDone, 629 base::Bind(&DownloadsDOMHandler::DangerPromptDone,
601 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId())); 630 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId()));
(...skipping 11 matching lines...) Expand all
613 if (!item && original_notifier_.get() && original_notifier_->GetManager()) 642 if (!item && original_notifier_.get() && original_notifier_->GetManager())
614 item = original_notifier_->GetManager()->GetDownload(download_id); 643 item = original_notifier_->GetManager()->GetDownload(download_id);
615 if (!item || item->IsDone()) 644 if (!item || item->IsDone())
616 return; 645 return;
617 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); 646 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS);
618 item->ValidateDangerousDownload(); 647 item->ValidateDangerousDownload();
619 } 648 }
620 649
621 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() { 650 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() {
622 content::DownloadManager* manager = main_notifier_.GetManager(); 651 content::DownloadManager* manager = main_notifier_.GetManager();
623 return (manager && 652 return manager &&
624 Profile::FromBrowserContext(manager->GetBrowserContext())-> 653 Profile::FromBrowserContext(manager->GetBrowserContext())->
625 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)); 654 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory);
626 } 655 }
627 656
628 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( 657 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue(
629 const base::ListValue* args) { 658 const base::ListValue* args) {
630 std::string download_id; 659 std::string download_id;
631 if (!args->GetString(0, &download_id)) { 660 if (!args->GetString(0, &download_id)) {
632 NOTREACHED(); 661 NOTREACHED();
633 return nullptr; 662 return nullptr;
634 } 663 }
635 664
636 uint64 id; 665 uint64 id;
637 if (!base::StringToUint64(download_id, &id)) { 666 if (!base::StringToUint64(download_id, &id)) {
638 NOTREACHED(); 667 NOTREACHED();
639 return nullptr; 668 return nullptr;
640 } 669 }
641 670
642 return GetDownloadById(static_cast<uint32>(id)); 671 return GetDownloadById(static_cast<uint32>(id));
643 } 672 }
644 673
645 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) { 674 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) {
646 content::DownloadItem* item = NULL; 675 content::DownloadItem* item = NULL;
647 if (GetMainNotifierManager()) 676 if (GetMainNotifierManager())
648 item = GetMainNotifierManager()->GetDownload(id); 677 item = GetMainNotifierManager()->GetDownload(id);
649 if (!item && original_notifier_.get() && original_notifier_->GetManager()) 678 if (!item && original_notifier_ && original_notifier_->GetManager())
650 item = original_notifier_->GetManager()->GetDownload(id); 679 item = original_notifier_->GetManager()->GetDownload(id);
651 return item; 680 return item;
652 } 681 }
653 682
654 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() { 683 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() {
655 return web_ui()->GetWebContents(); 684 return web_ui()->GetWebContents();
656 } 685 }
657 686
658 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { 687 void DownloadsDOMHandler::CallUpdateAll(const base::ListValue& list) {
659 web_ui()->CallJavascriptFunction("downloadsList", downloads); 688 web_ui()->CallJavascriptFunction("downloads.Manager.updateAll", list);
660 } 689 }
661 690
662 void DownloadsDOMHandler::CallDownloadUpdated( 691 void DownloadsDOMHandler::CallUpdateItem(const base::DictionaryValue& item) {
663 const base::ListValue& download_item) { 692 web_ui()->CallJavascriptFunction("downloads.Manager.updateItem", item);
664 web_ui()->CallJavascriptFunction("downloadUpdated", download_item);
665 } 693 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/downloads_dom_handler.h ('k') | chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698