| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/download/download_file.h" | 10 #include "chrome/browser/download/download_file.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 namespace { | 151 namespace { |
| 152 | 152 |
| 153 const struct { | 153 const struct { |
| 154 FilePath::StringType suggested_path; | 154 FilePath::StringType suggested_path; |
| 155 bool is_dangerous; | 155 bool is_dangerous; |
| 156 bool finish_before_rename; | 156 bool finish_before_rename; |
| 157 bool will_delete_crdownload; | 157 bool will_delete_crdownload; |
| 158 int expected_rename_count; | 158 int expected_rename_count; |
| 159 } kDownloadRenameCases[] = { | 159 } kDownloadRenameCases[] = { |
| 160 // Safe download, download finishes BEFORE rename. | 160 // Safe download, download finishes BEFORE file name determined. |
| 161 // Needs to be renamed only once. Crdownload file needs to be deleted. | 161 // Renamed twice (linear path through UI). Crdownload file does not need |
| 162 // to be deleted. |
| 162 { FILE_PATH_LITERAL("foo.zip"), | 163 { FILE_PATH_LITERAL("foo.zip"), |
| 163 false, | 164 false, |
| 164 true, | 165 true, |
| 165 true, | 166 false, |
| 166 1, }, | 167 2, }, |
| 167 // Dangerous download, download finishes BEFORE rename. | 168 // Dangerous download, download finishes BEFORE file name determined. |
| 168 // Needs to be renamed only once. | 169 // Needs to be renamed only once. |
| 169 { FILE_PATH_LITERAL("unconfirmed xxx.crdownload"), | 170 { FILE_PATH_LITERAL("unconfirmed xxx.crdownload"), |
| 170 true, | 171 true, |
| 171 true, | 172 true, |
| 172 false, | 173 false, |
| 173 1, }, | 174 1, }, |
| 174 // Safe download, download finishes AFTER rename. | 175 // Safe download, download finishes AFTER file name determined. |
| 175 // Needs to be renamed twice. | 176 // Needs to be renamed twice. |
| 176 { FILE_PATH_LITERAL("foo.zip"), | 177 { FILE_PATH_LITERAL("foo.zip"), |
| 177 false, | 178 false, |
| 178 false, | 179 false, |
| 179 false, | 180 false, |
| 180 2, }, | 181 2, }, |
| 181 // Dangerous download, download finishes AFTER rename. | 182 // Dangerous download, download finishes AFTER file name determined. |
| 182 // Needs to be renamed only once. | 183 // Needs to be renamed only once. |
| 183 { FILE_PATH_LITERAL("unconfirmed xxx.crdownload"), | 184 { FILE_PATH_LITERAL("unconfirmed xxx.crdownload"), |
| 184 true, | 185 true, |
| 185 false, | 186 false, |
| 186 false, | 187 false, |
| 187 1, }, | 188 1, }, |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 class MockDownloadFile : public DownloadFile { | 191 class MockDownloadFile : public DownloadFile { |
| 191 public: | 192 public: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 download_manager_->OnAllDataSaved(i, 1024); | 259 download_manager_->OnAllDataSaved(i, 1024); |
| 259 download_manager_->FileSelected(new_path, i, info); | 260 download_manager_->FileSelected(new_path, i, info); |
| 260 } else { | 261 } else { |
| 261 download_manager_->FileSelected(new_path, i, info); | 262 download_manager_->FileSelected(new_path, i, info); |
| 262 download_manager_->OnAllDataSaved(i, 1024); | 263 download_manager_->OnAllDataSaved(i, 1024); |
| 263 } | 264 } |
| 264 | 265 |
| 265 message_loop_.RunAllPending(); | 266 message_loop_.RunAllPending(); |
| 266 } | 267 } |
| 267 } | 268 } |
| OLD | NEW |