| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/pickle.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/string16.h" | 15 #include "base/string16.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 19 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 19 #include "chrome/browser/download/download_item_model.h" | 20 #include "chrome/browser/download/download_item_model.h" |
| 20 #include "chrome/browser/download/download_prefs.h" | 21 #include "chrome/browser/download/download_prefs.h" |
| 21 #include "chrome/browser/download/download_util.h" | 22 #include "chrome/browser/download/download_util.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 109 BrowserThread::FILE, FROM_HERE, | 110 BrowserThread::FILE, FROM_HERE, |
| 110 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), | 111 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), |
| 111 DownloadId(kValidIdDomain, id), download_buffer_)); | 112 DownloadId(kValidIdDomain, id), download_buffer_)); |
| 112 | 113 |
| 113 message_loop_.RunAllPending(); | 114 message_loop_.RunAllPending(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void OnDownloadInterrupted(int32 download_id, int64 size, | 117 void OnDownloadInterrupted(int32 download_id, int64 size, |
| 118 const Pickle& hash_state, |
| 117 InterruptReason reason) { | 119 InterruptReason reason) { |
| 118 download_manager_->OnDownloadInterrupted(download_id, size, reason); | 120 download_manager_->OnDownloadInterrupted(download_id, size, |
| 121 hash_state, reason); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Get the download item with ID |id|. | 124 // Get the download item with ID |id|. |
| 122 DownloadItem* GetActiveDownloadItem(int32 id) { | 125 DownloadItem* GetActiveDownloadItem(int32 id) { |
| 123 return download_manager_->GetActiveDownload(id); | 126 return download_manager_->GetActiveDownload(id); |
| 124 } | 127 } |
| 125 | 128 |
| 126 protected: | 129 protected: |
| 127 DownloadStatusUpdater download_status_updater_; | 130 DownloadStatusUpdater download_status_updater_; |
| 128 scoped_ptr<TestingProfile> profile_; | 131 scoped_ptr<TestingProfile> profile_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 177 } |
| 175 | 178 |
| 176 return function_error; | 179 return function_error; |
| 177 } | 180 } |
| 178 | 181 |
| 179 net::Error forced_error_; | 182 net::Error forced_error_; |
| 180 }; | 183 }; |
| 181 | 184 |
| 182 DownloadFileWithErrors::DownloadFileWithErrors(DownloadCreateInfo* info, | 185 DownloadFileWithErrors::DownloadFileWithErrors(DownloadCreateInfo* info, |
| 183 DownloadManager* manager) | 186 DownloadManager* manager) |
| 184 : DownloadFileImpl(info, new DownloadRequestHandle(), manager), | 187 : DownloadFileImpl(info, new DownloadRequestHandle(), manager, Pickle()), |
| 185 forced_error_(net::OK) { | 188 forced_error_(net::OK) { |
| 186 } | 189 } |
| 187 | 190 |
| 188 net::Error DownloadFileWithErrors::Initialize(bool calculate_hash) { | 191 net::Error DownloadFileWithErrors::Initialize(bool calculate_hash) { |
| 189 return ReturnError(DownloadFileImpl::Initialize(calculate_hash)); | 192 return ReturnError(DownloadFileImpl::Initialize(calculate_hash)); |
| 190 } | 193 } |
| 191 | 194 |
| 192 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, | 195 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, |
| 193 size_t data_len) { | 196 size_t data_len) { |
| 194 return ReturnError(DownloadFileImpl::AppendDataToFile(data, data_len)); | 197 return ReturnError(DownloadFileImpl::AppendDataToFile(data, data_len)); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // don't call the function that deletes it, so we do so ourselves. | 370 // don't call the function that deletes it, so we do so ourselves. |
| 368 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 371 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 369 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i)); | 372 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i)); |
| 370 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; | 373 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; |
| 371 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); | 374 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); |
| 372 info->mime_type = kStartDownloadCases[i].mime_type; | 375 info->mime_type = kStartDownloadCases[i].mime_type; |
| 373 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); | 376 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); |
| 374 | 377 |
| 375 DownloadFile* download_file( | 378 DownloadFile* download_file( |
| 376 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 379 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 377 download_manager_)); | 380 download_manager_, Pickle())); |
| 378 AddDownloadToFileManager(info->download_id.local(), download_file); | 381 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 379 download_file->Initialize(false); | 382 download_file->Initialize(false); |
| 380 download_manager_->StartDownload(info->download_id.local()); | 383 download_manager_->StartDownload(info->download_id.local()); |
| 381 message_loop_.RunAllPending(); | 384 message_loop_.RunAllPending(); |
| 382 | 385 |
| 383 // SelectFileObserver will have recorded any attempt to open the | 386 // SelectFileObserver will have recorded any attempt to open the |
| 384 // select file dialog. | 387 // select file dialog. |
| 385 // Note that DownloadManager::FileSelectionCanceled() is never called. | 388 // Note that DownloadManager::FileSelectionCanceled() is never called. |
| 386 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, | 389 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, |
| 387 observer.ShowedFileDialogForId(i)); | 390 observer.ShowedFileDialogForId(i)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 489 |
| 487 download_file->AppendDataToFile(kTestData, kTestDataLen); | 490 download_file->AppendDataToFile(kTestData, kTestDataLen); |
| 488 | 491 |
| 489 ContinueDownloadWithPath(download, new_path); | 492 ContinueDownloadWithPath(download, new_path); |
| 490 message_loop_.RunAllPending(); | 493 message_loop_.RunAllPending(); |
| 491 EXPECT_EQ(1, | 494 EXPECT_EQ(1, |
| 492 recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)); | 495 recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)); |
| 493 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 496 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 494 | 497 |
| 495 int64 error_size = 3; | 498 int64 error_size = 3; |
| 496 OnDownloadInterrupted(0, error_size, | 499 OnDownloadInterrupted(0, error_size, Pickle(), |
| 497 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); | 500 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); |
| 498 message_loop_.RunAllPending(); | 501 message_loop_.RunAllPending(); |
| 499 | 502 |
| 500 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 503 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 501 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 504 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 502 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | 505 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 503 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | 506 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
| 504 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 507 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 505 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 508 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 506 EXPECT_TRUE(observer->was_updated()); | 509 EXPECT_TRUE(observer->was_updated()); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 | 729 |
| 727 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 730 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 728 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 731 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 729 | 732 |
| 730 // Create and initialize the download file. We're bypassing the first part | 733 // Create and initialize the download file. We're bypassing the first part |
| 731 // of the download process and skipping to the part after the final file | 734 // of the download process and skipping to the part after the final file |
| 732 // name has been chosen, so we need to initialize the download file | 735 // name has been chosen, so we need to initialize the download file |
| 733 // properly. | 736 // properly. |
| 734 DownloadFile* download_file( | 737 DownloadFile* download_file( |
| 735 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 738 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 736 download_manager_)); | 739 download_manager_, Pickle())); |
| 737 download_file->Rename(cr_path); | 740 download_file->Rename(cr_path); |
| 738 // This creates the .crdownload version of the file. | 741 // This creates the .crdownload version of the file. |
| 739 download_file->Initialize(false); | 742 download_file->Initialize(false); |
| 740 // |download_file| is owned by DownloadFileManager. | 743 // |download_file| is owned by DownloadFileManager. |
| 741 AddDownloadToFileManager(info->download_id.local(), download_file); | 744 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 742 | 745 |
| 743 ContinueDownloadWithPath(download, new_path); | 746 ContinueDownloadWithPath(download, new_path); |
| 744 message_loop_.RunAllPending(); | 747 message_loop_.RunAllPending(); |
| 745 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 748 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 746 | 749 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 806 |
| 804 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 807 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 805 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 808 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 806 | 809 |
| 807 // Create and initialize the download file. We're bypassing the first part | 810 // Create and initialize the download file. We're bypassing the first part |
| 808 // of the download process and skipping to the part after the final file | 811 // of the download process and skipping to the part after the final file |
| 809 // name has been chosen, so we need to initialize the download file | 812 // name has been chosen, so we need to initialize the download file |
| 810 // properly. | 813 // properly. |
| 811 DownloadFile* download_file( | 814 DownloadFile* download_file( |
| 812 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 815 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 813 download_manager_)); | 816 download_manager_, Pickle())); |
| 814 download_file->Rename(cr_path); | 817 download_file->Rename(cr_path); |
| 815 // This creates the .crdownload version of the file. | 818 // This creates the .crdownload version of the file. |
| 816 download_file->Initialize(false); | 819 download_file->Initialize(false); |
| 817 // |download_file| is owned by DownloadFileManager. | 820 // |download_file| is owned by DownloadFileManager. |
| 818 AddDownloadToFileManager(info->download_id.local(), download_file); | 821 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 819 | 822 |
| 820 ContinueDownloadWithPath(download, new_path); | 823 ContinueDownloadWithPath(download, new_path); |
| 821 message_loop_.RunAllPending(); | 824 message_loop_.RunAllPending(); |
| 822 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 825 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 823 | 826 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 859 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 857 EXPECT_TRUE(observer->was_updated()); | 860 EXPECT_TRUE(observer->was_updated()); |
| 858 EXPECT_FALSE(observer->was_opened()); | 861 EXPECT_FALSE(observer->was_opened()); |
| 859 EXPECT_TRUE(download->file_externally_removed()); | 862 EXPECT_TRUE(download->file_externally_removed()); |
| 860 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 863 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 861 EXPECT_EQ(download_item_model->GetStatusText(), | 864 EXPECT_EQ(download_item_model->GetStatusText(), |
| 862 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 865 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 863 | 866 |
| 864 EXPECT_FALSE(file_util::PathExists(new_path)); | 867 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 865 } | 868 } |
| OLD | NEW |