| 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 <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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 DownloadFileWithErrors::DownloadFileWithErrors( | 387 DownloadFileWithErrors::DownloadFileWithErrors( |
| 388 DownloadCreateInfo* info, | 388 DownloadCreateInfo* info, |
| 389 scoped_ptr<content::ByteStreamReader> stream, | 389 scoped_ptr<content::ByteStreamReader> stream, |
| 390 DownloadManager* manager, | 390 DownloadManager* manager, |
| 391 bool calculate_hash) | 391 bool calculate_hash) |
| 392 : DownloadFileImpl(info, | 392 : DownloadFileImpl(info, |
| 393 stream.Pass(), | 393 stream.Pass(), |
| 394 new DownloadRequestHandle(), | 394 new DownloadRequestHandle(), |
| 395 manager, | 395 manager, |
| 396 calculate_hash, | 396 calculate_hash, |
| 397 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 397 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 398 net::BoundNetLog()), | 398 net::BoundNetLog()), |
| 399 forced_error_(net::OK) { | 399 forced_error_(net::OK) { |
| 400 } | 400 } |
| 401 | 401 |
| 402 net::Error DownloadFileWithErrors::Initialize() { | 402 net::Error DownloadFileWithErrors::Initialize() { |
| 403 return ReturnError(DownloadFileImpl::Initialize()); | 403 return ReturnError(DownloadFileImpl::Initialize()); |
| 404 } | 404 } |
| 405 | 405 |
| 406 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, | 406 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, |
| 407 size_t data_len) { | 407 size_t data_len) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 scoped_ptr<content::ByteStreamReader> stream_reader; | 558 scoped_ptr<content::ByteStreamReader> stream_reader; |
| 559 content::CreateByteStream(message_loop_.message_loop_proxy(), | 559 content::CreateByteStream(message_loop_.message_loop_proxy(), |
| 560 message_loop_.message_loop_proxy(), | 560 message_loop_.message_loop_proxy(), |
| 561 kTestDataLen, &stream_writer, &stream_reader); | 561 kTestDataLen, &stream_writer, &stream_reader); |
| 562 | 562 |
| 563 DownloadFile* download_file( | 563 DownloadFile* download_file( |
| 564 new DownloadFileImpl(info.get(), | 564 new DownloadFileImpl(info.get(), |
| 565 stream_reader.Pass(), | 565 stream_reader.Pass(), |
| 566 new DownloadRequestHandle(), | 566 new DownloadRequestHandle(), |
| 567 download_manager_, false, | 567 download_manager_, false, |
| 568 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 568 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 569 net::BoundNetLog())); | 569 net::BoundNetLog())); |
| 570 AddDownloadToFileManager(info->download_id, download_file); | 570 AddDownloadToFileManager(info->download_id, download_file); |
| 571 download_file->Initialize(); | 571 download_file->Initialize(); |
| 572 download_manager_->StartDownload(info->download_id.local()); | 572 download_manager_->StartDownload(info->download_id.local()); |
| 573 message_loop_.RunAllPending(); | 573 message_loop_.RunAllPending(); |
| 574 | 574 |
| 575 // SelectFileObserver will have recorded any attempt to open the | 575 // SelectFileObserver will have recorded any attempt to open the |
| 576 // select file dialog. | 576 // select file dialog. |
| 577 // Note that DownloadManager::FileSelectionCanceled() is never called. | 577 // Note that DownloadManager::FileSelectionCanceled() is never called. |
| 578 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, | 578 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 1124 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 1125 | 1125 |
| 1126 // Create and initialize the download file. We're bypassing the first part | 1126 // Create and initialize the download file. We're bypassing the first part |
| 1127 // of the download process and skipping to the part after the final file | 1127 // of the download process and skipping to the part after the final file |
| 1128 // name has been chosen, so we need to initialize the download file | 1128 // name has been chosen, so we need to initialize the download file |
| 1129 // properly. | 1129 // properly. |
| 1130 DownloadFile* download_file( | 1130 DownloadFile* download_file( |
| 1131 new DownloadFileImpl(info.get(), stream_output.Pass(), | 1131 new DownloadFileImpl(info.get(), stream_output.Pass(), |
| 1132 new DownloadRequestHandle(), | 1132 new DownloadRequestHandle(), |
| 1133 download_manager_, false, | 1133 download_manager_, false, |
| 1134 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 1134 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 1135 net::BoundNetLog())); | 1135 net::BoundNetLog())); |
| 1136 download_file->Rename(cr_path); | 1136 download_file->Rename(cr_path); |
| 1137 // This creates the .temp version of the file. | 1137 // This creates the .temp version of the file. |
| 1138 download_file->Initialize(); | 1138 download_file->Initialize(); |
| 1139 // |download_file| is owned by DownloadFileManager. | 1139 // |download_file| is owned by DownloadFileManager. |
| 1140 AddDownloadToFileManager(info->download_id, download_file); | 1140 AddDownloadToFileManager(info->download_id, download_file); |
| 1141 | 1141 |
| 1142 ContinueDownloadWithPath(download, new_path); | 1142 ContinueDownloadWithPath(download, new_path); |
| 1143 message_loop_.RunAllPending(); | 1143 message_loop_.RunAllPending(); |
| 1144 EXPECT_TRUE(GetActiveDownloadItem(info->download_id) != NULL); | 1144 EXPECT_TRUE(GetActiveDownloadItem(info->download_id) != NULL); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 1203 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 1204 | 1204 |
| 1205 // Create and initialize the download file. We're bypassing the first part | 1205 // Create and initialize the download file. We're bypassing the first part |
| 1206 // of the download process and skipping to the part after the final file | 1206 // of the download process and skipping to the part after the final file |
| 1207 // name has been chosen, so we need to initialize the download file | 1207 // name has been chosen, so we need to initialize the download file |
| 1208 // properly. | 1208 // properly. |
| 1209 DownloadFile* download_file( | 1209 DownloadFile* download_file( |
| 1210 new DownloadFileImpl(info.get(), stream_output.Pass(), | 1210 new DownloadFileImpl(info.get(), stream_output.Pass(), |
| 1211 new DownloadRequestHandle(), | 1211 new DownloadRequestHandle(), |
| 1212 download_manager_, false, | 1212 download_manager_, false, |
| 1213 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 1213 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 1214 net::BoundNetLog())); | 1214 net::BoundNetLog())); |
| 1215 download_file->Rename(cr_path); | 1215 download_file->Rename(cr_path); |
| 1216 // This creates the .temp version of the file. | 1216 // This creates the .temp version of the file. |
| 1217 download_file->Initialize(); | 1217 download_file->Initialize(); |
| 1218 // |download_file| is owned by DownloadFileManager. | 1218 // |download_file| is owned by DownloadFileManager. |
| 1219 AddDownloadToFileManager(info->download_id, download_file); | 1219 AddDownloadToFileManager(info->download_id, download_file); |
| 1220 | 1220 |
| 1221 ContinueDownloadWithPath(download, new_path); | 1221 ContinueDownloadWithPath(download, new_path); |
| 1222 message_loop_.RunAllPending(); | 1222 message_loop_.RunAllPending(); |
| 1223 EXPECT_TRUE(GetActiveDownloadItem(info->download_id) != NULL); | 1223 EXPECT_TRUE(GetActiveDownloadItem(info->download_id) != NULL); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1254 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1254 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1255 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1255 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1256 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1256 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1257 EXPECT_TRUE(observer->was_updated()); | 1257 EXPECT_TRUE(observer->was_updated()); |
| 1258 EXPECT_FALSE(observer->was_opened()); | 1258 EXPECT_FALSE(observer->was_opened()); |
| 1259 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1259 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1260 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1260 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1261 | 1261 |
| 1262 EXPECT_FALSE(file_util::PathExists(new_path)); | 1262 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1263 } | 1263 } |
| OLD | NEW |