OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/download/download_file.h" | 5 #include "chrome/browser/download/download_file.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { | 247 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { |
248 DCHECK(MessageLoop::current() == file_loop_); | 248 DCHECK(MessageLoop::current() == file_loop_); |
249 DCHECK(info); | 249 DCHECK(info); |
250 | 250 |
251 DownloadFile* download = new DownloadFile(info); | 251 DownloadFile* download = new DownloadFile(info); |
252 if (!download->Initialize()) { | 252 if (!download->Initialize()) { |
253 // Couldn't open, cancel the operation. The UI thread does not yet know | 253 // Couldn't open, cancel the operation. The UI thread does not yet know |
254 // about this download so we have to clean up 'info'. We need to get back | 254 // about this download so we have to clean up 'info'. We need to get back |
255 // to the IO thread to cancel the network request and CancelDownloadRequest | 255 // to the IO thread to cancel the network request and CancelDownloadRequest |
256 // on the UI thread is the safe way to do that. | 256 // on the UI thread is the safe way to do that. |
257 ui_loop_->PostTask(FROM_HERE, | 257 ChromeThread::PostTask( |
258 NewRunnableFunction(&DownloadManager::CancelDownloadRequest, | 258 ChromeThread::IO, FROM_HERE, |
259 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | |
260 resource_dispatcher_host_, | |
259 info->child_id, | 261 info->child_id, |
260 info->request_id)); | 262 info->request_id)); |
261 delete info; | 263 delete info; |
262 delete download; | 264 delete download; |
263 return; | 265 return; |
264 } | 266 } |
265 | 267 |
266 DCHECK(LookupDownload(info->download_id) == NULL); | 268 DCHECK(LookupDownload(info->download_id) == NULL); |
267 downloads_[info->download_id] = download; | 269 downloads_[info->download_id] = download; |
268 info->path = download->full_path(); | 270 info->path = download->full_path(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 | 380 |
379 // Lookup the DownloadManager for this TabContents' profile and inform it of | 381 // Lookup the DownloadManager for this TabContents' profile and inform it of |
380 // a new download. | 382 // a new download. |
381 // TODO(paulg): When implementing download restart via the Downloads tab, | 383 // TODO(paulg): When implementing download restart via the Downloads tab, |
382 // there will be no 'render_process_id' or 'render_view_id'. | 384 // there will be no 'render_process_id' or 'render_view_id'. |
383 void DownloadFileManager::OnStartDownload(DownloadCreateInfo* info) { | 385 void DownloadFileManager::OnStartDownload(DownloadCreateInfo* info) { |
384 DCHECK(MessageLoop::current() == ui_loop_); | 386 DCHECK(MessageLoop::current() == ui_loop_); |
385 DownloadManager* manager = DownloadManagerFromRenderIds(info->child_id, | 387 DownloadManager* manager = DownloadManagerFromRenderIds(info->child_id, |
386 info->render_view_id); | 388 info->render_view_id); |
387 if (!manager) { | 389 if (!manager) { |
388 DownloadManager::CancelDownloadRequest(info->child_id, info->request_id); | 390 ChromeThread::PostTask( |
391 ChromeThread::IO, FROM_HERE, | |
392 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | |
393 resource_dispatcher_host_, | |
394 info->child_id, | |
395 info->request_id)); | |
389 delete info; | 396 delete info; |
390 return; | 397 return; |
391 } | 398 } |
392 | 399 |
393 StartUpdateTimer(); | 400 StartUpdateTimer(); |
394 | 401 |
395 // Add the download manager to our request maps for future updates. We want to | 402 // Add the download manager to our request maps for future updates. We want to |
396 // be able to cancel all in progress downloads when a DownloadManager is | 403 // be able to cancel all in progress downloads when a DownloadManager is |
397 // deleted, such as when a profile is closed. We also want to be able to look | 404 // deleted, such as when a profile is closed. We also want to be able to look |
398 // up the DownloadManager associated with a given request without having to | 405 // up the DownloadManager associated with a given request without having to |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 // Error. Between the time the UI thread generated 'full_path' to the time | 607 // Error. Between the time the UI thread generated 'full_path' to the time |
601 // this code runs, something happened that prevents us from renaming. | 608 // this code runs, something happened that prevents us from renaming. |
602 DownloadManagerMap::iterator dmit = managers_.find(download->id()); | 609 DownloadManagerMap::iterator dmit = managers_.find(download->id()); |
603 if (dmit != managers_.end()) { | 610 if (dmit != managers_.end()) { |
604 DownloadManager* dlm = dmit->second; | 611 DownloadManager* dlm = dmit->second; |
605 ui_loop_->PostTask(FROM_HERE, | 612 ui_loop_->PostTask(FROM_HERE, |
606 NewRunnableMethod(dlm, | 613 NewRunnableMethod(dlm, |
607 &DownloadManager::DownloadCancelled, | 614 &DownloadManager::DownloadCancelled, |
608 id)); | 615 id)); |
609 } else { | 616 } else { |
610 ui_loop_->PostTask(FROM_HERE, | 617 ChromeThread::PostTask( |
611 NewRunnableFunction(&DownloadManager::CancelDownloadRequest, | 618 ChromeThread::IO, FROM_HERE, |
612 download->child_id(), | 619 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, |
620 resource_dispatcher_host_, | |
621 download->child_id(), | |
613 download->request_id())); | 622 download->request_id())); |
darin (slow to review)
2009/10/27 00:06:52
nit: indentation
jam
2009/10/27 02:38:18
Done.
| |
614 } | 623 } |
615 } | 624 } |
616 | 625 |
617 // If the download has completed before we got this final name, we remove it | 626 // If the download has completed before we got this final name, we remove it |
618 // from our in progress map. | 627 // from our in progress map. |
619 if (!download->in_progress()) { | 628 if (!download->in_progress()) { |
620 downloads_.erase(it); | 629 downloads_.erase(it); |
621 delete download; | 630 delete download; |
622 } | 631 } |
623 | 632 |
624 if (downloads_.empty()) | 633 if (downloads_.empty()) |
625 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 634 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
626 this, &DownloadFileManager::StopUpdateTimer)); | 635 this, &DownloadFileManager::StopUpdateTimer)); |
627 } | 636 } |
628 | 637 |
629 // static | 638 // static |
630 void DownloadFileManager::DeleteFile(const FilePath& path) { | 639 void DownloadFileManager::DeleteFile(const FilePath& path) { |
631 // Make sure we only delete files. | 640 // Make sure we only delete files. |
632 if (!file_util::DirectoryExists(path)) | 641 if (!file_util::DirectoryExists(path)) |
633 file_util::Delete(path, false); | 642 file_util::Delete(path, false); |
634 } | 643 } |
OLD | NEW |