| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return (download_path == desktop_dir); | 110 return (download_path == desktop_dir); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // DownloadItem implementation ------------------------------------------------- | 113 // DownloadItem implementation ------------------------------------------------- |
| 114 | 114 |
| 115 // Constructor for reading from the history service. | 115 // Constructor for reading from the history service. |
| 116 DownloadItem::DownloadItem(const DownloadCreateInfo& info) | 116 DownloadItem::DownloadItem(const DownloadCreateInfo& info) |
| 117 : id_(-1), | 117 : id_(-1), |
| 118 full_path_(info.path), | 118 full_path_(info.path), |
| 119 url_(info.url), | 119 url_(info.url), |
| 120 referrer_url_(info.referrer_url), |
| 121 mime_type_(info.mime_type), |
| 120 total_bytes_(info.total_bytes), | 122 total_bytes_(info.total_bytes), |
| 121 received_bytes_(info.received_bytes), | 123 received_bytes_(info.received_bytes), |
| 122 start_tick_(base::TimeTicks()), | 124 start_tick_(base::TimeTicks()), |
| 123 state_(static_cast<DownloadState>(info.state)), | 125 state_(static_cast<DownloadState>(info.state)), |
| 124 start_time_(info.start_time), | 126 start_time_(info.start_time), |
| 125 db_handle_(info.db_handle), | 127 db_handle_(info.db_handle), |
| 126 manager_(NULL), | 128 manager_(NULL), |
| 127 is_paused_(false), | 129 is_paused_(false), |
| 128 open_when_complete_(false), | 130 open_when_complete_(false), |
| 129 safety_state_(SAFE), | 131 safety_state_(SAFE), |
| 130 auto_opened_(false), | 132 auto_opened_(false), |
| 131 original_name_(info.original_name), | 133 original_name_(info.original_name), |
| 132 render_process_id_(-1), | 134 render_process_id_(-1), |
| 133 request_id_(-1) { | 135 request_id_(-1) { |
| 134 if (state_ == IN_PROGRESS) | 136 if (state_ == IN_PROGRESS) |
| 135 state_ = CANCELLED; | 137 state_ = CANCELLED; |
| 136 Init(false /* don't start progress timer */); | 138 Init(false /* don't start progress timer */); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // Constructor for DownloadItem created via user action in the main thread. | 141 // Constructor for DownloadItem created via user action in the main thread. |
| 140 DownloadItem::DownloadItem(int32 download_id, | 142 DownloadItem::DownloadItem(int32 download_id, |
| 141 const FilePath& path, | 143 const FilePath& path, |
| 142 int path_uniquifier, | 144 int path_uniquifier, |
| 143 const GURL& url, | 145 const GURL& url, |
| 144 const GURL& referrer_url, | 146 const GURL& referrer_url, |
| 147 const std::string& mime_type, |
| 145 const FilePath& original_name, | 148 const FilePath& original_name, |
| 146 const base::Time start_time, | 149 const base::Time start_time, |
| 147 int64 download_size, | 150 int64 download_size, |
| 148 int render_process_id, | 151 int render_process_id, |
| 149 int request_id, | 152 int request_id, |
| 150 bool is_dangerous) | 153 bool is_dangerous) |
| 151 : id_(download_id), | 154 : id_(download_id), |
| 152 full_path_(path), | 155 full_path_(path), |
| 153 path_uniquifier_(path_uniquifier), | 156 path_uniquifier_(path_uniquifier), |
| 154 url_(url), | 157 url_(url), |
| 155 referrer_url_(referrer_url), | 158 referrer_url_(referrer_url), |
| 159 mime_type_(mime_type), |
| 156 total_bytes_(download_size), | 160 total_bytes_(download_size), |
| 157 received_bytes_(0), | 161 received_bytes_(0), |
| 158 start_tick_(base::TimeTicks::Now()), | 162 start_tick_(base::TimeTicks::Now()), |
| 159 state_(IN_PROGRESS), | 163 state_(IN_PROGRESS), |
| 160 start_time_(start_time), | 164 start_time_(start_time), |
| 161 db_handle_(kUninitializedHandle), | 165 db_handle_(kUninitializedHandle), |
| 162 manager_(NULL), | 166 manager_(NULL), |
| 163 is_paused_(false), | 167 is_paused_(false), |
| 164 open_when_complete_(false), | 168 open_when_complete_(false), |
| 165 safety_state_(is_dangerous ? DANGEROUS : SAFE), | 169 safety_state_(is_dangerous ? DANGEROUS : SAFE), |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 info->path = target_path; | 674 info->path = target_path; |
| 671 | 675 |
| 672 DownloadItem* download = NULL; | 676 DownloadItem* download = NULL; |
| 673 DownloadMap::iterator it = in_progress_.find(info->download_id); | 677 DownloadMap::iterator it = in_progress_.find(info->download_id); |
| 674 if (it == in_progress_.end()) { | 678 if (it == in_progress_.end()) { |
| 675 download = new DownloadItem(info->download_id, | 679 download = new DownloadItem(info->download_id, |
| 676 info->path, | 680 info->path, |
| 677 info->path_uniquifier, | 681 info->path_uniquifier, |
| 678 info->url, | 682 info->url, |
| 679 info->referrer_url, | 683 info->referrer_url, |
| 684 info->mime_type, |
| 680 info->original_name, | 685 info->original_name, |
| 681 info->start_time, | 686 info->start_time, |
| 682 info->total_bytes, | 687 info->total_bytes, |
| 683 info->render_process_id, | 688 info->render_process_id, |
| 684 info->request_id, | 689 info->request_id, |
| 685 info->is_dangerous); | 690 info->is_dangerous); |
| 686 download->set_manager(this); | 691 download->set_manager(this); |
| 687 in_progress_[info->download_id] = download; | 692 in_progress_[info->download_id] = download; |
| 688 } else { | 693 } else { |
| 689 NOTREACHED(); // Should not exist! | 694 NOTREACHED(); // Should not exist! |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 if (it != dangerous_finished_.end()) | 839 if (it != dangerous_finished_.end()) |
| 835 dangerous_finished_.erase(it); | 840 dangerous_finished_.erase(it); |
| 836 | 841 |
| 837 // Open the download if the user or user prefs indicate it should be. | 842 // Open the download if the user or user prefs indicate it should be. |
| 838 FilePath::StringType extension = download->full_path().Extension(); | 843 FilePath::StringType extension = download->full_path().Extension(); |
| 839 // Drop the leading period. (The auto-open list is period-less.) | 844 // Drop the leading period. (The auto-open list is period-less.) |
| 840 if (extension.size() > 0) | 845 if (extension.size() > 0) |
| 841 extension = extension.substr(1); | 846 extension = extension.substr(1); |
| 842 | 847 |
| 843 // Handle chrome extensions explicitly and skip the shell execute. | 848 // Handle chrome extensions explicitly and skip the shell execute. |
| 844 if (Extension::IsExtension(download->full_path())) { | 849 if (download->mime_type() == Extension::kMimeType) { |
| 845 OpenChromeExtension(download->full_path(), download->url(), | 850 OpenChromeExtension(download->full_path(), download->url(), |
| 846 download->referrer_url()); | 851 download->referrer_url()); |
| 847 download->set_auto_opened(true); | 852 download->set_auto_opened(true); |
| 848 } else if (download->open_when_complete() || | 853 } else if (download->open_when_complete() || |
| 849 ShouldOpenFileExtension(extension)) { | 854 ShouldOpenFileExtension(extension)) { |
| 850 OpenDownloadInShell(download, NULL); | 855 OpenDownloadInShell(download, NULL); |
| 851 download->set_auto_opened(true); | 856 download->set_auto_opened(true); |
| 852 } | 857 } |
| 853 | 858 |
| 854 // Notify our observers that we are complete (the call to Finished() set the | 859 // Notify our observers that we are complete (the call to Finished() set the |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 file_loop_->PostTask(FROM_HERE, | 1209 file_loop_->PostTask(FROM_HERE, |
| 1205 NewRunnableMethod(file_manager_, | 1210 NewRunnableMethod(file_manager_, |
| 1206 &DownloadFileManager::OnShowDownloadInShell, | 1211 &DownloadFileManager::OnShowDownloadInShell, |
| 1207 FilePath(download->full_path()))); | 1212 FilePath(download->full_path()))); |
| 1208 } | 1213 } |
| 1209 | 1214 |
| 1210 void DownloadManager::OpenDownload(const DownloadItem* download, | 1215 void DownloadManager::OpenDownload(const DownloadItem* download, |
| 1211 gfx::NativeView parent_window) { | 1216 gfx::NativeView parent_window) { |
| 1212 // Open Chrome extensions with ExtensionsService. For everything else do shell | 1217 // Open Chrome extensions with ExtensionsService. For everything else do shell |
| 1213 // execute. | 1218 // execute. |
| 1214 if (Extension::IsExtension(download->full_path())) { | 1219 if (download->mime_type() == Extension::kMimeType) { |
| 1215 OpenChromeExtension(download->full_path(), download->url(), | 1220 OpenChromeExtension(download->full_path(), download->url(), |
| 1216 download->referrer_url()); | 1221 download->referrer_url()); |
| 1217 } else { | 1222 } else { |
| 1218 OpenDownloadInShell(download, parent_window); | 1223 OpenDownloadInShell(download, parent_window); |
| 1219 } | 1224 } |
| 1220 } | 1225 } |
| 1221 | 1226 |
| 1222 void DownloadManager::OpenChromeExtension(const FilePath& full_path, | 1227 void DownloadManager::OpenChromeExtension(const FilePath& full_path, |
| 1223 const GURL& download_url, | 1228 const GURL& download_url, |
| 1224 const GURL& referrer_url) { | 1229 const GURL& referrer_url) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1487 | 1492 |
| 1488 if (contents) | 1493 if (contents) |
| 1489 contents->OnStartDownload(download); | 1494 contents->OnStartDownload(download); |
| 1490 } | 1495 } |
| 1491 | 1496 |
| 1492 // Clears the last download path, used to initialize "save as" dialogs. | 1497 // Clears the last download path, used to initialize "save as" dialogs. |
| 1493 void DownloadManager::ClearLastDownloadPath() { | 1498 void DownloadManager::ClearLastDownloadPath() { |
| 1494 last_download_path_ = FilePath(); | 1499 last_download_path_ = FilePath(); |
| 1495 } | 1500 } |
| 1496 | 1501 |
| OLD | NEW |