| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool DownloadFile::Open(const char* open_mode) { | 132 bool DownloadFile::Open(const char* open_mode) { |
| 133 DCHECK(!full_path_.empty()); | 133 DCHECK(!full_path_.empty()); |
| 134 file_ = file_util::OpenFile(full_path_, open_mode); | 134 file_ = file_util::OpenFile(full_path_, open_mode); |
| 135 if (!file_) { | 135 if (!file_) { |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 140 AnnotateWithSourceInformation(); |
| 141 #endif |
| 142 return true; |
| 143 } |
| 144 |
| 145 void DownloadFile::AnnotateWithSourceInformation() { |
| 146 #if defined(OS_WIN) |
| 140 // Sets the Zone to tell Windows that this file comes from the internet. | 147 // Sets the Zone to tell Windows that this file comes from the internet. |
| 141 // We ignore the return value because a failure is not fatal. | 148 // We ignore the return value because a failure is not fatal. |
| 142 win_util::SetInternetZoneIdentifier(full_path_); | 149 win_util::SetInternetZoneIdentifier(full_path_); |
| 143 #elif defined(OS_MACOSX) | 150 #elif defined(OS_MACOSX) |
| 144 quarantine_mac::AddQuarantineMetadataToFile(full_path_, source_url_, | 151 quarantine_mac::AddQuarantineMetadataToFile(full_path_, source_url_, |
| 145 referrer_url_); | 152 referrer_url_); |
| 146 #endif | 153 #endif |
| 147 return true; | |
| 148 } | 154 } |
| 149 | 155 |
| 150 // DownloadFileManager implementation ------------------------------------------ | 156 // DownloadFileManager implementation ------------------------------------------ |
| 151 | 157 |
| 152 DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, | 158 DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, |
| 153 ResourceDispatcherHost* rdh) | 159 ResourceDispatcherHost* rdh) |
| 154 : next_id_(0), | 160 : next_id_(0), |
| 155 ui_loop_(ui_loop), | 161 ui_loop_(ui_loop), |
| 156 resource_dispatcher_host_(rdh) { | 162 resource_dispatcher_host_(rdh) { |
| 157 } | 163 } |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 DownloadManager* manager) { | 564 DownloadManager* manager) { |
| 559 DCHECK(MessageLoop::current() == file_loop_); | 565 DCHECK(MessageLoop::current() == file_loop_); |
| 560 DownloadFileMap::iterator it = downloads_.find(id); | 566 DownloadFileMap::iterator it = downloads_.find(id); |
| 561 if (it == downloads_.end()) | 567 if (it == downloads_.end()) |
| 562 return; | 568 return; |
| 563 | 569 |
| 564 file_util::CreateDirectory(full_path.DirName()); | 570 file_util::CreateDirectory(full_path.DirName()); |
| 565 | 571 |
| 566 DownloadFile* download = it->second; | 572 DownloadFile* download = it->second; |
| 567 if (download->Rename(full_path)) { | 573 if (download->Rename(full_path)) { |
| 574 #if defined(OS_MACOSX) |
| 575 // Done here because we only want to do this once; see |
| 576 // http://crbug.com/13120 for details. |
| 577 download->AnnotateWithSourceInformation(); |
| 578 #endif |
| 568 ui_loop_->PostTask(FROM_HERE, | 579 ui_loop_->PostTask(FROM_HERE, |
| 569 NewRunnableMethod(manager, | 580 NewRunnableMethod(manager, |
| 570 &DownloadManager::DownloadRenamedToFinalName, | 581 &DownloadManager::DownloadRenamedToFinalName, |
| 571 id, | 582 id, |
| 572 full_path)); | 583 full_path)); |
| 573 } else { | 584 } else { |
| 574 // Error. Between the time the UI thread generated 'full_path' to the time | 585 // Error. Between the time the UI thread generated 'full_path' to the time |
| 575 // this code runs, something happened that prevents us from renaming. | 586 // this code runs, something happened that prevents us from renaming. |
| 576 DownloadManagerMap::iterator dmit = managers_.find(download->id()); | 587 DownloadManagerMap::iterator dmit = managers_.find(download->id()); |
| 577 if (dmit != managers_.end()) { | 588 if (dmit != managers_.end()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 599 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 610 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 600 this, &DownloadFileManager::StopUpdateTimer)); | 611 this, &DownloadFileManager::StopUpdateTimer)); |
| 601 } | 612 } |
| 602 | 613 |
| 603 // static | 614 // static |
| 604 void DownloadFileManager::DeleteFile(const FilePath& path) { | 615 void DownloadFileManager::DeleteFile(const FilePath& path) { |
| 605 // Make sure we only delete files. | 616 // Make sure we only delete files. |
| 606 if (!file_util::DirectoryExists(path)) | 617 if (!file_util::DirectoryExists(path)) |
| 607 file_util::Delete(path, false); | 618 file_util::Delete(path, false); |
| 608 } | 619 } |
| OLD | NEW |