| 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/download/download_manager.h" | 13 #include "chrome/browser/download/download_manager.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/browser/tab_contents/web_contents.h" | 17 #include "chrome/browser/tab_contents/web_contents.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/platform_util.h" | 19 #include "chrome/common/platform_util.h" |
| 20 #include "chrome/common/stl_util-inl.h" | 20 #include "chrome/common/stl_util-inl.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 27 #include "chrome/common/win_util.h" | 27 #include "chrome/common/win_util.h" |
| 28 #include "chrome/common/win_safe_util.h" | 28 #include "chrome/common/win_safe_util.h" |
| 29 #elif defined(OS_MACOSX) |
| 30 #include "chrome/common/quarantine_mac.h" |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 // Throttle updates to the UI thread so that a fast moving download doesn't | 33 // Throttle updates to the UI thread so that a fast moving download doesn't |
| 32 // cause it to become unresponsive (in milliseconds). | 34 // cause it to become unresponsive (in milliseconds). |
| 33 static const int kUpdatePeriodMs = 500; | 35 static const int kUpdatePeriodMs = 500; |
| 34 | 36 |
| 35 // Timer task for posting UI updates. This task is created and maintained by | 37 // Timer task for posting UI updates. This task is created and maintained by |
| 36 // the DownloadFileManager long as there is an in progress download. The task | 38 // the DownloadFileManager long as there is an in progress download. The task |
| 37 // is cancelled when all active downloads have completed, or in the destructor | 39 // is cancelled when all active downloads have completed, or in the destructor |
| 38 // of the DownloadFileManager. | 40 // of the DownloadFileManager. |
| 39 class DownloadFileUpdateTask : public Task { | 41 class DownloadFileUpdateTask : public Task { |
| 40 public: | 42 public: |
| 41 explicit DownloadFileUpdateTask(DownloadFileManager* manager) | 43 explicit DownloadFileUpdateTask(DownloadFileManager* manager) |
| 42 : manager_(manager) {} | 44 : manager_(manager) {} |
| 43 virtual void Run() { | 45 virtual void Run() { |
| 44 manager_->UpdateInProgressDownloads(); | 46 manager_->UpdateInProgressDownloads(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 DownloadFileManager* manager_; | 50 DownloadFileManager* manager_; |
| 49 | 51 |
| 50 DISALLOW_COPY_AND_ASSIGN(DownloadFileUpdateTask); | 52 DISALLOW_COPY_AND_ASSIGN(DownloadFileUpdateTask); |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 // DownloadFile implementation ------------------------------------------------- | 55 // DownloadFile implementation ------------------------------------------------- |
| 54 | 56 |
| 55 DownloadFile::DownloadFile(const DownloadCreateInfo* info) | 57 DownloadFile::DownloadFile(const DownloadCreateInfo* info) |
| 56 : file_(NULL), | 58 : file_(NULL), |
| 59 source_url_(info->url), |
| 60 referrer_url_(info->referrer_url), |
| 57 id_(info->download_id), | 61 id_(info->download_id), |
| 58 render_process_id_(info->render_process_id), | 62 render_process_id_(info->render_process_id), |
| 59 render_view_id_(info->render_view_id), | 63 render_view_id_(info->render_view_id), |
| 60 request_id_(info->request_id), | 64 request_id_(info->request_id), |
| 61 bytes_so_far_(0), | 65 bytes_so_far_(0), |
| 62 path_renamed_(false), | 66 path_renamed_(false), |
| 63 in_progress_(true) { | 67 in_progress_(true) { |
| 64 } | 68 } |
| 65 | 69 |
| 66 DownloadFile::~DownloadFile() { | 70 DownloadFile::~DownloadFile() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 file_ = file_util::OpenFile(full_path_, open_mode); | 133 file_ = file_util::OpenFile(full_path_, open_mode); |
| 130 if (!file_) { | 134 if (!file_) { |
| 131 return false; | 135 return false; |
| 132 } | 136 } |
| 133 | 137 |
| 134 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 135 // Sets the Zone to tell Windows that this file comes from the internet. | 139 // Sets the Zone to tell Windows that this file comes from the internet. |
| 136 // We ignore the return value because a failure is not fatal. | 140 // We ignore the return value because a failure is not fatal. |
| 137 win_util::SetInternetZoneIdentifier(full_path_); | 141 win_util::SetInternetZoneIdentifier(full_path_); |
| 138 #elif defined(OS_MACOSX) | 142 #elif defined(OS_MACOSX) |
| 139 // TODO(port): Set quarrantine information, http://crbug.com/10853 | 143 quarantine_mac::AddQuarantineMetadataToFile(full_path_, source_url_, |
| 144 referrer_url_); |
| 140 #endif | 145 #endif |
| 141 return true; | 146 return true; |
| 142 } | 147 } |
| 143 | 148 |
| 144 // DownloadFileManager implementation ------------------------------------------ | 149 // DownloadFileManager implementation ------------------------------------------ |
| 145 | 150 |
| 146 DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, | 151 DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, |
| 147 ResourceDispatcherHost* rdh) | 152 ResourceDispatcherHost* rdh) |
| 148 : next_id_(0), | 153 : next_id_(0), |
| 149 ui_loop_(ui_loop), | 154 ui_loop_(ui_loop), |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 599 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 595 this, &DownloadFileManager::StopUpdateTimer)); | 600 this, &DownloadFileManager::StopUpdateTimer)); |
| 596 } | 601 } |
| 597 | 602 |
| 598 // static | 603 // static |
| 599 void DownloadFileManager::DeleteFile(const FilePath& path) { | 604 void DownloadFileManager::DeleteFile(const FilePath& path) { |
| 600 // Make sure we only delete files. | 605 // Make sure we only delete files. |
| 601 if (!file_util::DirectoryExists(path)) | 606 if (!file_util::DirectoryExists(path)) |
| 602 file_util::Delete(path, false); | 607 file_util::Delete(path, false); |
| 603 } | 608 } |
| OLD | NEW |