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

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 10069014: Save Page As MHTML (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: avoid re-entering Created 8 years, 8 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) 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 "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 downloads_.insert(download); 437 downloads_.insert(download);
438 active_downloads_[download_id] = download; 438 active_downloads_[download_id] = download;
439 439
440 return bound_net_log; 440 return bound_net_log;
441 } 441 }
442 442
443 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem( 443 DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem(
444 const FilePath& main_file_path, 444 const FilePath& main_file_path,
445 const GURL& page_url, 445 const GURL& page_url,
446 bool is_otr, 446 bool is_otr,
447 const std::string& mime_type,
447 DownloadItem::Observer* observer) { 448 DownloadItem::Observer* observer) {
448 net::BoundNetLog bound_net_log = 449 net::BoundNetLog bound_net_log =
449 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); 450 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
450 DownloadItem* download = new DownloadItemImpl( 451 DownloadItem* download = new DownloadItemImpl(
451 this, main_file_path, page_url, is_otr, GetNextId(), bound_net_log); 452 this,
453 main_file_path,
454 page_url,
455 is_otr,
456 GetNextId(),
457 mime_type,
458 bound_net_log);
452 459
453 download->AddObserver(observer); 460 download->AddObserver(observer);
454 461
455 DCHECK(!ContainsKey(save_page_downloads_, download->GetId())); 462 DCHECK(!ContainsKey(save_page_downloads_, download->GetId()));
456 downloads_.insert(download); 463 downloads_.insert(download);
457 save_page_downloads_[download->GetId()] = download; 464 save_page_downloads_[download->GetId()] = download;
458 465
459 // Will notify the observer in the callback. 466 // Will notify the observer in the callback.
460 delegate_->AddItemToPersistentStore(download); 467 delegate_->AddItemToPersistentStore(download);
461 468
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 618
612 // If the download hasn't been inserted into the history system 619 // If the download hasn't been inserted into the history system
613 // (which occurs strictly after file name determination, intermediate 620 // (which occurs strictly after file name determination, intermediate
614 // file rename, and UI display) then it's not ready for completion. 621 // file rename, and UI display) then it's not ready for completion.
615 if (!download->IsPersisted()) 622 if (!download->IsPersisted())
616 return false; 623 return false;
617 624
618 return true; 625 return true;
619 } 626 }
620 627
628 // When SavePackage downloads MHTML to GData (see
629 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it
630 // does for non-SavePackage downloads, but SavePackage downloads never satisfy
631 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls
632 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage
633 // notices that the upload has completed and runs its normal Finish() pathway.
634 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes
635 // downloads. SavePackage always uses its own Finish() to mark downloads
636 // complete.
Randy Smith (Not in Mondays) 2012/04/27 18:24:04 Is there a way to do this via callback so that we
benjhayden 2012/04/28 19:09:03 SavePackage could pass base::Bind(&SavePackage::Ma
637
621 void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) { 638 void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) {
622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
623 VLOG(20) << __FUNCTION__ << "()" << " download = " 640 VLOG(20) << __FUNCTION__ << "()" << " download = "
624 << download->DebugString(false); 641 << download->DebugString(false);
625 642
626 if (!IsDownloadReadyForCompletion(download)) 643 if (!IsDownloadReadyForCompletion(download))
627 return; 644 return;
628 645
629 // TODO(rdsmith): DCHECK that we only pass through this point 646 // TODO(rdsmith): DCHECK that we only pass through this point
630 // once per download. The natural way to do this is by a state 647 // once per download. The natural way to do this is by a state
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 if (it->second->IsComplete() && !it->second->GetOpened()) 1225 if (it->second->IsComplete() && !it->second->GetOpened())
1209 ++num_unopened; 1226 ++num_unopened;
1210 } 1227 }
1211 download_stats::RecordOpensOutstanding(num_unopened); 1228 download_stats::RecordOpensOutstanding(num_unopened);
1212 } 1229 }
1213 1230
1214 void DownloadManagerImpl::SetFileManagerForTesting( 1231 void DownloadManagerImpl::SetFileManagerForTesting(
1215 DownloadFileManager* file_manager) { 1232 DownloadFileManager* file_manager) {
1216 file_manager_ = file_manager; 1233 file_manager_ = file_manager;
1217 } 1234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698