| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 virtual FilePath GetIntermediatePath( | 128 virtual FilePath GetIntermediatePath( |
| 129 const FilePath& suggested_path) OVERRIDE { | 129 const FilePath& suggested_path) OVERRIDE { |
| 130 return GetTempDownloadPath(suggested_path); | 130 return GetTempDownloadPath(suggested_path); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual void ChooseDownloadPath(WebContents* web_contents, | 133 virtual void ChooseDownloadPath(WebContents* web_contents, |
| 134 const FilePath& suggested_path, | 134 const FilePath& suggested_path, |
| 135 void* data) OVERRIDE { | 135 int32 download_id) OVERRIDE { |
| 136 if (!expected_suggested_path_.empty()) { | 136 if (!expected_suggested_path_.empty()) { |
| 137 EXPECT_STREQ(expected_suggested_path_.value().c_str(), | 137 EXPECT_STREQ(expected_suggested_path_.value().c_str(), |
| 138 suggested_path.value().c_str()); | 138 suggested_path.value().c_str()); |
| 139 } | 139 } |
| 140 if (file_selection_response_.empty()) { | 140 if (file_selection_response_.empty()) { |
| 141 BrowserThread::PostTask( | 141 BrowserThread::PostTask( |
| 142 BrowserThread::UI, FROM_HERE, | 142 BrowserThread::UI, FROM_HERE, |
| 143 base::Bind(&DownloadManager::FileSelectionCanceled, | 143 base::Bind(&DownloadManager::FileSelectionCanceled, |
| 144 download_manager_, | 144 download_manager_, |
| 145 base::Unretained(data))); | 145 download_id)); |
| 146 } else { | 146 } else { |
| 147 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
| 148 BrowserThread::UI, FROM_HERE, | 148 BrowserThread::UI, FROM_HERE, |
| 149 base::Bind(&DownloadManager::FileSelected, | 149 base::Bind(&DownloadManager::FileSelected, |
| 150 download_manager_, | 150 download_manager_, |
| 151 file_selection_response_, | 151 file_selection_response_, |
| 152 base::Unretained(data))); | 152 download_id)); |
| 153 } | 153 } |
| 154 expected_suggested_path_.clear(); | 154 expected_suggested_path_.clear(); |
| 155 file_selection_response_.clear(); | 155 file_selection_response_.clear(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE { | 158 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE { |
| 159 return path.Extension() == FilePath::StringType(FILE_PATH_LITERAL(".pdf")); | 159 return path.Extension() == FilePath::StringType(FILE_PATH_LITERAL(".pdf")); |
| 160 } | 160 } |
| 161 | 161 |
| 162 virtual void AddItemToPersistentStore(DownloadItem* item) OVERRIDE { | 162 virtual void AddItemToPersistentStore(DownloadItem* item) OVERRIDE { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 AddDownloadToFileManager(id, download_file); | 241 AddDownloadToFileManager(id, download_file); |
| 242 ON_CALL(*download_file, GetDownloadManager()) | 242 ON_CALL(*download_file, GetDownloadManager()) |
| 243 .WillByDefault(Return(download_manager_)); | 243 .WillByDefault(Return(download_manager_)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void OnResponseCompleted(int32 download_id, int64 size, | 246 void OnResponseCompleted(int32 download_id, int64 size, |
| 247 const std::string& hash) { | 247 const std::string& hash) { |
| 248 download_manager_->OnResponseCompleted(download_id, size, hash); | 248 download_manager_->OnResponseCompleted(download_id, size, hash); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void FileSelected(const FilePath& path, void* params) { | 251 void FileSelected(const FilePath& path, int32 download_id) { |
| 252 download_manager_->FileSelected(path, params); | 252 download_manager_->FileSelected(path, download_id); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ContinueDownloadWithPath(DownloadItem* download, const FilePath& path) { | 255 void ContinueDownloadWithPath(DownloadItem* download, const FilePath& path) { |
| 256 download_manager_->ContinueDownloadWithPath(download, path); | 256 download_manager_->ContinueDownloadWithPath(download, path); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void UpdateData(int32 id, const char* data, size_t length) { | 259 void UpdateData(int32 id, const char* data, size_t length) { |
| 260 // We are passing ownership of this buffer to the download file manager. | 260 // We are passing ownership of this buffer to the download file manager. |
| 261 net::IOBuffer* io_buffer = new net::IOBuffer(length); | 261 net::IOBuffer* io_buffer = new net::IOBuffer(length); |
| 262 // We need |AddRef()| because we do a |Release()| in |UpdateDownload()|. | 262 // We need |AddRef()| because we do a |Release()| in |UpdateDownload()|. |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 .Times(1) | 904 .Times(1) |
| 905 .WillOnce(Return(net::OK)); | 905 .WillOnce(Return(net::OK)); |
| 906 } | 906 } |
| 907 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); | 907 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); |
| 908 DownloadItem* download = GetActiveDownloadItem(i); | 908 DownloadItem* download = GetActiveDownloadItem(i); |
| 909 ASSERT_TRUE(download != NULL); | 909 ASSERT_TRUE(download != NULL); |
| 910 DownloadStateInfo state = download->GetStateInfo(); | 910 DownloadStateInfo state = download->GetStateInfo(); |
| 911 state.danger = kDownloadRenameCases[i].danger; | 911 state.danger = kDownloadRenameCases[i].danger; |
| 912 download->SetFileCheckResults(state); | 912 download->SetFileCheckResults(state); |
| 913 | 913 |
| 914 int32* id_ptr = new int32; | |
| 915 *id_ptr = i; // Deleted in FileSelected(). | |
| 916 if (kDownloadRenameCases[i].finish_before_rename) { | 914 if (kDownloadRenameCases[i].finish_before_rename) { |
| 917 OnResponseCompleted(i, 1024, std::string("fake_hash")); | 915 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
| 918 message_loop_.RunAllPending(); | 916 message_loop_.RunAllPending(); |
| 919 FileSelected(new_path, id_ptr); | 917 FileSelected(new_path, i); |
| 920 } else { | 918 } else { |
| 921 FileSelected(new_path, id_ptr); | 919 FileSelected(new_path, i); |
| 922 message_loop_.RunAllPending(); | 920 message_loop_.RunAllPending(); |
| 923 OnResponseCompleted(i, 1024, std::string("fake_hash")); | 921 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
| 924 } | 922 } |
| 925 // Validating the download item, so it will complete. | 923 // Validating the download item, so it will complete. |
| 926 if (state.danger == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE) | 924 if (state.danger == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE) |
| 927 download->DangerousDownloadValidated(); | 925 download->DangerousDownloadValidated(); |
| 928 message_loop_.RunAllPending(); | 926 message_loop_.RunAllPending(); |
| 929 } | 927 } |
| 930 } | 928 } |
| 931 | 929 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1301 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1304 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1302 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1305 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1306 EXPECT_TRUE(observer->was_updated()); | 1304 EXPECT_TRUE(observer->was_updated()); |
| 1307 EXPECT_FALSE(observer->was_opened()); | 1305 EXPECT_FALSE(observer->was_opened()); |
| 1308 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1306 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1309 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1307 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1310 | 1308 |
| 1311 EXPECT_FALSE(file_util::PathExists(new_path)); | 1309 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1312 } | 1310 } |
| OLD | NEW |