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 "content/browser/download/download_file_manager.h" | 5 #include "content/browser/download/download_file_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Life of |info| ends here. No more references to it after this method. | 58 // Life of |info| ends here. No more references to it after this method. |
59 scoped_ptr<DownloadCreateInfo> infop(info); | 59 scoped_ptr<DownloadCreateInfo> infop(info); |
60 | 60 |
61 scoped_ptr<DownloadFile> | 61 scoped_ptr<DownloadFile> |
62 download_file(new DownloadFile(info, download_manager)); | 62 download_file(new DownloadFile(info, download_manager)); |
63 if (!download_file->Initialize(get_hash)) { | 63 if (!download_file->Initialize(get_hash)) { |
64 info->request_handle.CancelRequest(); | 64 info->request_handle.CancelRequest(); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 DownloadId global_id(download_manager, info->download_id); | 68 int32 id = info->download_id; |
69 DCHECK(GetDownloadFile(global_id) == NULL); | 69 DCHECK(GetDownloadFile(id) == NULL); |
70 downloads_[global_id] = download_file.release(); | 70 downloads_[id] = download_file.release(); |
71 | 71 |
72 // The file is now ready, we can un-pause the request and start saving data. | 72 // The file is now ready, we can un-pause the request and start saving data. |
73 info->request_handle.ResumeRequest(); | 73 info->request_handle.ResumeRequest(); |
74 | 74 |
75 StartUpdateTimer(); | 75 StartUpdateTimer(); |
76 | 76 |
77 BrowserThread::PostTask( | 77 BrowserThread::PostTask( |
78 BrowserThread::UI, FROM_HERE, | 78 BrowserThread::UI, FROM_HERE, |
79 NewRunnableMethod(download_manager, | 79 NewRunnableMethod(download_manager, |
80 &DownloadManager::StartDownload, info->download_id)); | 80 &DownloadManager::StartDownload, id)); |
81 } | 81 } |
82 | 82 |
83 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { | 83 DownloadFile* DownloadFileManager::GetDownloadFile(int id) { |
84 DownloadFileMap::iterator it = downloads_.find(global_id); | 84 DownloadFileMap::iterator it = downloads_.find(id); |
85 return it == downloads_.end() ? NULL : it->second; | 85 return it == downloads_.end() ? NULL : it->second; |
86 } | 86 } |
87 | 87 |
88 void DownloadFileManager::StartUpdateTimer() { | 88 void DownloadFileManager::StartUpdateTimer() { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
90 if (!update_timer_.IsRunning()) { | 90 if (!update_timer_.IsRunning()) { |
91 update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), | 91 update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), |
92 this, &DownloadFileManager::UpdateInProgressDownloads); | 92 this, &DownloadFileManager::UpdateInProgressDownloads); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void DownloadFileManager::StopUpdateTimer() { | 96 void DownloadFileManager::StopUpdateTimer() { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
98 update_timer_.Stop(); | 98 update_timer_.Stop(); |
99 } | 99 } |
100 | 100 |
101 void DownloadFileManager::UpdateInProgressDownloads() { | 101 void DownloadFileManager::UpdateInProgressDownloads() { |
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
103 for (DownloadFileMap::iterator i = downloads_.begin(); | 103 for (DownloadFileMap::iterator i = downloads_.begin(); |
104 i != downloads_.end(); ++i) { | 104 i != downloads_.end(); ++i) { |
105 DownloadId global_id = i->first; | 105 int id = i->first; |
106 DownloadFile* download_file = i->second; | 106 DownloadFile* download_file = i->second; |
107 DownloadManager* manager = download_file->GetDownloadManager(); | 107 DownloadManager* manager = download_file->GetDownloadManager(); |
108 if (manager) { | 108 if (manager) { |
109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
110 NewRunnableMethod(manager, &DownloadManager::UpdateDownload, | 110 NewRunnableMethod(manager, &DownloadManager::UpdateDownload, |
111 global_id.local(), download_file->bytes_so_far())); | 111 id, download_file->bytes_so_far())); |
112 } | 112 } |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
| 116 int DownloadFileManager::GetNextId() { |
| 117 return next_id_.GetNext(); |
| 118 } |
| 119 |
116 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { | 120 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
118 DCHECK(info); | 122 DCHECK(info); |
119 | 123 |
120 DownloadManager* manager = info->request_handle.GetDownloadManager(); | 124 DownloadManager* manager = info->request_handle.GetDownloadManager(); |
121 if (!manager) { | 125 if (!manager) { |
122 info->request_handle.CancelRequest(); | 126 info->request_handle.CancelRequest(); |
123 delete info; | 127 delete info; |
124 return; | 128 return; |
125 } | 129 } |
126 | 130 |
127 // TODO(phajdan.jr): fix the duplication of path info below. | 131 // TODO(phajdan.jr): fix the duplication of path info below. |
128 info->path = info->save_info.file_path; | 132 info->path = info->save_info.file_path; |
129 | 133 |
130 manager->CreateDownloadItem(info); | 134 manager->CreateDownloadItem(info); |
131 bool hash_needed = manager->delegate()->GenerateFileHash(); | 135 bool hash_needed = manager->delegate()->GenerateFileHash(); |
132 | 136 |
133 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 137 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
134 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile, | 138 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile, |
135 info, make_scoped_refptr(manager), hash_needed)); | 139 info, make_scoped_refptr(manager), hash_needed)); |
136 } | 140 } |
137 | 141 |
138 // We don't forward an update to the UI thread here, since we want to throttle | 142 // We don't forward an update to the UI thread here, since we want to throttle |
139 // the UI update rate via a periodic timer. If the user has cancelled the | 143 // the UI update rate via a periodic timer. If the user has cancelled the |
140 // download (in the UI thread), we may receive a few more updates before the IO | 144 // download (in the UI thread), we may receive a few more updates before the IO |
141 // thread gets the cancel message: we just delete the data since the | 145 // thread gets the cancel message: we just delete the data since the |
142 // DownloadFile has been deleted. | 146 // DownloadFile has been deleted. |
143 void DownloadFileManager::UpdateDownload( | 147 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { |
144 DownloadId global_id, DownloadBuffer* buffer) { | |
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
146 std::vector<DownloadBuffer::Contents> contents; | 149 std::vector<DownloadBuffer::Contents> contents; |
147 { | 150 { |
148 base::AutoLock auto_lock(buffer->lock); | 151 base::AutoLock auto_lock(buffer->lock); |
149 contents.swap(buffer->contents); | 152 contents.swap(buffer->contents); |
150 } | 153 } |
151 | 154 |
152 DownloadFile* download_file = GetDownloadFile(global_id); | 155 DownloadFile* download_file = GetDownloadFile(id); |
153 for (size_t i = 0; i < contents.size(); ++i) { | 156 for (size_t i = 0; i < contents.size(); ++i) { |
154 net::IOBuffer* data = contents[i].first; | 157 net::IOBuffer* data = contents[i].first; |
155 const int data_len = contents[i].second; | 158 const int data_len = contents[i].second; |
156 if (download_file) | 159 if (download_file) |
157 download_file->AppendDataToFile(data->data(), data_len); | 160 download_file->AppendDataToFile(data->data(), data_len); |
158 data->Release(); | 161 data->Release(); |
159 } | 162 } |
160 } | 163 } |
161 | 164 |
162 void DownloadFileManager::OnResponseCompleted( | 165 void DownloadFileManager::OnResponseCompleted( |
163 DownloadId global_id, | 166 int id, |
164 DownloadBuffer* buffer, | 167 DownloadBuffer* buffer, |
165 int os_error, | 168 int os_error, |
166 const std::string& security_info) { | 169 const std::string& security_info) { |
167 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id | 170 VLOG(20) << __FUNCTION__ << "()" << " id = " << id |
168 << " os_error = " << os_error | 171 << " os_error = " << os_error |
169 << " security_info = \"" << security_info << "\""; | 172 << " security_info = \"" << security_info << "\""; |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
171 delete buffer; | 174 delete buffer; |
172 DownloadFile* download_file = GetDownloadFile(global_id); | 175 DownloadFile* download_file = GetDownloadFile(id); |
173 if (!download_file) | 176 if (!download_file) |
174 return; | 177 return; |
175 | 178 |
176 download_file->Finish(); | 179 download_file->Finish(); |
177 | 180 |
178 DownloadManager* download_manager = download_file->GetDownloadManager(); | 181 DownloadManager* download_manager = download_file->GetDownloadManager(); |
179 if (!download_manager) { | 182 if (!download_manager) { |
180 CancelDownload(global_id); | 183 CancelDownload(id); |
181 return; | 184 return; |
182 } | 185 } |
183 | 186 |
184 std::string hash; | 187 std::string hash; |
185 if (!download_file->GetSha256Hash(&hash)) | 188 if (!download_file->GetSha256Hash(&hash)) |
186 hash.clear(); | 189 hash.clear(); |
187 | 190 |
188 BrowserThread::PostTask( | 191 BrowserThread::PostTask( |
189 BrowserThread::UI, FROM_HERE, | 192 BrowserThread::UI, FROM_HERE, |
190 NewRunnableMethod( | 193 NewRunnableMethod( |
191 download_manager, &DownloadManager::OnResponseCompleted, | 194 download_manager, &DownloadManager::OnResponseCompleted, |
192 global_id.local(), download_file->bytes_so_far(), os_error, hash)); | 195 id, download_file->bytes_so_far(), os_error, hash)); |
193 // We need to keep the download around until the UI thread has finalized | 196 // We need to keep the download around until the UI thread has finalized |
194 // the name. | 197 // the name. |
195 } | 198 } |
196 | 199 |
197 // This method will be sent via a user action, or shutdown on the UI thread, and | 200 // This method will be sent via a user action, or shutdown on the UI thread, and |
198 // run on the download thread. Since this message has been sent from the UI | 201 // run on the download thread. Since this message has been sent from the UI |
199 // thread, the download may have already completed and won't exist in our map. | 202 // thread, the download may have already completed and won't exist in our map. |
200 void DownloadFileManager::CancelDownload(DownloadId global_id) { | 203 void DownloadFileManager::CancelDownload(int id) { |
201 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id; | 204 VLOG(20) << __FUNCTION__ << "()" << " id = " << id; |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
203 DownloadFileMap::iterator it = downloads_.find(global_id); | 206 DownloadFileMap::iterator it = downloads_.find(id); |
204 if (it == downloads_.end()) | 207 if (it == downloads_.end()) |
205 return; | 208 return; |
206 | 209 |
207 DownloadFile* download_file = it->second; | 210 DownloadFile* download_file = it->second; |
208 VLOG(20) << __FUNCTION__ << "()" | 211 VLOG(20) << __FUNCTION__ << "()" |
209 << " download_file = " << download_file->DebugString(); | 212 << " download_file = " << download_file->DebugString(); |
210 download_file->Cancel(); | 213 download_file->Cancel(); |
211 | 214 |
212 EraseDownload(global_id); | 215 EraseDownload(id); |
213 } | 216 } |
214 | 217 |
215 void DownloadFileManager::CompleteDownload(DownloadId global_id) { | 218 void DownloadFileManager::CompleteDownload(int id) { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
217 | 220 |
218 if (!ContainsKey(downloads_, global_id)) | 221 if (!ContainsKey(downloads_, id)) |
219 return; | 222 return; |
220 | 223 |
221 DownloadFile* download_file = downloads_[global_id]; | 224 DownloadFile* download_file = downloads_[id]; |
222 | 225 |
223 VLOG(20) << " " << __FUNCTION__ << "()" | 226 VLOG(20) << " " << __FUNCTION__ << "()" |
224 << " id = " << global_id | 227 << " id = " << id |
225 << " download_file = " << download_file->DebugString(); | 228 << " download_file = " << download_file->DebugString(); |
226 | 229 |
227 download_file->Detach(); | 230 download_file->Detach(); |
228 | 231 |
229 EraseDownload(global_id); | 232 EraseDownload(id); |
230 } | 233 } |
231 | 234 |
232 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { | 235 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
234 DCHECK(manager); | 237 DCHECK(manager); |
235 | 238 |
236 std::set<DownloadFile*> to_remove; | 239 std::set<DownloadFile*> to_remove; |
237 | 240 |
238 for (DownloadFileMap::iterator i = downloads_.begin(); | 241 for (DownloadFileMap::iterator i = downloads_.begin(); |
239 i != downloads_.end(); ++i) { | 242 i != downloads_.end(); ++i) { |
240 DownloadFile* download_file = i->second; | 243 DownloadFile* download_file = i->second; |
241 if (download_file->GetDownloadManager() == manager) { | 244 if (download_file->GetDownloadManager() == manager) { |
242 download_file->CancelDownloadRequest(); | 245 download_file->CancelDownloadRequest(); |
243 to_remove.insert(download_file); | 246 to_remove.insert(download_file); |
244 } | 247 } |
245 } | 248 } |
246 | 249 |
247 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); | 250 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); |
248 i != to_remove.end(); ++i) { | 251 i != to_remove.end(); ++i) { |
249 downloads_.erase(DownloadId((*i)->GetDownloadManager(), (*i)->id())); | 252 downloads_.erase((*i)->id()); |
250 delete *i; | 253 delete *i; |
251 } | 254 } |
252 } | 255 } |
253 | 256 |
254 // Actions from the UI thread and run on the download thread | 257 // Actions from the UI thread and run on the download thread |
255 | 258 |
256 // The DownloadManager in the UI thread has provided an intermediate .crdownload | 259 // The DownloadManager in the UI thread has provided an intermediate .crdownload |
257 // name for the download specified by 'id'. Rename the in progress download. | 260 // name for the download specified by 'id'. Rename the in progress download. |
258 // | 261 // |
259 // There are 2 possible rename cases where this method can be called: | 262 // There are 2 possible rename cases where this method can be called: |
260 // 1. tmp -> foo.crdownload (not final, safe) | 263 // 1. tmp -> foo.crdownload (not final, safe) |
261 // 2. tmp-> Unconfirmed.xxx.crdownload (not final, dangerous) | 264 // 2. tmp-> Unconfirmed.xxx.crdownload (not final, dangerous) |
262 void DownloadFileManager::RenameInProgressDownloadFile( | 265 void DownloadFileManager::RenameInProgressDownloadFile( |
263 DownloadId global_id, const FilePath& full_path) { | 266 int id, const FilePath& full_path) { |
264 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id | 267 VLOG(20) << __FUNCTION__ << "()" << " id = " << id |
265 << " full_path = \"" << full_path.value() << "\""; | 268 << " full_path = \"" << full_path.value() << "\""; |
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
267 | 270 |
268 DownloadFile* download_file = GetDownloadFile(global_id); | 271 DownloadFile* download_file = GetDownloadFile(id); |
269 if (!download_file) | 272 if (!download_file) |
270 return; | 273 return; |
271 | 274 |
272 VLOG(20) << __FUNCTION__ << "()" | 275 VLOG(20) << __FUNCTION__ << "()" |
273 << " download_file = " << download_file->DebugString(); | 276 << " download_file = " << download_file->DebugString(); |
274 | 277 |
275 if (!download_file->Rename(full_path)) { | 278 if (!download_file->Rename(full_path)) { |
276 // Error. Between the time the UI thread generated 'full_path' to the time | 279 // Error. Between the time the UI thread generated 'full_path' to the time |
277 // this code runs, something happened that prevents us from renaming. | 280 // this code runs, something happened that prevents us from renaming. |
278 CancelDownloadOnRename(global_id); | 281 CancelDownloadOnRename(id); |
279 } | 282 } |
280 } | 283 } |
281 | 284 |
282 // The DownloadManager in the UI thread has provided a final name for the | 285 // The DownloadManager in the UI thread has provided a final name for the |
283 // download specified by 'id'. Rename the download that's in the process | 286 // download specified by 'id'. Rename the download that's in the process |
284 // of completing. | 287 // of completing. |
285 // | 288 // |
286 // There are 2 possible rename cases where this method can be called: | 289 // There are 2 possible rename cases where this method can be called: |
287 // 1. foo.crdownload -> foo (final, safe) | 290 // 1. foo.crdownload -> foo (final, safe) |
288 // 2. Unconfirmed.xxx.crdownload -> xxx (final, validated) | 291 // 2. Unconfirmed.xxx.crdownload -> xxx (final, validated) |
289 void DownloadFileManager::RenameCompletingDownloadFile( | 292 void DownloadFileManager::RenameCompletingDownloadFile( |
290 DownloadId global_id, | 293 int id, const FilePath& full_path, bool overwrite_existing_file) { |
291 const FilePath& full_path, | 294 VLOG(20) << __FUNCTION__ << "()" << " id = " << id |
292 bool overwrite_existing_file) { | |
293 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id | |
294 << " overwrite_existing_file = " << overwrite_existing_file | 295 << " overwrite_existing_file = " << overwrite_existing_file |
295 << " full_path = \"" << full_path.value() << "\""; | 296 << " full_path = \"" << full_path.value() << "\""; |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
297 | 298 |
298 DownloadFile* download_file = GetDownloadFile(global_id); | 299 DownloadFile* download_file = GetDownloadFile(id); |
299 if (!download_file) | 300 if (!download_file) |
300 return; | 301 return; |
301 | 302 |
302 DCHECK(download_file->GetDownloadManager()); | 303 DCHECK(download_file->GetDownloadManager()); |
303 DownloadManager* download_manager = download_file->GetDownloadManager(); | 304 DownloadManager* download_manager = download_file->GetDownloadManager(); |
304 | 305 |
305 VLOG(20) << __FUNCTION__ << "()" | 306 VLOG(20) << __FUNCTION__ << "()" |
306 << " download_file = " << download_file->DebugString(); | 307 << " download_file = " << download_file->DebugString(); |
307 | 308 |
308 int uniquifier = 0; | 309 int uniquifier = 0; |
309 FilePath new_path = full_path; | 310 FilePath new_path = full_path; |
310 if (!overwrite_existing_file) { | 311 if (!overwrite_existing_file) { |
311 // Make our name unique at this point, as if a dangerous file is | 312 // Make our name unique at this point, as if a dangerous file is |
312 // downloading and a 2nd download is started for a file with the same | 313 // downloading and a 2nd download is started for a file with the same |
313 // name, they would have the same path. This is because we uniquify | 314 // name, they would have the same path. This is because we uniquify |
314 // the name on download start, and at that time the first file does | 315 // the name on download start, and at that time the first file does |
315 // not exists yet, so the second file gets the same name. | 316 // not exists yet, so the second file gets the same name. |
316 // This should not happen in the SAFE case, and we check for that in the UI | 317 // This should not happen in the SAFE case, and we check for that in the UI |
317 // thread. | 318 // thread. |
318 uniquifier = DownloadFile::GetUniquePathNumber(new_path); | 319 uniquifier = DownloadFile::GetUniquePathNumber(new_path); |
319 if (uniquifier > 0) { | 320 if (uniquifier > 0) { |
320 DownloadFile::AppendNumberToPath(&new_path, uniquifier); | 321 DownloadFile::AppendNumberToPath(&new_path, uniquifier); |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 // Rename the file, overwriting if necessary. | 325 // Rename the file, overwriting if necessary. |
325 if (!download_file->Rename(new_path)) { | 326 if (!download_file->Rename(new_path)) { |
326 // Error. Between the time the UI thread generated 'full_path' to the time | 327 // Error. Between the time the UI thread generated 'full_path' to the time |
327 // this code runs, something happened that prevents us from renaming. | 328 // this code runs, something happened that prevents us from renaming. |
328 CancelDownloadOnRename(global_id); | 329 CancelDownloadOnRename(id); |
329 return; | 330 return; |
330 } | 331 } |
331 | 332 |
332 #if defined(OS_MACOSX) | 333 #if defined(OS_MACOSX) |
333 // Done here because we only want to do this once; see | 334 // Done here because we only want to do this once; see |
334 // http://crbug.com/13120 for details. | 335 // http://crbug.com/13120 for details. |
335 download_file->AnnotateWithSourceInformation(); | 336 download_file->AnnotateWithSourceInformation(); |
336 #endif | 337 #endif |
337 | 338 |
338 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( | 339 BrowserThread::PostTask( |
339 download_manager, &DownloadManager::OnDownloadRenamedToFinalName, | 340 BrowserThread::UI, FROM_HERE, |
340 global_id.local(), new_path, uniquifier)); | 341 NewRunnableMethod( |
| 342 download_manager, &DownloadManager::OnDownloadRenamedToFinalName, id, |
| 343 new_path, uniquifier)); |
341 } | 344 } |
342 | 345 |
343 // Called only from RenameInProgressDownloadFile and | 346 // Called only from RenameInProgressDownloadFile and |
344 // RenameCompletingDownloadFile on the FILE thread. | 347 // RenameCompletingDownloadFile on the FILE thread. |
345 void DownloadFileManager::CancelDownloadOnRename(DownloadId global_id) { | 348 void DownloadFileManager::CancelDownloadOnRename(int id) { |
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
347 | 350 |
348 DownloadFile* download_file = GetDownloadFile(global_id); | 351 DownloadFile* download_file = GetDownloadFile(id); |
349 if (!download_file) | 352 if (!download_file) |
350 return; | 353 return; |
351 | 354 |
352 DownloadManager* download_manager = download_file->GetDownloadManager(); | 355 DownloadManager* download_manager = download_file->GetDownloadManager(); |
353 if (!download_manager) { | 356 if (!download_manager) { |
354 // Without a download manager, we can't cancel the request normally, so we | 357 // Without a download manager, we can't cancel the request normally, so we |
355 // need to do it here. The normal path will also update the download | 358 // need to do it here. The normal path will also update the download |
356 // history before cancelling the request. | 359 // history before cancelling the request. |
357 download_file->CancelDownloadRequest(); | 360 download_file->CancelDownloadRequest(); |
358 return; | 361 return; |
359 } | 362 } |
360 | 363 |
361 BrowserThread::PostTask( | 364 BrowserThread::PostTask( |
362 BrowserThread::UI, FROM_HERE, | 365 BrowserThread::UI, FROM_HERE, |
363 NewRunnableMethod(download_manager, | 366 NewRunnableMethod(download_manager, |
364 &DownloadManager::CancelDownload, global_id.local())); | 367 &DownloadManager::CancelDownload, id)); |
365 } | 368 } |
366 | 369 |
367 void DownloadFileManager::EraseDownload(DownloadId global_id) { | 370 void DownloadFileManager::EraseDownload(int id) { |
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
369 | 372 |
370 if (!ContainsKey(downloads_, global_id)) | 373 if (!ContainsKey(downloads_, id)) |
371 return; | 374 return; |
372 | 375 |
373 DownloadFile* download_file = downloads_[global_id]; | 376 DownloadFile* download_file = downloads_[id]; |
374 | 377 |
375 VLOG(20) << " " << __FUNCTION__ << "()" | 378 VLOG(20) << " " << __FUNCTION__ << "()" |
376 << " id = " << global_id | 379 << " id = " << id |
377 << " download_file = " << download_file->DebugString(); | 380 << " download_file = " << download_file->DebugString(); |
378 | 381 |
379 downloads_.erase(global_id); | 382 downloads_.erase(id); |
380 | 383 |
381 delete download_file; | 384 delete download_file; |
382 | 385 |
383 if (downloads_.empty()) | 386 if (downloads_.empty()) |
384 StopUpdateTimer(); | 387 StopUpdateTimer(); |
385 } | 388 } |
OLD | NEW |