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

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 6096003: Put history insertion for downloads processing inline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments, fixed bugs. Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/download/download_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 new OtherDownloadManagerObserver(this)); 235 new OtherDownloadManagerObserver(this));
236 236
237 return true; 237 return true;
238 } 238 }
239 239
240 // We have received a message from DownloadFileManager about a new download. We 240 // We have received a message from DownloadFileManager about a new download. We
241 // create a download item and store it in our download map, and inform the 241 // create a download item and store it in our download map, and inform the
242 // history system of a new download. Since this method can be called while the 242 // history system of a new download. Since this method can be called while the
243 // history service thread is still reading the persistent state, we do not 243 // history service thread is still reading the persistent state, we do not
244 // insert the new DownloadItem into 'history_downloads_' or inform our 244 // insert the new DownloadItem into 'history_downloads_' or inform our
245 // observers at this point. OnCreateDatabaseEntryComplete() handles that 245 // observers at this point. OnCreateDownloadEntryComplete() handles that
246 // finalization of the the download creation as a callback from the 246 // finalization of the the download creation as a callback from the
247 // history thread. 247 // history thread.
248 void DownloadManager::StartDownload(DownloadCreateInfo* info) { 248 void DownloadManager::StartDownload(DownloadCreateInfo* info) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
250 DCHECK(info); 250 DCHECK(info);
251 251
252 // Check whether this download is for an extension install or not. 252 // Check whether this download is for an extension install or not.
253 // Allow extensions to be explicitly saved. 253 // Allow extensions to be explicitly saved.
254 if (!info->prompt_user_for_save_location) { 254 if (!info->prompt_user_for_save_location) {
255 if (UserScript::HasUserScriptFileExtension(info->url) || 255 if (UserScript::HasUserScriptFileExtension(info->url) ||
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 DownloadItem* download = new DownloadItem(this, *info, 424 DownloadItem* download = new DownloadItem(this, *info,
425 profile_->IsOffTheRecord()); 425 profile_->IsOffTheRecord());
426 DCHECK(!ContainsKey(in_progress_, info->download_id)); 426 DCHECK(!ContainsKey(in_progress_, info->download_id));
427 DCHECK(!ContainsKey(active_downloads_, info->download_id)); 427 DCHECK(!ContainsKey(active_downloads_, info->download_id));
428 downloads_.insert(download); 428 downloads_.insert(download);
429 active_downloads_[info->download_id] = download; 429 active_downloads_[info->download_id] = download;
430 } 430 }
431 431
432 void DownloadManager::AttachDownloadItem(DownloadCreateInfo* info, 432 void DownloadManager::AttachDownloadItem(DownloadCreateInfo* info,
433 const FilePath& target_path) { 433 const FilePath& target_path) {
434 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString();
435
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
435 437
436 scoped_ptr<DownloadCreateInfo> infop(info); 438 scoped_ptr<DownloadCreateInfo> infop(info);
437 info->path = target_path; 439 info->path = target_path;
438 440
439 // NOTE(ahendrickson) Eventually |active_downloads_| will replace 441 // NOTE(ahendrickson) Eventually |active_downloads_| will replace
440 // |in_progress_|, but we don't want to change the semantics yet. 442 // |in_progress_|, but we don't want to change the semantics yet.
441 DCHECK(!ContainsKey(in_progress_, info->download_id)); 443 DCHECK(!ContainsKey(in_progress_, info->download_id));
442 DCHECK(ContainsKey(active_downloads_, info->download_id)); 444 DCHECK(ContainsKey(active_downloads_, info->download_id));
443 DownloadItem* download = active_downloads_[info->download_id]; 445 DownloadItem* download = active_downloads_[info->download_id];
444 DCHECK(download != NULL); 446 DCHECK(download != NULL);
445 DCHECK(ContainsKey(downloads_, download)); 447 DCHECK(ContainsKey(downloads_, download));
446 448
447 download->SetFileCheckResults(info->path, 449 download->SetFileCheckResults(info->path,
448 info->is_dangerous, 450 info->is_dangerous,
449 info->path_uniquifier, 451 info->path_uniquifier,
450 info->prompt_user_for_save_location, 452 info->prompt_user_for_save_location,
451 info->is_extension_install, 453 info->is_extension_install,
452 info->original_name); 454 info->original_name);
453 in_progress_[info->download_id] = download; 455 in_progress_[info->download_id] = download;
456 UpdateAppIcon(); // Reflect entry into in_progress_.
454 457
455 bool download_finished = ContainsKey(pending_finished_downloads_, 458 // Rename to intermediate name.
456 info->download_id); 459 if (info->is_dangerous) {
457 460 // The download is not safe. We can now rename the file to its
458 VLOG(20) << __FUNCTION__ << "()" 461 // tentative name using OnFinalDownloadName (the actual final
459 << " target_path = \"" << target_path.value() << "\"" 462 // name after user confirmation will be set in
460 << " download_finished = " << download_finished 463 // ProceedWithFinishedDangerousDownload).
461 << " info = " << info->DebugString()
462 << " download = " << download->DebugString(true);
463
464 if (download_finished || info->is_dangerous) {
465 // The download has already finished or the download is not safe.
466 // We can now rename the file to its final name (or its tentative name
467 // in dangerous download cases).
468 BrowserThread::PostTask( 464 BrowserThread::PostTask(
469 BrowserThread::FILE, FROM_HERE, 465 BrowserThread::FILE, FROM_HERE,
470 NewRunnableMethod( 466 NewRunnableMethod(
471 file_manager_, &DownloadFileManager::OnFinalDownloadName, 467 file_manager_, &DownloadFileManager::OnFinalDownloadName,
472 download->id(), target_path, !info->is_dangerous, 468 download->id(), target_path, false,
473 make_scoped_refptr(this))); 469 make_scoped_refptr(this)));
474 } else { 470 } else {
475 // The download hasn't finished and it is a safe download. We need to 471 // The download is a safe download. We need to
476 // rename it to its intermediate '.crdownload' path. 472 // rename it to its intermediate '.crdownload' path. The final
473 // name after user confirmation will be set from
474 // DownloadItem::OnSafeDownloadFinished.
477 FilePath download_path = download_util::GetCrDownloadPath(target_path); 475 FilePath download_path = download_util::GetCrDownloadPath(target_path);
478 BrowserThread::PostTask( 476 BrowserThread::PostTask(
479 BrowserThread::FILE, FROM_HERE, 477 BrowserThread::FILE, FROM_HERE,
480 NewRunnableMethod( 478 NewRunnableMethod(
481 file_manager_, &DownloadFileManager::OnIntermediateDownloadName, 479 file_manager_, &DownloadFileManager::OnIntermediateDownloadName,
482 download->id(), download_path, make_scoped_refptr(this))); 480 download->id(), download_path, make_scoped_refptr(this)));
483 download->Rename(download_path); 481 download->Rename(download_path);
484 } 482 }
485 483
486 if (download_finished) {
487 // If the download already completed by the time we reached this point, then
488 // notify observers that it did.
489 OnAllDataSaved(info->download_id,
490 pending_finished_downloads_[info->download_id]);
491 }
492
493 download_history_->AddEntry(*info, download, 484 download_history_->AddEntry(*info, download,
494 NewCallback(this, &DownloadManager::OnCreateDownloadEntryComplete)); 485 NewCallback(this, &DownloadManager::OnCreateDownloadEntryComplete));
495
496 UpdateAppIcon();
497 } 486 }
498 487
499 void DownloadManager::UpdateDownload(int32 download_id, int64 size) { 488 void DownloadManager::UpdateDownload(int32 download_id, int64 size) {
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
501 DownloadMap::iterator it = active_downloads_.find(download_id); 490 DownloadMap::iterator it = active_downloads_.find(download_id);
502 if (it != active_downloads_.end()) { 491 if (it != active_downloads_.end()) {
503 DownloadItem* download = it->second; 492 DownloadItem* download = it->second;
504 if (download->state() == DownloadItem::IN_PROGRESS) { 493 if (download->state() == DownloadItem::IN_PROGRESS) {
505 download->Update(size); 494 download->Update(size);
495 UpdateAppIcon(); // Reflect size updates.
ahendrickson 2011/01/13 03:15:17 Why not set a flag if we update a download, then c
Randy Smith (Not in Mondays) 2011/01/16 20:43:56 I'm very confused. What loop? We call find, get
506 download_history_->UpdateEntry(download); 496 download_history_->UpdateEntry(download);
507 } 497 }
508 } 498 }
509 UpdateAppIcon();
510 } 499 }
511 500
512 void DownloadManager::OnAllDataSaved(int32 download_id, int64 size) { 501 void DownloadManager::OnAllDataSaved(int32 download_id, int64 size) {
513 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id 502 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
514 << " size = " << size; 503 << " size = " << size;
515 DownloadMap::iterator it = in_progress_.find(download_id); 504
516 if (it == in_progress_.end()) { 505 DCHECK_EQ(0U, pending_finished_downloads_.count(download_id));
ahendrickson 2011/01/13 03:15:17 Would |ContainsKey()| work here, and in succeeding
Randy Smith (Not in Mondays) 2011/01/16 20:43:56 So if you ask me for this change again I'll do it.
517 // The download is done, but the user hasn't selected a final location for 506 pending_finished_downloads_[download_id] = size;
518 // it yet (the Save As dialog box is probably still showing), so just keep 507
519 // track of the fact that this download id is complete, when the 508 MaybeCompleteDownload(download_id);
520 // DownloadItem is constructed later we'll notify its completion then. 509 }
521 DCHECK(!ContainsKey(pending_finished_downloads_, download_id)); 510
522 pending_finished_downloads_[download_id] = size; 511 bool DownloadManager::IsDownloadReadyForCompletion(int32 download_id) {
523 VLOG(20) << __FUNCTION__ << "()" << " Added download_id = " << download_id 512 // If we don't have all the data, the download is not ready for
524 << " to pending_finished_downloads_"; 513 // completion.
514 if (pending_finished_downloads_.count(download_id) == 0)
515 return false;
516
517 // If the download isn't active (e.g. has been cancelled) it's not
518 // ready for completion.
519 if (active_downloads_.count(download_id) == 0)
520 return false;
521
522 // If the download hasn't been inserted into the history system
523 // (which occurs strictly after file name determination, intermediate
524 // file rename, and UI display) then it's not ready for completion.
525 return (active_downloads_[download_id]->db_handle() !=
526 DownloadHistory::kUninitializedHandle);
527 }
528
529 void DownloadManager::MaybeCompleteDownload(int32 download_id) {
530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
531 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id;
532
533 if (!IsDownloadReadyForCompletion(download_id))
525 return; 534 return;
535
536 // TODO(rdsmith): DCHECK that we only pass through this point
537 // once per download. The natural way to do this is by a state
538 // transition on the DownloadItem.
539
540 // Confirm we're in the proper set of states to be here;
541 // in in_progress_, in pending_finished_, have a history handle.
542 DCHECK_EQ(1u, in_progress_.count(download_id));
543 DCHECK_EQ(1u, pending_finished_downloads_.count(download_id));
544 DownloadItem* download = in_progress_[download_id];
545 DCHECK(download->db_handle() != DownloadHistory::kUninitializedHandle);
546 DCHECK_EQ(1u, history_downloads_.count(download->db_handle()));
547
548 VLOG(20) << __FUNCTION__ << "()" << " executing: download = "
549 << download->DebugString(false);
550
551 // Remove the id from in_progress and pending_finished.
552 int size = pending_finished_downloads_[download_id];
553 pending_finished_downloads_.erase(download_id);
554 in_progress_.erase(download_id);
555 UpdateAppIcon(); // Reflect removal from in_progress_.
556
557 // Final update of download item and history.
558 download->OnAllDataSaved(size);
ahendrickson 2011/01/13 03:15:17 It seems odd not to call |download->OnAllDataSaved
Paweł Hajdan Jr. 2011/01/13 08:43:10 Yes, definitely. I thought that OnAllDataSaved sho
Randy Smith (Not in Mondays) 2011/01/16 20:43:56 Well, DownloadManager::OnAllDataSaved triggers Dow
Paweł Hajdan Jr. 2011/01/17 18:13:23 I'm sorry, I actually think that OnReadyToFinish i
Randy Smith (Not in Mondays) 2011/01/17 19:56:17 Sorry, now you've gotten me confused. download->O
559 download_history_->UpdateEntry(download);
560
561 switch (download->safety_state()) {
562 case DownloadItem::DANGEROUS:
563 // If this a dangerous download not yet validated by the user, don't do
564 // anything. When the user notifies us, it will trigger a call to
565 // ProceedWithFinishedDangerousDownload.
566 return;
567 case DownloadItem::DANGEROUS_BUT_VALIDATED:
568 // The dangerous download has been validated by the user. We first
569 // need to rename the downloaded file from its temporary name to
570 // its final name. We will continue the download processing in the
571 // callback.
572 BrowserThread::PostTask(
573 BrowserThread::FILE, FROM_HERE,
574 NewRunnableMethod(
575 this, &DownloadManager::ProceedWithFinishedDangerousDownload,
576 download->db_handle(),
577 download->full_path(), download->target_name()));
578 return;
579 case DownloadItem::SAFE:
580 // The download is safe; just finish it.
581 download->OnSafeDownloadFinished(file_manager_);
582 return;
526 } 583 }
527
528 // Remove the id from the list of pending ids.
529 PendingFinishedMap::iterator erase_it =
530 pending_finished_downloads_.find(download_id);
531 if (erase_it != pending_finished_downloads_.end()) {
532 pending_finished_downloads_.erase(erase_it);
533 VLOG(20) << __FUNCTION__ << "()" << " Removed download_id = " << download_id
534 << " from pending_finished_downloads_";
535 }
536
537 DownloadItem* download = it->second;
538
539 VLOG(20) << __FUNCTION__ << "()"
540 << " download = " << download->DebugString(true);
541
542 download->OnAllDataSaved(size);
543
544 // Clean up will happen when the history system create callback runs if we
545 // don't have a valid db_handle yet.
546 if (download->db_handle() != DownloadHistory::kUninitializedHandle) {
547 in_progress_.erase(it);
548 download_history_->UpdateEntry(download);
549 }
550
551 UpdateAppIcon();
552
553 // If this a dangerous download not yet validated by the user, don't do
554 // anything. When the user notifies us, it will trigger a call to
555 // ProceedWithFinishedDangerousDownload.
556 if (download->safety_state() == DownloadItem::DANGEROUS) {
557 return;
558 }
559
560 if (download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) {
561 // We first need to rename the downloaded file from its temporary name to
562 // its final name before we can continue.
563 BrowserThread::PostTask(
564 BrowserThread::FILE, FROM_HERE,
565 NewRunnableMethod(
566 this, &DownloadManager::ProceedWithFinishedDangerousDownload,
567 download->db_handle(),
568 download->full_path(), download->target_name()));
569 return;
570 }
571
572 download->OnSafeDownloadFinished(file_manager_);
573 } 584 }
574 585
575 void DownloadManager::RemoveFromActiveList(int32 download_id) { 586 void DownloadManager::RemoveFromActiveList(int32 download_id) {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
577 active_downloads_.erase(download_id); 588 active_downloads_.erase(download_id);
578 } 589 }
579 590
580 void DownloadManager::DownloadRenamedToFinalName(int download_id, 591 void DownloadManager::DownloadRenamedToFinalName(int download_id,
581 const FilePath& full_path) { 592 const FilePath& full_path) {
582 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id 593 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 DownloadItem* download = it->second; 664 DownloadItem* download = it->second;
654 665
655 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id 666 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
656 << " download = " << download->DebugString(true); 667 << " download = " << download->DebugString(true);
657 668
658 // Clean up will happen when the history system create callback runs if we 669 // Clean up will happen when the history system create callback runs if we
659 // don't have a valid db_handle yet. 670 // don't have a valid db_handle yet.
660 if (download->db_handle() != DownloadHistory::kUninitializedHandle) { 671 if (download->db_handle() != DownloadHistory::kUninitializedHandle) {
661 in_progress_.erase(it); 672 in_progress_.erase(it);
662 active_downloads_.erase(download_id); 673 active_downloads_.erase(download_id);
674 UpdateAppIcon(); // Reflect removal from in_progress_.
663 download_history_->UpdateEntry(download); 675 download_history_->UpdateEntry(download);
664 } 676 }
665 677
666 DownloadCancelledInternal(download_id, 678 DownloadCancelledInternal(download_id,
667 download->render_process_id(), 679 download->render_process_id(),
668 download->request_id()); 680 download->request_id());
669 UpdateAppIcon();
670 } 681 }
671 682
672 void DownloadManager::DownloadCancelledInternal(int download_id, 683 void DownloadManager::DownloadCancelledInternal(int download_id,
673 int render_process_id, 684 int render_process_id,
674 int request_id) { 685 int request_id) {
675 // Cancel the network request. RDH is guaranteed to outlive the IO thread. 686 // Cancel the network request. RDH is guaranteed to outlive the IO thread.
676 BrowserThread::PostTask( 687 BrowserThread::PostTask(
677 BrowserThread::IO, FROM_HERE, 688 BrowserThread::IO, FROM_HERE,
678 NewRunnableFunction(&download_util::CancelDownloadRequest, 689 NewRunnableFunction(&download_util::CancelDownloadRequest,
679 g_browser_process->resource_dispatcher_host(), 690 g_browser_process->resource_dispatcher_host(),
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 // Insert into our full map. 990 // Insert into our full map.
980 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); 991 DCHECK(!ContainsKey(history_downloads_, download->db_handle()));
981 history_downloads_[download->db_handle()] = download; 992 history_downloads_[download->db_handle()] = download;
982 993
983 // Show in the appropriate browser UI. 994 // Show in the appropriate browser UI.
984 ShowDownloadInBrowser(info, download); 995 ShowDownloadInBrowser(info, download);
985 996
986 // Inform interested objects about the new download. 997 // Inform interested objects about the new download.
987 NotifyModelChanged(); 998 NotifyModelChanged();
988 999
989 // If this download has been completed before we've received the db handle, 1000 // If this download has been cancelled before we've received the DB handle,
990 // post one final message to the history service so that it can be properly 1001 // post one final message to the history service so that it can be properly
991 // in sync with the DownloadItem's completion status, and also inform any 1002 // in sync with the DownloadItem's completion status, and also inform any
992 // observers so that they get more than just the start notification. 1003 // observers so that they get more than just the start notification.
1004 //
1005 // Otherwise, try to complete the download
993 if (download->state() != DownloadItem::IN_PROGRESS) { 1006 if (download->state() != DownloadItem::IN_PROGRESS) {
1007 DCHECK_EQ(DownloadItem::CANCELLED, download->state());
994 in_progress_.erase(it); 1008 in_progress_.erase(it);
995 // TODO(ahendrickson) -- We don't actually know whether or not we can
996 // remove the download item from the |active_downloads_| map, as there
997 // is no state in |DownloadItem::DownloadState| to indicate that the
998 // downloads system is done with an item. Fix this when we have a
999 // proper final state to check for.
1000 active_downloads_.erase(info.download_id); 1009 active_downloads_.erase(info.download_id);
1001 download_history_->UpdateEntry(download); 1010 download_history_->UpdateEntry(download);
1002 download->UpdateObservers(); 1011 download->UpdateObservers();
1012 } else {
1013 MaybeCompleteDownload(info.download_id);
1003 } 1014 }
1004
1005 UpdateAppIcon();
1006 } 1015 }
1007 1016
1008 void DownloadManager::ShowDownloadInBrowser(const DownloadCreateInfo& info, 1017 void DownloadManager::ShowDownloadInBrowser(const DownloadCreateInfo& info,
1009 DownloadItem* download) { 1018 DownloadItem* download) {
1010 // The 'contents' may no longer exist if the user closed the tab before we 1019 // The 'contents' may no longer exist if the user closed the tab before we
1011 // get this start completion event. If it does, tell the origin TabContents 1020 // get this start completion event. If it does, tell the origin TabContents
1012 // to display its download shelf. 1021 // to display its download shelf.
1013 TabContents* contents = tab_util::GetTabContentsByID(info.child_id, 1022 TabContents* contents = tab_util::GetTabContentsByID(info.child_id,
1014 info.render_view_id); 1023 info.render_view_id);
1015 1024
(...skipping 27 matching lines...) Expand all
1043 return item; 1052 return item;
1044 } 1053 }
1045 return NULL; 1054 return NULL;
1046 } 1055 }
1047 1056
1048 // Confirm that everything in all maps is also in |downloads_|, and that 1057 // Confirm that everything in all maps is also in |downloads_|, and that
1049 // everything in |downloads_| is also in some other map. 1058 // everything in |downloads_| is also in some other map.
1050 void DownloadManager::AssertContainersConsistent() const { 1059 void DownloadManager::AssertContainersConsistent() const {
1051 #if !defined(NDEBUG) 1060 #if !defined(NDEBUG)
1052 // Turn everything into sets. 1061 // Turn everything into sets.
1053 DownloadSet in_progress_set, history_set; 1062 DownloadSet active_set, history_set;
1054 const DownloadMap* input_maps[] = {&active_downloads_, &history_downloads_}; 1063 const DownloadMap* input_maps[] = {&active_downloads_, &history_downloads_};
1055 DownloadSet* local_sets[] = {&in_progress_set, &history_set}; 1064 DownloadSet* local_sets[] = {&active_set, &history_set};
1056 DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(local_sets)); 1065 DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(local_sets));
1057 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) { 1066 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) {
1058 for (DownloadMap::const_iterator it = input_maps[i]->begin(); 1067 for (DownloadMap::const_iterator it = input_maps[i]->begin();
1059 it != input_maps[i]->end(); it++) { 1068 it != input_maps[i]->end(); it++) {
1060 local_sets[i]->insert(&*it->second); 1069 local_sets[i]->insert(&*it->second);
1061 } 1070 }
1062 } 1071 }
1063 1072
1064 // Check if each set is fully present in downloads, and create a union. 1073 // Check if each set is fully present in downloads, and create a union.
1065 const DownloadSet* all_sets[] = {&in_progress_set, &history_set, 1074 const DownloadSet* all_sets[] = {&active_set, &history_set,
1066 &save_page_as_downloads_}; 1075 &save_page_as_downloads_};
1067 DownloadSet downloads_union; 1076 DownloadSet downloads_union;
1068 for (int i = 0; i < static_cast<int>(ARRAYSIZE_UNSAFE(all_sets)); i++) { 1077 for (int i = 0; i < static_cast<int>(ARRAYSIZE_UNSAFE(all_sets)); i++) {
1069 DownloadSet remainder; 1078 DownloadSet remainder;
1070 std::insert_iterator<DownloadSet> insert_it(remainder, remainder.begin()); 1079 std::insert_iterator<DownloadSet> insert_it(remainder, remainder.begin());
1071 std::set_difference(all_sets[i]->begin(), all_sets[i]->end(), 1080 std::set_difference(all_sets[i]->begin(), all_sets[i]->end(),
1072 downloads_.begin(), downloads_.end(), 1081 downloads_.begin(), downloads_.end(),
1073 insert_it); 1082 insert_it);
1074 DCHECK(remainder.empty()); 1083 DCHECK(remainder.empty());
1075 std::insert_iterator<DownloadSet> 1084 std::insert_iterator<DownloadSet>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 observed_download_manager_->RemoveObserver(this); 1120 observed_download_manager_->RemoveObserver(this);
1112 } 1121 }
1113 1122
1114 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1123 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1115 observing_download_manager_->NotifyModelChanged(); 1124 observing_download_manager_->NotifyModelChanged();
1116 } 1125 }
1117 1126
1118 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1127 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1119 observed_download_manager_ = NULL; 1128 observed_download_manager_ = NULL;
1120 } 1129 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698