| 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 "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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 net::UploadOwnedBytesElementReader::CreateWithString(body)); | 64 net::UploadOwnedBytesElementReader::CreateWithString(body)); |
| 65 request->set_upload(make_scoped_ptr( | 65 request->set_upload(make_scoped_ptr( |
| 66 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); | 66 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 67 } | 67 } |
| 68 if (params->post_id() >= 0) { | 68 if (params->post_id() >= 0) { |
| 69 // The POST in this case does not have an actual body, and only works | 69 // The POST in this case does not have an actual body, and only works |
| 70 // when retrieving data from cache. This is done because we don't want | 70 // when retrieving data from cache. This is done because we don't want |
| 71 // to do a re-POST without user consent, and currently don't have a good | 71 // to do a re-POST without user consent, and currently don't have a good |
| 72 // plan on how to display the UI for that. | 72 // plan on how to display the UI for that. |
| 73 DCHECK(params->prefer_cache()); | 73 DCHECK(params->prefer_cache()); |
| 74 DCHECK(params->method() == "POST"); | 74 DCHECK_EQ("POST", params->method()); |
| 75 ScopedVector<net::UploadElementReader> element_readers; | 75 ScopedVector<net::UploadElementReader> element_readers; |
| 76 request->set_upload(make_scoped_ptr( | 76 request->set_upload(make_scoped_ptr( |
| 77 new net::UploadDataStream(element_readers.Pass(), params->post_id()))); | 77 new net::UploadDataStream(element_readers.Pass(), params->post_id()))); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // If we're not at the beginning of the file, retrieve only the remaining | 80 // If we're not at the beginning of the file, retrieve only the remaining |
| 81 // portion. | 81 // portion. |
| 82 bool has_last_modified = !params->last_modified().empty(); | 82 bool has_last_modified = !params->last_modified().empty(); |
| 83 bool has_etag = !params->etag().empty(); | 83 bool has_etag = !params->etag().empty(); |
| 84 | 84 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 if (has_etag) { | 101 if (has_etag) { |
| 102 request->SetExtraRequestHeaderByName("If-Match", params->etag(), true); | 102 request->SetExtraRequestHeaderByName("If-Match", params->etag(), true); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter | 106 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter |
| 107 = params->request_headers_begin(); | 107 = params->request_headers_begin(); |
| 108 iter != params->request_headers_end(); | 108 iter != params->request_headers_end(); |
| 109 ++iter) { | 109 ++iter) { |
| 110 request->SetExtraRequestHeaderByName( | 110 request->SetExtraRequestHeaderByName( |
| 111 iter->first, iter->second, false/*overwrite*/); | 111 iter->first, iter->second, false /*overwrite*/); |
| 112 } | 112 } |
| 113 | 113 |
| 114 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 114 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 115 save_info->file_path = params->file_path(); | 115 save_info->file_path = params->file_path(); |
| 116 save_info->suggested_name = params->suggested_name(); | 116 save_info->suggested_name = params->suggested_name(); |
| 117 save_info->offset = params->offset(); | 117 save_info->offset = params->offset(); |
| 118 save_info->hash_state = params->hash_state(); | 118 save_info->hash_state = params->hash_state(); |
| 119 save_info->prompt_for_save_location = params->prompt(); | 119 save_info->prompt_for_save_location = params->prompt(); |
| 120 save_info->file_stream = params->GetFileStream(); | 120 save_info->file_stream = params->GetFileStream(); |
| 121 | 121 |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 554 |
| 555 DownloadFileFactory* DownloadManagerImpl::GetDownloadFileFactoryForTesting() { | 555 DownloadFileFactory* DownloadManagerImpl::GetDownloadFileFactoryForTesting() { |
| 556 return file_factory_.get(); | 556 return file_factory_.get(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { | 559 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { |
| 560 if (!download) | 560 if (!download) |
| 561 return; | 561 return; |
| 562 | 562 |
| 563 uint32 download_id = download->GetId(); | 563 uint32 download_id = download->GetId(); |
| 564 if (downloads_.find(download_id) == downloads_.end()) | 564 if (downloads_.erase(download_id) == 0) |
| 565 return; | 565 return; |
| 566 | |
| 567 delete download; | 566 delete download; |
| 568 downloads_.erase(download_id); | |
| 569 } | 567 } |
| 570 | 568 |
| 571 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, | 569 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, |
| 572 base::Time remove_end) { | 570 base::Time remove_end) { |
| 573 int count = 0; | 571 int count = 0; |
| 574 DownloadMap::const_iterator it = downloads_.begin(); | 572 DownloadMap::const_iterator it = downloads_.begin(); |
| 575 while (it != downloads_.end()) { | 573 while (it != downloads_.end()) { |
| 576 DownloadItemImpl* download = it->second; | 574 DownloadItemImpl* download = it->second; |
| 577 | 575 |
| 578 // Increment done here to protect against invalidation below. | 576 // Increment done here to protect against invalidation below. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 598 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); | 596 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); |
| 599 RecordClearAllSize(num_deleted); | 597 RecordClearAllSize(num_deleted); |
| 600 return num_deleted; | 598 return num_deleted; |
| 601 } | 599 } |
| 602 | 600 |
| 603 void DownloadManagerImpl::DownloadUrl( | 601 void DownloadManagerImpl::DownloadUrl( |
| 604 scoped_ptr<DownloadUrlParameters> params) { | 602 scoped_ptr<DownloadUrlParameters> params) { |
| 605 if (params->post_id() >= 0) { | 603 if (params->post_id() >= 0) { |
| 606 // Check this here so that the traceback is more useful. | 604 // Check this here so that the traceback is more useful. |
| 607 DCHECK(params->prefer_cache()); | 605 DCHECK(params->prefer_cache()); |
| 608 DCHECK(params->method() == "POST"); | 606 DCHECK_EQ("POST", params->method()); |
| 609 } | 607 } |
| 610 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 608 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 611 &BeginDownload, base::Passed(¶ms), | 609 &BeginDownload, base::Passed(¶ms), |
| 612 content::DownloadItem::kInvalidId)); | 610 content::DownloadItem::kInvalidId)); |
| 613 } | 611 } |
| 614 | 612 |
| 615 void DownloadManagerImpl::AddObserver(Observer* observer) { | 613 void DownloadManagerImpl::AddObserver(Observer* observer) { |
| 616 observers_.AddObserver(observer); | 614 observers_.AddObserver(observer); |
| 617 } | 615 } |
| 618 | 616 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 629 const base::Time& start_time, | 627 const base::Time& start_time, |
| 630 const base::Time& end_time, | 628 const base::Time& end_time, |
| 631 const std::string& etag, | 629 const std::string& etag, |
| 632 const std::string& last_modified, | 630 const std::string& last_modified, |
| 633 int64 received_bytes, | 631 int64 received_bytes, |
| 634 int64 total_bytes, | 632 int64 total_bytes, |
| 635 DownloadItem::DownloadState state, | 633 DownloadItem::DownloadState state, |
| 636 DownloadDangerType danger_type, | 634 DownloadDangerType danger_type, |
| 637 DownloadInterruptReason interrupt_reason, | 635 DownloadInterruptReason interrupt_reason, |
| 638 bool opened) { | 636 bool opened) { |
| 639 DCHECK(!ContainsKey(downloads_, id)); | 637 if (ContainsKey(downloads_, id)) { |
| 640 if (ContainsKey(downloads_, id)) | 638 NOTREACHED(); |
| 641 return NULL; | 639 return NULL; |
| 640 } |
| 642 DownloadItemImpl* item = item_factory_->CreatePersistedItem( | 641 DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
| 643 this, | 642 this, |
| 644 id, | 643 id, |
| 645 current_path, | 644 current_path, |
| 646 target_path, | 645 target_path, |
| 647 url_chain, | 646 url_chain, |
| 648 referrer_url, | 647 referrer_url, |
| 649 start_time, | 648 start_time, |
| 650 end_time, | 649 end_time, |
| 651 etag, | 650 etag, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 if (delegate_) | 711 if (delegate_) |
| 713 delegate_->OpenDownload(download); | 712 delegate_->OpenDownload(download); |
| 714 } | 713 } |
| 715 | 714 |
| 716 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 715 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 717 if (delegate_) | 716 if (delegate_) |
| 718 delegate_->ShowDownloadInShell(download); | 717 delegate_->ShowDownloadInShell(download); |
| 719 } | 718 } |
| 720 | 719 |
| 721 } // namespace content | 720 } // namespace content |
| OLD | NEW |