blob: a60aee63e002a7925fd72ef0e16361b8360a721f [file] [log] [blame]
[email protected]f4f50ef2011-01-21 19:01:191// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]5656f8a2011-11-17 16:12:585#include "content/browser/download/download_manager_impl.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]e7557f172011-08-19 23:42:017#include <iterator>
8
[email protected]eda58402011-09-21 19:32:029#include "base/bind.h"
[email protected]2041cf342010-02-19 03:15:5910#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
[email protected]503d03872011-05-06 08:36:2612#include "base/i18n/case_conversion.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/logging.h"
[email protected]7286e3fc2011-07-19 22:13:2414#include "base/stl_util.h"
[email protected]eda58402011-09-21 19:32:0215#include "base/stringprintf.h"
16#include "base/synchronization/lock.h"
17#include "base/sys_string_conversions.h"
[email protected]d2a8fb72010-01-21 05:31:4218#include "build/build_config.h"
[email protected]71bf3f5e2011-08-15 21:05:2219#include "content/browser/download/download_create_info.h"
20#include "content/browser/download/download_file_manager.h"
[email protected]2909e342011-10-29 00:46:5321#include "content/browser/download/download_id_factory.h"
[email protected]c09a8fd2011-11-21 19:54:5022#include "content/browser/download/download_item_impl.h"
[email protected]bb1a4212011-08-22 22:38:2523#include "content/browser/download/download_persistent_store_info.h"
[email protected]da4a5582011-10-17 19:08:0624#include "content/browser/download/download_stats.h"
[email protected]71bf3f5e2011-08-15 21:05:2225#include "content/browser/download/download_status_updater.h"
[email protected]be76b7e2011-10-13 12:57:5726#include "content/browser/download/interrupt_reasons.h"
[email protected]7324d1d2011-03-01 05:02:1627#include "content/browser/renderer_host/render_view_host.h"
28#include "content/browser/renderer_host/resource_dispatcher_host.h"
29#include "content/browser/tab_contents/tab_contents.h"
[email protected]ccb797302011-12-15 16:55:1130#include "content/public/browser/browser_context.h"
[email protected]c38831a12011-10-28 12:44:4931#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4432#include "content/public/browser/content_browser_client.h"
[email protected]1bd0ef12011-10-20 05:24:1733#include "content/public/browser/download_manager_delegate.h"
[email protected]ad50def52011-10-19 23:17:0734#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1635#include "content/public/browser/notification_types.h"
[email protected]f3b1a082011-11-18 00:34:3036#include "content/public/browser/render_process_host.h"
initial.commit09911bf2008-07-26 23:55:2937
[email protected]631bb742011-11-02 11:29:3938using content::BrowserThread;
39
[email protected]a0ce3282011-08-19 20:49:5240namespace {
41
[email protected]fabf36d22011-10-28 21:50:1742// Param structs exist because base::Bind can only handle 6 args.
43struct URLParams {
44 URLParams(const GURL& url, const GURL& referrer)
45 : url_(url), referrer_(referrer) {}
46 GURL url_;
47 GURL referrer_;
48};
49
50struct RenderParams {
51 RenderParams(int rpi, int rvi)
52 : render_process_id_(rpi), render_view_id_(rvi) {}
53 int render_process_id_;
54 int render_view_id_;
55};
56
57void BeginDownload(const URLParams& url_params,
58 const DownloadSaveInfo& save_info,
59 ResourceDispatcherHost* resource_dispatcher_host,
60 const RenderParams& render_params,
61 const content::ResourceContext* context) {
62 net::URLRequest* request = new net::URLRequest(url_params.url_,
63 resource_dispatcher_host);
64 request->set_referrer(url_params.referrer_.spec());
[email protected]c79a0c02011-08-22 22:37:3765 resource_dispatcher_host->BeginDownload(
[email protected]fabf36d22011-10-28 21:50:1766 request, save_info, true,
[email protected]8e3ae68c2011-09-16 22:15:4767 DownloadResourceHandler::OnStartedCallback(),
[email protected]fabf36d22011-10-28 21:50:1768 render_params.render_process_id_,
69 render_params.render_view_id_,
[email protected]c79a0c02011-08-22 22:37:3770 *context);
[email protected]a0ce3282011-08-19 20:49:5271}
72
73} // namespace
74
[email protected]5656f8a2011-11-17 16:12:5875DownloadManagerImpl::DownloadManagerImpl(
76 content::DownloadManagerDelegate* delegate,
77 DownloadIdFactory* id_factory,
78 DownloadStatusUpdater* status_updater)
79 : shutdown_needed_(false),
80 browser_context_(NULL),
81 file_manager_(NULL),
82 status_updater_((status_updater != NULL)
83 ? status_updater->AsWeakPtr()
84 : base::WeakPtr<DownloadStatusUpdater>()),
85 delegate_(delegate),
86 id_factory_(id_factory),
87 largest_db_handle_in_history_(DownloadItem::kUninitializedHandle) {
[email protected]eda58402011-09-21 19:32:0288 // NOTE(benjhayden): status_updater may be NULL when using
89 // TestingBrowserProcess.
90 if (status_updater_.get() != NULL)
[email protected]073ed7b2010-09-27 09:20:0291 status_updater_->AddDelegate(this);
initial.commit09911bf2008-07-26 23:55:2992}
93
[email protected]5656f8a2011-11-17 16:12:5894DownloadManagerImpl::~DownloadManagerImpl() {
[email protected]326a6a92010-09-10 20:21:1395 DCHECK(!shutdown_needed_);
[email protected]eda58402011-09-21 19:32:0296 if (status_updater_.get() != NULL)
[email protected]073ed7b2010-09-27 09:20:0297 status_updater_->RemoveDelegate(this);
initial.commit09911bf2008-07-26 23:55:2998}
99
[email protected]5656f8a2011-11-17 16:12:58100DownloadId DownloadManagerImpl::GetNextId() {
[email protected]2909e342011-10-29 00:46:53101 return id_factory_->GetNextId();
102}
103
[email protected]fc03de22011-12-06 23:28:12104bool DownloadManagerImpl::ShouldOpenDownload(DownloadItem* item) {
105 return delegate_->ShouldOpenDownload(item);
106}
107
108bool DownloadManagerImpl::ShouldOpenFileBasedOnExtension(const FilePath& path) {
109 return delegate_->ShouldOpenFileBasedOnExtension(path);
110}
111
[email protected]5656f8a2011-11-17 16:12:58112void DownloadManagerImpl::Shutdown() {
[email protected]da6e3922010-11-24 21:45:50113 VLOG(20) << __FUNCTION__ << "()"
114 << " shutdown_needed_ = " << shutdown_needed_;
[email protected]326a6a92010-09-10 20:21:13115 if (!shutdown_needed_)
116 return;
117 shutdown_needed_ = false;
initial.commit09911bf2008-07-26 23:55:29118
[email protected]326a6a92010-09-10 20:21:13119 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown());
[email protected]fb4f8d902011-09-16 06:07:08120 // TODO(benjhayden): Consider clearing observers_.
[email protected]326a6a92010-09-10 20:21:13121
122 if (file_manager_) {
[email protected]ca4b5fa32010-10-09 12:42:18123 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]fabf36d22011-10-28 21:50:17124 base::Bind(&DownloadFileManager::OnDownloadManagerShutdown,
125 file_manager_, make_scoped_refptr(this)));
[email protected]326a6a92010-09-10 20:21:13126 }
initial.commit09911bf2008-07-26 23:55:29127
[email protected]f04182f32010-12-10 19:12:07128 AssertContainersConsistent();
129
130 // Go through all downloads in downloads_. Dangerous ones we need to
131 // remove on disk, and in progress ones we need to cancel.
[email protected]57fd1252010-12-23 17:24:09132 for (DownloadSet::iterator it = downloads_.begin(); it != downloads_.end();) {
[email protected]f04182f32010-12-10 19:12:07133 DownloadItem* download = *it;
134
135 // Save iterator from potential erases in this set done by called code.
136 // Iterators after an erasure point are still valid for lists and
137 // associative containers such as sets.
138 it++;
139
[email protected]c09a8fd2011-11-21 19:54:50140 if (download->GetSafetyState() == DownloadItem::DANGEROUS &&
[email protected]48837962011-04-19 17:03:29141 download->IsPartialDownload()) {
[email protected]f04182f32010-12-10 19:12:07142 // The user hasn't accepted it, so we need to remove it
143 // from the disk. This may or may not result in it being
144 // removed from the DownloadManager queues and deleted
[email protected]fc03de22011-12-06 23:28:12145 // (specifically, DownloadManager::DownloadRemoved only
[email protected]f04182f32010-12-10 19:12:07146 // removes and deletes it if it's known to the history service)
147 // so the only thing we know after calling this function is that
148 // the download was deleted if-and-only-if it was removed
149 // from all queues.
[email protected]303077002011-04-19 23:21:01150 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
[email protected]bf68a00b2011-04-07 17:28:26151 } else if (download->IsPartialDownload()) {
[email protected]93af2272011-09-21 18:29:17152 download->Cancel(false);
153 delegate_->UpdateItemInPersistentStore(download);
initial.commit09911bf2008-07-26 23:55:29154 }
155 }
156
[email protected]f04182f32010-12-10 19:12:07157 // At this point, all dangerous downloads have had their files removed
158 // and all in progress downloads have been cancelled. We can now delete
159 // anything left.
[email protected]9ccbb372008-10-10 18:50:32160
[email protected]5cd11b6e2011-06-10 20:30:59161 // Copy downloads_ to separate container so as not to set off checks
162 // in DownloadItem destruction.
163 DownloadSet downloads_to_delete;
164 downloads_to_delete.swap(downloads_);
165
initial.commit09911bf2008-07-26 23:55:29166 in_progress_.clear();
[email protected]70850c72011-01-11 17:31:27167 active_downloads_.clear();
[email protected]5cd11b6e2011-06-10 20:30:59168 history_downloads_.clear();
[email protected]5cd11b6e2011-06-10 20:30:59169 STLDeleteElements(&downloads_to_delete);
initial.commit09911bf2008-07-26 23:55:29170
[email protected]6d0146c2011-08-04 19:13:04171 DCHECK(save_page_downloads_.empty());
172
initial.commit09911bf2008-07-26 23:55:29173 file_manager_ = NULL;
[email protected]2588ea9d2011-08-22 20:59:53174 delegate_->Shutdown();
[email protected]82f37b02010-07-29 22:04:57175
initial.commit09911bf2008-07-26 23:55:29176 shutdown_needed_ = false;
177}
178
[email protected]5656f8a2011-11-17 16:12:58179void DownloadManagerImpl::GetTemporaryDownloads(
[email protected]6d0146c2011-08-04 19:13:04180 const FilePath& dir_path, DownloadVector* result) {
[email protected]82f37b02010-07-29 22:04:57181 DCHECK(result);
[email protected]6aa4a1c02010-01-15 18:49:58182
[email protected]f04182f32010-12-10 19:12:07183 for (DownloadMap::iterator it = history_downloads_.begin();
184 it != history_downloads_.end(); ++it) {
[email protected]c09a8fd2011-11-21 19:54:50185 if (it->second->IsTemporary() &&
[email protected]fdd2715c2011-12-09 22:24:20186 (dir_path.empty() || it->second->GetFullPath().DirName() == dir_path))
[email protected]82f37b02010-07-29 22:04:57187 result->push_back(it->second);
[email protected]6aa4a1c02010-01-15 18:49:58188 }
[email protected]6aa4a1c02010-01-15 18:49:58189}
190
[email protected]5656f8a2011-11-17 16:12:58191void DownloadManagerImpl::GetAllDownloads(
[email protected]6d0146c2011-08-04 19:13:04192 const FilePath& dir_path, DownloadVector* result) {
[email protected]82f37b02010-07-29 22:04:57193 DCHECK(result);
[email protected]8ddbd66a2010-05-21 16:38:34194
[email protected]f04182f32010-12-10 19:12:07195 for (DownloadMap::iterator it = history_downloads_.begin();
196 it != history_downloads_.end(); ++it) {
[email protected]c09a8fd2011-11-21 19:54:50197 if (!it->second->IsTemporary() &&
198 (dir_path.empty() || it->second->GetFullPath().DirName() == dir_path))
[email protected]82f37b02010-07-29 22:04:57199 result->push_back(it->second);
[email protected]8ddbd66a2010-05-21 16:38:34200 }
[email protected]8ddbd66a2010-05-21 16:38:34201}
202
[email protected]5656f8a2011-11-17 16:12:58203void DownloadManagerImpl::SearchDownloads(const string16& query,
204 DownloadVector* result) {
[email protected]503d03872011-05-06 08:36:26205 string16 query_lower(base::i18n::ToLower(query));
[email protected]d3b12902010-08-16 23:39:42206
[email protected]f04182f32010-12-10 19:12:07207 for (DownloadMap::iterator it = history_downloads_.begin();
208 it != history_downloads_.end(); ++it) {
[email protected]d3b12902010-08-16 23:39:42209 DownloadItem* download_item = it->second;
210
[email protected]c09a8fd2011-11-21 19:54:50211 if (download_item->IsTemporary())
[email protected]d3b12902010-08-16 23:39:42212 continue;
213
214 // Display Incognito downloads only in Incognito window, and vice versa.
215 // The Incognito Downloads page will get the list of non-Incognito downloads
216 // from its parent profile.
[email protected]c09a8fd2011-11-21 19:54:50217 if (browser_context_->IsOffTheRecord() != download_item->IsOtr())
[email protected]d3b12902010-08-16 23:39:42218 continue;
219
220 if (download_item->MatchesQuery(query_lower))
221 result->push_back(download_item);
222 }
[email protected]d3b12902010-08-16 23:39:42223}
224
initial.commit09911bf2008-07-26 23:55:29225// Query the history service for information about all persisted downloads.
[email protected]5656f8a2011-11-17 16:12:58226bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) {
[email protected]6d0c9fb2011-08-22 19:26:03227 DCHECK(browser_context);
initial.commit09911bf2008-07-26 23:55:29228 DCHECK(!shutdown_needed_) << "DownloadManager already initialized.";
229 shutdown_needed_ = true;
230
[email protected]6d0c9fb2011-08-22 19:26:03231 browser_context_ = browser_context;
[email protected]024f2f02010-04-30 22:51:46232
[email protected]2941c2392010-07-15 22:54:30233 // In test mode, there may be no ResourceDispatcherHost. In this case it's
234 // safe to avoid setting |file_manager_| because we only call a small set of
235 // functions, none of which need it.
[email protected]a0ce3282011-08-19 20:49:52236 ResourceDispatcherHost* rdh =
237 content::GetContentClient()->browser()->GetResourceDispatcherHost();
[email protected]2941c2392010-07-15 22:54:30238 if (rdh) {
239 file_manager_ = rdh->download_file_manager();
240 DCHECK(file_manager_);
initial.commit09911bf2008-07-26 23:55:29241 }
242
initial.commit09911bf2008-07-26 23:55:29243 return true;
244}
245
[email protected]aa9881c2011-08-15 18:01:12246// We have received a message from DownloadFileManager about a new download.
[email protected]5656f8a2011-11-17 16:12:58247void DownloadManagerImpl::StartDownload(int32 download_id) {
[email protected]ca4b5fa32010-10-09 12:42:18248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]287b86b2011-02-26 00:11:35249
[email protected]aa9881c2011-08-15 18:01:12250 if (delegate_->ShouldStartDownload(download_id))
251 RestartDownload(download_id);
[email protected]287b86b2011-02-26 00:11:35252}
253
[email protected]5656f8a2011-11-17 16:12:58254void DownloadManagerImpl::CheckForHistoryFilesRemoval() {
[email protected]9fc114672011-06-15 08:17:48255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 for (DownloadMap::iterator it = history_downloads_.begin();
257 it != history_downloads_.end(); ++it) {
258 CheckForFileRemoval(it->second);
259 }
260}
261
[email protected]5656f8a2011-11-17 16:12:58262void DownloadManagerImpl::CheckForFileRemoval(DownloadItem* download_item) {
[email protected]9fc114672011-06-15 08:17:48263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
264 if (download_item->IsComplete() &&
[email protected]c09a8fd2011-11-21 19:54:50265 !download_item->GetFileExternallyRemoved()) {
[email protected]9fc114672011-06-15 08:17:48266 BrowserThread::PostTask(
267 BrowserThread::FILE, FROM_HERE,
[email protected]5656f8a2011-11-17 16:12:58268 base::Bind(&DownloadManagerImpl::CheckForFileRemovalOnFileThread,
[email protected]c09a8fd2011-11-21 19:54:50269 this, download_item->GetDbHandle(),
[email protected]fabf36d22011-10-28 21:50:17270 download_item->GetTargetFilePath()));
[email protected]9fc114672011-06-15 08:17:48271 }
272}
273
[email protected]5656f8a2011-11-17 16:12:58274void DownloadManagerImpl::CheckForFileRemovalOnFileThread(
[email protected]9fc114672011-06-15 08:17:48275 int64 db_handle, const FilePath& path) {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
277 if (!file_util::PathExists(path)) {
278 BrowserThread::PostTask(
279 BrowserThread::UI, FROM_HERE,
[email protected]5656f8a2011-11-17 16:12:58280 base::Bind(&DownloadManagerImpl::OnFileRemovalDetected,
281 this,
282 db_handle));
[email protected]9fc114672011-06-15 08:17:48283 }
284}
285
[email protected]5656f8a2011-11-17 16:12:58286void DownloadManagerImpl::OnFileRemovalDetected(int64 db_handle) {
[email protected]9fc114672011-06-15 08:17:48287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
288 DownloadMap::iterator it = history_downloads_.find(db_handle);
289 if (it != history_downloads_.end()) {
290 DownloadItem* download_item = it->second;
291 download_item->OnDownloadedFileRemoved();
292 }
293}
294
[email protected]5656f8a2011-11-17 16:12:58295void DownloadManagerImpl::RestartDownload(
[email protected]aa9881c2011-08-15 18:01:12296 int32 download_id) {
[email protected]ca4b5fa32010-10-09 12:42:18297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
initial.commit09911bf2008-07-26 23:55:29298
[email protected]4cd82f72011-05-23 19:15:01299 DownloadItem* download = GetActiveDownloadItem(download_id);
300 if (!download)
301 return;
302
303 VLOG(20) << __FUNCTION__ << "()"
304 << " download = " << download->DebugString(true);
305
[email protected]c09a8fd2011-11-21 19:54:50306 FilePath suggested_path = download->GetSuggestedPath();
[email protected]4cd82f72011-05-23 19:15:01307
[email protected]c09a8fd2011-11-21 19:54:50308 if (download->PromptUserForSaveLocation()) {
initial.commit09911bf2008-07-26 23:55:29309 // We must ask the user for the place to put the download.
[email protected]ae77da82011-11-01 19:17:29310 TabContents* contents = download->GetTabContents();
[email protected]99cb7f82011-07-28 17:27:26311
[email protected]4cd82f72011-05-23 19:15:01312 // |id_ptr| will be deleted in either FileSelected() or
[email protected]93af2272011-09-21 18:29:17313 // FileSelectionCancelled().
[email protected]4cd82f72011-05-23 19:15:01314 int32* id_ptr = new int32;
315 *id_ptr = download_id;
[email protected]795b76a2011-12-14 16:52:53316 FilePath target_path;
317 // If |download| is a potentially dangerous file, then |suggested_path|
318 // contains the intermediate name instead of the final download
319 // filename. The latter is GetTargetName().
320 if (download->GetDangerType() != DownloadStateInfo::NOT_DANGEROUS)
321 target_path = suggested_path.DirName().Append(download->GetTargetName());
322 else
323 target_path = suggested_path;
[email protected]99cb7f82011-07-28 17:27:26324
[email protected]795b76a2011-12-14 16:52:53325 delegate_->ChooseDownloadPath(contents, target_path,
326 reinterpret_cast<void*>(id_ptr));
[email protected]f5920322011-03-24 20:34:16327 FOR_EACH_OBSERVER(Observer, observers_,
[email protected]fed38252011-07-08 17:26:50328 SelectFileDialogDisplayed(download_id));
initial.commit09911bf2008-07-26 23:55:29329 } else {
330 // No prompting for download, just continue with the suggested name.
[email protected]4cd82f72011-05-23 19:15:01331 ContinueDownloadWithPath(download, suggested_path);
initial.commit09911bf2008-07-26 23:55:29332 }
333}
334
[email protected]fc03de22011-12-06 23:28:12335content::BrowserContext* DownloadManagerImpl::BrowserContext() const {
[email protected]5656f8a2011-11-17 16:12:58336 return browser_context_;
337}
338
339FilePath DownloadManagerImpl::LastDownloadPath() {
340 return last_download_path_;
341}
342
343void DownloadManagerImpl::CreateDownloadItem(
[email protected]594e66fe2011-10-25 22:49:41344 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle) {
[email protected]c2e76012010-12-23 21:10:29345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
346
[email protected]c09a8fd2011-11-21 19:54:50347 DownloadItem* download = new DownloadItemImpl(
[email protected]ae77da82011-11-01 19:17:29348 this, *info, new DownloadRequestHandle(request_handle),
349 browser_context_->IsOffTheRecord());
[email protected]2909e342011-10-29 00:46:53350 int32 download_id = info->download_id.local();
[email protected]4cd82f72011-05-23 19:15:01351 DCHECK(!ContainsKey(in_progress_, download_id));
[email protected]d8472d92011-08-26 20:15:20352
353 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
[email protected]821960a2011-08-23 20:40:03354 CHECK(!ContainsKey(active_downloads_, download_id));
[email protected]c2e76012010-12-23 21:10:29355 downloads_.insert(download);
[email protected]4cd82f72011-05-23 19:15:01356 active_downloads_[download_id] = download;
[email protected]c2e76012010-12-23 21:10:29357}
358
[email protected]fc03de22011-12-06 23:28:12359DownloadItem* DownloadManagerImpl::CreateSavePackageDownloadItem(
360 const FilePath& main_file_path,
361 const GURL& page_url,
362 bool is_otr,
363 DownloadItem::Observer* observer) {
364 DownloadItem* download = new DownloadItemImpl(
365 this, main_file_path, page_url, is_otr, GetNextId());
366
367 download->AddObserver(observer);
368
369 DCHECK(!ContainsKey(save_page_downloads_, download->GetId()));
370 downloads_.insert(download);
371 save_page_downloads_[download->GetId()] = download;
372
373 // Will notify the observer in the callback.
374 delegate_->AddItemToPersistentStore(download);
375
376 return download;
377}
378
[email protected]795b76a2011-12-14 16:52:53379// For non-safe downloads with no prompting, |chosen_file| is the intermediate
380// path for saving the in-progress download. The final target filename for these
381// is |download->GetTargetName()|. For all other downloads (non-safe downloads
382// for which we have prompted for a save location, and all safe downloads),
383// |chosen_file| is the final target download path.
[email protected]5656f8a2011-11-17 16:12:58384void DownloadManagerImpl::ContinueDownloadWithPath(
385 DownloadItem* download, const FilePath& chosen_file) {
[email protected]ca4b5fa32010-10-09 12:42:18386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]4cd82f72011-05-23 19:15:01387 DCHECK(download);
[email protected]aa033af2010-07-27 18:16:39388
[email protected]c09a8fd2011-11-21 19:54:50389 int32 download_id = download->GetId();
initial.commit09911bf2008-07-26 23:55:29390
[email protected]70850c72011-01-11 17:31:27391 // NOTE(ahendrickson) Eventually |active_downloads_| will replace
392 // |in_progress_|, but we don't want to change the semantics yet.
[email protected]4cd82f72011-05-23 19:15:01393 DCHECK(!ContainsKey(in_progress_, download_id));
[email protected]70850c72011-01-11 17:31:27394 DCHECK(ContainsKey(downloads_, download));
[email protected]4cd82f72011-05-23 19:15:01395 DCHECK(ContainsKey(active_downloads_, download_id));
[email protected]70850c72011-01-11 17:31:27396
[email protected]4cd82f72011-05-23 19:15:01397 // Make sure the initial file name is set only once.
[email protected]fdd2715c2011-12-09 22:24:20398 DCHECK(download->GetFullPath().empty());
[email protected]4cd82f72011-05-23 19:15:01399 download->OnPathDetermined(chosen_file);
[email protected]4cd82f72011-05-23 19:15:01400
401 VLOG(20) << __FUNCTION__ << "()"
402 << " download = " << download->DebugString(true);
403
404 in_progress_[download_id] = download;
[email protected]5f8589fe2011-08-17 20:58:39405 UpdateDownloadProgress(); // Reflect entry into in_progress_.
initial.commit09911bf2008-07-26 23:55:29406
[email protected]adb2f3d12011-01-23 16:24:54407 // Rename to intermediate name.
[email protected]f5920322011-03-24 20:34:16408 FilePath download_path;
[email protected]ec865262011-08-23 20:01:48409 if (!delegate_->OverrideIntermediatePath(download, &download_path))
[email protected]c09a8fd2011-11-21 19:54:50410 download_path = download->GetFullPath();
[email protected]594cd7d2010-07-21 03:23:56411
[email protected]f5920322011-03-24 20:34:16412 BrowserThread::PostTask(
413 BrowserThread::FILE, FROM_HERE,
[email protected]fabf36d22011-10-28 21:50:17414 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile,
[email protected]fc03de22011-12-06 23:28:12415 file_manager_, download->GetGlobalId(),
416 download_path));
[email protected]f5920322011-03-24 20:34:16417
418 download->Rename(download_path);
419
[email protected]2588ea9d2011-08-22 20:59:53420 delegate_->AddItemToPersistentStore(download);
initial.commit09911bf2008-07-26 23:55:29421}
422
[email protected]e384fd82011-11-30 06:37:20423void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 bytes_so_far,
424 int64 bytes_per_sec) {
[email protected]70850c72011-01-11 17:31:27425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
426 DownloadMap::iterator it = active_downloads_.find(download_id);
427 if (it != active_downloads_.end()) {
initial.commit09911bf2008-07-26 23:55:29428 DownloadItem* download = it->second;
[email protected]bf68a00b2011-04-07 17:28:26429 if (download->IsInProgress()) {
[email protected]e384fd82011-11-30 06:37:20430 download->UpdateProgress(bytes_so_far, bytes_per_sec);
[email protected]5f8589fe2011-08-17 20:58:39431 UpdateDownloadProgress(); // Reflect size updates.
[email protected]2588ea9d2011-08-22 20:59:53432 delegate_->UpdateItemInPersistentStore(download);
[email protected]70850c72011-01-11 17:31:27433 }
initial.commit09911bf2008-07-26 23:55:29434 }
435}
436
[email protected]5656f8a2011-11-17 16:12:58437void DownloadManagerImpl::OnResponseCompleted(int32 download_id,
438 int64 size,
439 const std::string& hash) {
[email protected]33c6d3f12011-09-04 00:00:54440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]da6e3922010-11-24 21:45:50441 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
442 << " size = " << size;
[email protected]9d7ef802011-02-25 19:03:35443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]9ccbb372008-10-10 18:50:32444
[email protected]c4f02c42011-01-24 21:55:06445 // If it's not in active_downloads_, that means it was cancelled; just
446 // ignore the notification.
447 if (active_downloads_.count(download_id) == 0)
448 return;
449
[email protected]adb2f3d12011-01-23 16:24:54450 DownloadItem* download = active_downloads_[download_id];
[email protected]ac4af82f2011-11-10 19:09:37451 download->OnAllDataSaved(size, hash);
452 delegate_->OnResponseCompleted(download);
[email protected]b09f1282011-09-14 00:37:45453
[email protected]fc03de22011-12-06 23:28:12454 download->MaybeCompleteDownload();
[email protected]adb2f3d12011-01-23 16:24:54455}
[email protected]9ccbb372008-10-10 18:50:32456
[email protected]fc03de22011-12-06 23:28:12457void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const {
[email protected]5cd11b6e2011-06-10 20:30:59458 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
[email protected]c09a8fd2011-11-21 19:54:50459 if (download->GetState() == DownloadItem::REMOVING) {
[email protected]7d413112011-06-16 18:50:17460 CHECK(!ContainsKey(downloads_, download));
[email protected]c09a8fd2011-11-21 19:54:50461 CHECK(!ContainsKey(active_downloads_, download->GetId()));
462 CHECK(!ContainsKey(in_progress_, download->GetId()));
463 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle()));
[email protected]7d413112011-06-16 18:50:17464 return;
465 }
466
467 // Should be in downloads_ if we're not REMOVING.
468 CHECK(ContainsKey(downloads_, download));
469
470 // Check history_downloads_ consistency.
[email protected]c09a8fd2011-11-21 19:54:50471 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) {
472 CHECK(ContainsKey(history_downloads_, download->GetDbHandle()));
[email protected]7d413112011-06-16 18:50:17473 } else {
474 // TODO(rdsmith): Somewhat painful; make sure to disable in
475 // release builds after resolution of http://crbug.com/85408.
[email protected]fc03de22011-12-06 23:28:12476 for (DownloadMap::const_iterator it = history_downloads_.begin();
[email protected]7d413112011-06-16 18:50:17477 it != history_downloads_.end(); ++it) {
478 CHECK(it->second != download);
479 }
480 }
481
[email protected]c09a8fd2011-11-21 19:54:50482 int64 state = download->GetState();
[email protected]61b75a52011-08-29 16:34:34483 base::debug::Alias(&state);
[email protected]c09a8fd2011-11-21 19:54:50484 if (ContainsKey(active_downloads_, download->GetId())) {
485 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle)
486 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState());
487 if (DownloadItem::IN_PROGRESS != download->GetState())
488 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle());
[email protected]f9a2997f2011-09-23 16:54:07489 }
[email protected]c09a8fd2011-11-21 19:54:50490 if (DownloadItem::IN_PROGRESS == download->GetState())
491 CHECK(ContainsKey(active_downloads_, download->GetId()));
[email protected]5cd11b6e2011-06-10 20:30:59492}
493
[email protected]5656f8a2011-11-17 16:12:58494bool DownloadManagerImpl::IsDownloadReadyForCompletion(DownloadItem* download) {
[email protected]adb2f3d12011-01-23 16:24:54495 // If we don't have all the data, the download is not ready for
496 // completion.
[email protected]c09a8fd2011-11-21 19:54:50497 if (!download->AllDataSaved())
[email protected]adb2f3d12011-01-23 16:24:54498 return false;
[email protected]6a7fb042010-02-01 16:30:47499
[email protected]9d7ef802011-02-25 19:03:35500 // If the download is dangerous, but not yet validated, it's not ready for
501 // completion.
[email protected]c09a8fd2011-11-21 19:54:50502 if (download->GetSafetyState() == DownloadItem::DANGEROUS)
[email protected]9d7ef802011-02-25 19:03:35503 return false;
504
[email protected]adb2f3d12011-01-23 16:24:54505 // If the download isn't active (e.g. has been cancelled) it's not
506 // ready for completion.
[email protected]c09a8fd2011-11-21 19:54:50507 if (active_downloads_.count(download->GetId()) == 0)
[email protected]adb2f3d12011-01-23 16:24:54508 return false;
509
510 // If the download hasn't been inserted into the history system
511 // (which occurs strictly after file name determination, intermediate
512 // file rename, and UI display) then it's not ready for completion.
[email protected]c09a8fd2011-11-21 19:54:50513 if (download->GetDbHandle() == DownloadItem::kUninitializedHandle)
[email protected]7054b592011-06-22 14:46:42514 return false;
515
516 return true;
[email protected]adb2f3d12011-01-23 16:24:54517}
518
[email protected]5656f8a2011-11-17 16:12:58519void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) {
[email protected]adb2f3d12011-01-23 16:24:54520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
521 VLOG(20) << __FUNCTION__ << "()" << " download = "
522 << download->DebugString(false);
523
524 if (!IsDownloadReadyForCompletion(download))
[email protected]9ccbb372008-10-10 18:50:32525 return;
[email protected]9ccbb372008-10-10 18:50:32526
[email protected]adb2f3d12011-01-23 16:24:54527 // TODO(rdsmith): DCHECK that we only pass through this point
528 // once per download. The natural way to do this is by a state
529 // transition on the DownloadItem.
[email protected]594cd7d2010-07-21 03:23:56530
[email protected]adb2f3d12011-01-23 16:24:54531 // Confirm we're in the proper set of states to be here;
[email protected]9d7ef802011-02-25 19:03:35532 // in in_progress_, have all data, have a history handle, (validated or safe).
[email protected]c09a8fd2011-11-21 19:54:50533 DCHECK_NE(DownloadItem::DANGEROUS, download->GetSafetyState());
534 DCHECK_EQ(1u, in_progress_.count(download->GetId()));
535 DCHECK(download->AllDataSaved());
536 DCHECK(download->GetDbHandle() != DownloadItem::kUninitializedHandle);
537 DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle()));
[email protected]adb2f3d12011-01-23 16:24:54538
[email protected]c2918652011-11-01 18:50:23539 // Give the delegate a chance to override.
540 if (!delegate_->ShouldCompleteDownload(download))
541 return;
542
[email protected]adb2f3d12011-01-23 16:24:54543 VLOG(20) << __FUNCTION__ << "()" << " executing: download = "
544 << download->DebugString(false);
545
546 // Remove the id from in_progress
[email protected]c09a8fd2011-11-21 19:54:50547 in_progress_.erase(download->GetId());
[email protected]5f8589fe2011-08-17 20:58:39548 UpdateDownloadProgress(); // Reflect removal from in_progress_.
[email protected]adb2f3d12011-01-23 16:24:54549
[email protected]2588ea9d2011-08-22 20:59:53550 delegate_->UpdateItemInPersistentStore(download);
[email protected]adb2f3d12011-01-23 16:24:54551
[email protected]f5920322011-03-24 20:34:16552 // Finish the download.
[email protected]48837962011-04-19 17:03:29553 download->OnDownloadCompleting(file_manager_);
[email protected]9ccbb372008-10-10 18:50:32554}
555
[email protected]fc03de22011-12-06 23:28:12556void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) {
[email protected]70850c72011-01-11 17:31:27557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]cc3c7c092011-05-09 18:40:21558 DCHECK(download);
[email protected]2588ea9d2011-08-22 20:59:53559 delegate_->UpdateItemInPersistentStore(download);
[email protected]fc03de22011-12-06 23:28:12560 active_downloads_.erase(download->GetId());
561 AssertStateConsistent(download);
[email protected]70850c72011-01-11 17:31:27562}
563
[email protected]5656f8a2011-11-17 16:12:58564void DownloadManagerImpl::OnDownloadRenamedToFinalName(
565 int download_id,
566 const FilePath& full_path,
567 int uniquifier) {
[email protected]da6e3922010-11-24 21:45:50568 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
[email protected]f5920322011-03-24 20:34:16569 << " full_path = \"" << full_path.value() << "\""
570 << " uniquifier = " << uniquifier;
[email protected]ca4b5fa32010-10-09 12:42:18571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]f5920322011-03-24 20:34:16572
[email protected]2e030682010-07-23 19:45:36573 DownloadItem* item = GetDownloadItem(download_id);
574 if (!item)
575 return;
[email protected]6cade212008-12-03 00:32:22576
[email protected]795b76a2011-12-14 16:52:53577 if (item->GetDangerType() == DownloadStateInfo::NOT_DANGEROUS ||
578 item->PromptUserForSaveLocation()) {
579 DCHECK_EQ(0, uniquifier)
580 << "We should not uniquify user supplied filenames or safe filenames "
581 "that have already been uniquified.";
[email protected]8fa1eeb52011-04-13 14:18:02582 }
583
[email protected]fabf36d22011-10-28 21:50:17584 BrowserThread::PostTask(
585 BrowserThread::FILE, FROM_HERE,
586 base::Bind(&DownloadFileManager::CompleteDownload,
[email protected]c09a8fd2011-11-21 19:54:50587 file_manager_, item->GetGlobalId()));
[email protected]9ccbb372008-10-10 18:50:32588
[email protected]f5920322011-03-24 20:34:16589 if (uniquifier)
[email protected]c09a8fd2011-11-21 19:54:50590 item->SetPathUniquifier(uniquifier);
[email protected]9ccbb372008-10-10 18:50:32591
[email protected]f5920322011-03-24 20:34:16592 item->OnDownloadRenamedToFinalName(full_path);
[email protected]2588ea9d2011-08-22 20:59:53593 delegate_->UpdatePathForItemInPersistentStore(item, full_path);
initial.commit09911bf2008-07-26 23:55:29594}
595
[email protected]5656f8a2011-11-17 16:12:58596void DownloadManagerImpl::CancelDownload(int32 download_id) {
[email protected]93af2272011-09-21 18:29:17597 DownloadItem* download = GetActiveDownload(download_id);
598 // A cancel at the right time could remove the download from the
599 // |active_downloads_| map before we get here.
600 if (!download)
601 return;
602
603 download->Cancel(true);
604}
605
[email protected]fc03de22011-12-06 23:28:12606void DownloadManagerImpl::DownloadCancelled(DownloadItem* download) {
[email protected]d8472d92011-08-26 20:15:20607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]d8472d92011-08-26 20:15:20608
609 VLOG(20) << __FUNCTION__ << "()"
[email protected]da6e3922010-11-24 21:45:50610 << " download = " << download->DebugString(true);
611
[email protected]93af2272011-09-21 18:29:17612 RemoveFromActiveList(download);
[email protected]47a881b2011-08-29 22:59:21613 // This function is called from the DownloadItem, so DI state
614 // should already have been updated.
[email protected]fc03de22011-12-06 23:28:12615 AssertStateConsistent(download);
initial.commit09911bf2008-07-26 23:55:29616
[email protected]15d90ba2011-11-03 03:41:55617 if (file_manager_)
618 download->OffThreadCancel(file_manager_);
initial.commit09911bf2008-07-26 23:55:29619}
620
[email protected]5656f8a2011-11-17 16:12:58621void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id,
622 int64 size,
623 InterruptReason reason) {
[email protected]47a881b2011-08-29 22:59:21624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
625
626 DownloadItem* download = GetActiveDownload(download_id);
627 if (!download)
628 return;
629
[email protected]be76b7e2011-10-13 12:57:57630 VLOG(20) << __FUNCTION__ << "()"
631 << " reason " << InterruptReasonDebugString(reason)
[email protected]c09a8fd2011-11-21 19:54:50632 << " at offset " << download->GetReceivedBytes()
[email protected]47a881b2011-08-29 22:59:21633 << " size = " << size
634 << " download = " << download->DebugString(true);
635
[email protected]93af2272011-09-21 18:29:17636 RemoveFromActiveList(download);
[email protected]be76b7e2011-10-13 12:57:57637 download->Interrupted(size, reason);
[email protected]93af2272011-09-21 18:29:17638 download->OffThreadCancel(file_manager_);
[email protected]47a881b2011-08-29 22:59:21639}
640
[email protected]5656f8a2011-11-17 16:12:58641DownloadItem* DownloadManagerImpl::GetActiveDownload(int32 download_id) {
[email protected]bf68a00b2011-04-07 17:28:26642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
643 DownloadMap::iterator it = active_downloads_.find(download_id);
[email protected]bf68a00b2011-04-07 17:28:26644 if (it == active_downloads_.end())
[email protected]47a881b2011-08-29 22:59:21645 return NULL;
[email protected]bf68a00b2011-04-07 17:28:26646
647 DownloadItem* download = it->second;
648
[email protected]47a881b2011-08-29 22:59:21649 DCHECK(download);
[email protected]c09a8fd2011-11-21 19:54:50650 DCHECK_EQ(download_id, download->GetId());
[email protected]4cd82f72011-05-23 19:15:01651
[email protected]47a881b2011-08-29 22:59:21652 return download;
653}
[email protected]54610672011-07-18 18:24:43654
[email protected]5656f8a2011-11-17 16:12:58655void DownloadManagerImpl::RemoveFromActiveList(DownloadItem* download) {
[email protected]93af2272011-09-21 18:29:17656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
657 DCHECK(download);
658
659 // Clean up will happen when the history system create callback runs if we
660 // don't have a valid db_handle yet.
[email protected]c09a8fd2011-11-21 19:54:50661 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) {
662 in_progress_.erase(download->GetId());
663 active_downloads_.erase(download->GetId());
[email protected]93af2272011-09-21 18:29:17664 UpdateDownloadProgress(); // Reflect removal from in_progress_.
665 delegate_->UpdateItemInPersistentStore(download);
666 }
667}
668
[email protected]5656f8a2011-11-17 16:12:58669content::DownloadManagerDelegate* DownloadManagerImpl::delegate() const {
670 return delegate_;
671}
672
673void DownloadManagerImpl::SetDownloadManagerDelegate(
[email protected]1bd0ef12011-10-20 05:24:17674 content::DownloadManagerDelegate* delegate) {
[email protected]9bb54ee2011-10-12 17:43:35675 delegate_ = delegate;
676}
677
[email protected]5656f8a2011-11-17 16:12:58678void DownloadManagerImpl::UpdateDownloadProgress() {
[email protected]5f8589fe2011-08-17 20:58:39679 delegate_->DownloadProgressUpdated();
[email protected]6a7fb042010-02-01 16:30:47680}
681
[email protected]5656f8a2011-11-17 16:12:58682int DownloadManagerImpl::RemoveDownloadItems(
[email protected]6d0146c2011-08-04 19:13:04683 const DownloadVector& pending_deletes) {
684 if (pending_deletes.empty())
685 return 0;
686
687 // Delete from internal maps.
688 for (DownloadVector::const_iterator it = pending_deletes.begin();
689 it != pending_deletes.end();
690 ++it) {
691 DownloadItem* download = *it;
692 DCHECK(download);
[email protected]c09a8fd2011-11-21 19:54:50693 history_downloads_.erase(download->GetDbHandle());
694 save_page_downloads_.erase(download->GetId());
[email protected]6d0146c2011-08-04 19:13:04695 downloads_.erase(download);
696 }
697
698 // Tell observers to refresh their views.
699 NotifyModelChanged();
700
701 // Delete the download items themselves.
702 const int num_deleted = static_cast<int>(pending_deletes.size());
703 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
704 return num_deleted;
705}
706
[email protected]fc03de22011-12-06 23:28:12707void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) {
708 if (history_downloads_.find(download->GetDbHandle()) ==
709 history_downloads_.end())
[email protected]93af2272011-09-21 18:29:17710 return;
711
712 // Make history update.
[email protected]93af2272011-09-21 18:29:17713 delegate_->RemoveItemFromPersistentStore(download);
initial.commit09911bf2008-07-26 23:55:29714
715 // Remove from our tables and delete.
[email protected]6d0146c2011-08-04 19:13:04716 int downloads_count = RemoveDownloadItems(DownloadVector(1, download));
[email protected]f04182f32010-12-10 19:12:07717 DCHECK_EQ(1, downloads_count);
initial.commit09911bf2008-07-26 23:55:29718}
719
[email protected]5656f8a2011-11-17 16:12:58720int DownloadManagerImpl::RemoveDownloadsBetween(const base::Time remove_begin,
721 const base::Time remove_end) {
[email protected]2588ea9d2011-08-22 20:59:53722 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end);
initial.commit09911bf2008-07-26 23:55:29723
[email protected]a312a442010-12-15 23:40:33724 // All downloads visible to the user will be in the history,
725 // so scan that map.
[email protected]6d0146c2011-08-04 19:13:04726 DownloadVector pending_deletes;
727 for (DownloadMap::const_iterator it = history_downloads_.begin();
728 it != history_downloads_.end();
729 ++it) {
initial.commit09911bf2008-07-26 23:55:29730 DownloadItem* download = it->second;
[email protected]c09a8fd2011-11-21 19:54:50731 if (download->GetStartTime() >= remove_begin &&
732 (remove_end.is_null() || download->GetStartTime() < remove_end) &&
[email protected]6d0146c2011-08-04 19:13:04733 (download->IsComplete() || download->IsCancelled())) {
[email protected]fc03de22011-12-06 23:28:12734 AssertStateConsistent(download);
[email protected]78b8fcc92009-03-31 17:36:28735 pending_deletes.push_back(download);
initial.commit09911bf2008-07-26 23:55:29736 }
initial.commit09911bf2008-07-26 23:55:29737 }
[email protected]6d0146c2011-08-04 19:13:04738 return RemoveDownloadItems(pending_deletes);
initial.commit09911bf2008-07-26 23:55:29739}
740
[email protected]5656f8a2011-11-17 16:12:58741int DownloadManagerImpl::RemoveDownloads(const base::Time remove_begin) {
[email protected]e93d2822009-01-30 05:59:59742 return RemoveDownloadsBetween(remove_begin, base::Time());
initial.commit09911bf2008-07-26 23:55:29743}
744
[email protected]5656f8a2011-11-17 16:12:58745int DownloadManagerImpl::RemoveAllDownloads() {
[email protected]da4a5582011-10-17 19:08:06746 download_stats::RecordClearAllSize(history_downloads_.size());
[email protected]d41355e6f2009-04-07 21:21:12747 // The null times make the date range unbounded.
748 return RemoveDownloadsBetween(base::Time(), base::Time());
749}
750
initial.commit09911bf2008-07-26 23:55:29751// Initiate a download of a specific URL. We send the request to the
752// ResourceDispatcherHost, and let it send us responses like a regular
753// download.
[email protected]5656f8a2011-11-17 16:12:58754void DownloadManagerImpl::DownloadUrl(const GURL& url,
755 const GURL& referrer,
756 const std::string& referrer_charset,
757 TabContents* tab_contents) {
[email protected]ae8945192010-07-20 16:56:26758 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(),
759 tab_contents);
[email protected]6aa4a1c02010-01-15 18:49:58760}
761
[email protected]5656f8a2011-11-17 16:12:58762void DownloadManagerImpl::DownloadUrlToFile(const GURL& url,
763 const GURL& referrer,
764 const std::string& referrer_charset,
765 const DownloadSaveInfo& save_info,
766 TabContents* tab_contents) {
[email protected]57c6a652009-05-04 07:58:34767 DCHECK(tab_contents);
[email protected]c79a0c02011-08-22 22:37:37768 ResourceDispatcherHost* resource_dispatcher_host =
769 content::GetContentClient()->browser()->GetResourceDispatcherHost();
[email protected]ed24fad2011-05-10 22:44:01770 // We send a pointer to content::ResourceContext, instead of the usual
771 // reference, so that a copy of the object isn't made.
[email protected]fabf36d22011-10-28 21:50:17772 // base::Bind can't handle 7 args, so we use URLParams and RenderParams.
773 BrowserThread::PostTask(
774 BrowserThread::IO, FROM_HERE,
775 base::Bind(&BeginDownload,
776 URLParams(url, referrer), save_info, resource_dispatcher_host,
[email protected]f3b1a082011-11-18 00:34:30777 RenderParams(tab_contents->GetRenderProcessHost()->GetID(),
[email protected]fabf36d22011-10-28 21:50:17778 tab_contents->render_view_host()->routing_id()),
779 &tab_contents->browser_context()->GetResourceContext()));
initial.commit09911bf2008-07-26 23:55:29780}
781
[email protected]5656f8a2011-11-17 16:12:58782void DownloadManagerImpl::AddObserver(Observer* observer) {
initial.commit09911bf2008-07-26 23:55:29783 observers_.AddObserver(observer);
784 observer->ModelChanged();
785}
786
[email protected]5656f8a2011-11-17 16:12:58787void DownloadManagerImpl::RemoveObserver(Observer* observer) {
initial.commit09911bf2008-07-26 23:55:29788 observers_.RemoveObserver(observer);
789}
790
[email protected]5656f8a2011-11-17 16:12:58791bool DownloadManagerImpl::IsDownloadProgressKnown() const {
[email protected]45f432e942011-10-25 18:17:22792 for (DownloadMap::const_iterator i = in_progress_.begin();
[email protected]073ed7b2010-09-27 09:20:02793 i != in_progress_.end(); ++i) {
[email protected]c09a8fd2011-11-21 19:54:50794 if (i->second->GetTotalBytes() <= 0)
[email protected]073ed7b2010-09-27 09:20:02795 return false;
796 }
797
798 return true;
799}
800
[email protected]5656f8a2011-11-17 16:12:58801int64 DownloadManagerImpl::GetInProgressDownloadCount() const {
[email protected]073ed7b2010-09-27 09:20:02802 return in_progress_.size();
803}
804
[email protected]5656f8a2011-11-17 16:12:58805int64 DownloadManagerImpl::GetReceivedDownloadBytes() const {
[email protected]073ed7b2010-09-27 09:20:02806 DCHECK(IsDownloadProgressKnown());
807 int64 received_bytes = 0;
[email protected]45f432e942011-10-25 18:17:22808 for (DownloadMap::const_iterator i = in_progress_.begin();
[email protected]073ed7b2010-09-27 09:20:02809 i != in_progress_.end(); ++i) {
[email protected]c09a8fd2011-11-21 19:54:50810 received_bytes += i->second->GetReceivedBytes();
[email protected]073ed7b2010-09-27 09:20:02811 }
812 return received_bytes;
813}
814
[email protected]5656f8a2011-11-17 16:12:58815int64 DownloadManagerImpl::GetTotalDownloadBytes() const {
[email protected]073ed7b2010-09-27 09:20:02816 DCHECK(IsDownloadProgressKnown());
817 int64 total_bytes = 0;
[email protected]45f432e942011-10-25 18:17:22818 for (DownloadMap::const_iterator i = in_progress_.begin();
[email protected]073ed7b2010-09-27 09:20:02819 i != in_progress_.end(); ++i) {
[email protected]c09a8fd2011-11-21 19:54:50820 total_bytes += i->second->GetTotalBytes();
[email protected]073ed7b2010-09-27 09:20:02821 }
822 return total_bytes;
823}
824
[email protected]5656f8a2011-11-17 16:12:58825void DownloadManagerImpl::FileSelected(const FilePath& path, void* params) {
[email protected]4cd82f72011-05-23 19:15:01826 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
827
828 int32* id_ptr = reinterpret_cast<int32*>(params);
829 DCHECK(id_ptr != NULL);
830 int32 download_id = *id_ptr;
831 delete id_ptr;
832
833 DownloadItem* download = GetActiveDownloadItem(download_id);
834 if (!download)
835 return;
836 VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\""
837 << " download = " << download->DebugString(true);
838
[email protected]c09a8fd2011-11-21 19:54:50839 if (download->PromptUserForSaveLocation())
[email protected]7ae7c2cb2009-01-06 23:31:41840 last_download_path_ = path.DirName();
[email protected]287b86b2011-02-26 00:11:35841
[email protected]4cd82f72011-05-23 19:15:01842 // Make sure the initial file name is set only once.
843 ContinueDownloadWithPath(download, path);
initial.commit09911bf2008-07-26 23:55:29844}
845
[email protected]5656f8a2011-11-17 16:12:58846void DownloadManagerImpl::FileSelectionCanceled(void* params) {
initial.commit09911bf2008-07-26 23:55:29847 // The user didn't pick a place to save the file, so need to cancel the
848 // download that's already in progress to the temporary location.
[email protected]4cd82f72011-05-23 19:15:01849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
850 int32* id_ptr = reinterpret_cast<int32*>(params);
851 DCHECK(id_ptr != NULL);
852 int32 download_id = *id_ptr;
853 delete id_ptr;
854
855 DownloadItem* download = GetActiveDownloadItem(download_id);
856 if (!download)
857 return;
858
859 VLOG(20) << __FUNCTION__ << "()"
860 << " download = " << download->DebugString(true);
861
[email protected]93af2272011-09-21 18:29:17862 // TODO(ahendrickson) -- This currently has no effect, as the download is
863 // not put on the active list until the file selection is complete. Need
864 // to put it on the active list earlier in the process.
865 RemoveFromActiveList(download);
866
867 download->OffThreadCancel(file_manager_);
[email protected]4cd82f72011-05-23 19:15:01868}
869
initial.commit09911bf2008-07-26 23:55:29870// Operations posted to us from the history service ----------------------------
871
872// The history service has retrieved all download entries. 'entries' contains
[email protected]bb1a4212011-08-22 22:38:25873// 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time).
[email protected]5656f8a2011-11-17 16:12:58874void DownloadManagerImpl::OnPersistentStoreQueryComplete(
[email protected]bb1a4212011-08-22 22:38:25875 std::vector<DownloadPersistentStoreInfo>* entries) {
[email protected]d8472d92011-08-26 20:15:20876 // TODO(rdsmith): Remove this and related logic when
[email protected]639ddad2011-10-05 02:53:47877 // http://crbug.com/85408 is fixed.
[email protected]d8472d92011-08-26 20:15:20878 largest_db_handle_in_history_ = 0;
879
initial.commit09911bf2008-07-26 23:55:29880 for (size_t i = 0; i < entries->size(); ++i) {
[email protected]fc03de22011-12-06 23:28:12881 DownloadItem* download = new DownloadItemImpl(
882 this, GetNextId(), entries->at(i));
[email protected]d8472d92011-08-26 20:15:20883 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
[email protected]c09a8fd2011-11-21 19:54:50884 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle()));
[email protected]f04182f32010-12-10 19:12:07885 downloads_.insert(download);
[email protected]c09a8fd2011-11-21 19:54:50886 history_downloads_[download->GetDbHandle()] = download;
[email protected]da6e3922010-11-24 21:45:50887 VLOG(20) << __FUNCTION__ << "()" << i << ">"
888 << " download = " << download->DebugString(true);
[email protected]d8472d92011-08-26 20:15:20889
[email protected]c09a8fd2011-11-21 19:54:50890 if (download->GetDbHandle() > largest_db_handle_in_history_)
891 largest_db_handle_in_history_ = download->GetDbHandle();
initial.commit09911bf2008-07-26 23:55:29892 }
[email protected]b0ab1d42010-02-24 19:29:28893 NotifyModelChanged();
[email protected]9fc114672011-06-15 08:17:48894 CheckForHistoryFilesRemoval();
initial.commit09911bf2008-07-26 23:55:29895}
896
[email protected]5656f8a2011-11-17 16:12:58897void DownloadManagerImpl::AddDownloadItemToHistory(DownloadItem* download,
898 int64 db_handle) {
[email protected]70850c72011-01-11 17:31:27899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]d2a8fb72010-01-21 05:31:42900
[email protected]639ddad2011-10-05 02:53:47901 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408
[email protected]1e9fe7ff2011-06-24 17:37:33902 // is fixed.
[email protected]2588ea9d2011-08-22 20:59:53903 CHECK_NE(DownloadItem::kUninitializedHandle, db_handle);
[email protected]1e9fe7ff2011-06-24 17:37:33904
[email protected]da4a5582011-10-17 19:08:06905 download_stats::RecordHistorySize(history_downloads_.size());
906
[email protected]c09a8fd2011-11-21 19:54:50907 DCHECK(download->GetDbHandle() == DownloadItem::kUninitializedHandle);
908 download->SetDbHandle(db_handle);
[email protected]5bcd73eb2011-03-23 21:14:02909
[email protected]639ddad2011-10-05 02:53:47910 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408
[email protected]d8472d92011-08-26 20:15:20911 // is fixed.
[email protected]c09a8fd2011-11-21 19:54:50912 CHECK(!ContainsKey(history_downloads_, download->GetDbHandle()));
913 history_downloads_[download->GetDbHandle()] = download;
[email protected]6d0146c2011-08-04 19:13:04914
915 // Show in the appropriate browser UI.
916 // This includes buttons to save or cancel, for a dangerous download.
917 ShowDownloadInBrowser(download);
918
919 // Inform interested objects about the new download.
920 NotifyModelChanged();
[email protected]f9a45b02011-06-30 23:49:19921}
922
[email protected]2588ea9d2011-08-22 20:59:53923
[email protected]5656f8a2011-11-17 16:12:58924void DownloadManagerImpl::OnItemAddedToPersistentStore(int32 download_id,
925 int64 db_handle) {
[email protected]2588ea9d2011-08-22 20:59:53926 if (save_page_downloads_.count(download_id)) {
927 OnSavePageItemAddedToPersistentStore(download_id, db_handle);
928 } else if (active_downloads_.count(download_id)) {
929 OnDownloadItemAddedToPersistentStore(download_id, db_handle);
930 }
931 // It's valid that we don't find a matching item, i.e. on shutdown.
932}
933
[email protected]f9a45b02011-06-30 23:49:19934// Once the new DownloadItem's creation info has been committed to the history
935// service, we associate the DownloadItem with the db handle, update our
936// 'history_downloads_' map and inform observers.
[email protected]5656f8a2011-11-17 16:12:58937void DownloadManagerImpl::OnDownloadItemAddedToPersistentStore(
938 int32 download_id, int64 db_handle) {
[email protected]f9a45b02011-06-30 23:49:19939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]19420cc2011-07-18 17:43:45940 DownloadItem* download = GetActiveDownloadItem(download_id);
[email protected]93af2272011-09-21 18:29:17941 if (!download)
[email protected]19420cc2011-07-18 17:43:45942 return;
[email protected]54610672011-07-18 18:24:43943
944 VLOG(20) << __FUNCTION__ << "()" << " db_handle = " << db_handle
945 << " download_id = " << download_id
946 << " download = " << download->DebugString(true);
[email protected]f9a45b02011-06-30 23:49:19947
[email protected]d8472d92011-08-26 20:15:20948 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
[email protected]d8472d92011-08-26 20:15:20949 int64 largest_handle = largest_db_handle_in_history_;
950 base::debug::Alias(&largest_handle);
[email protected]e5107ce2011-09-19 20:36:13951 int32 matching_item_download_id
952 = (ContainsKey(history_downloads_, db_handle) ?
[email protected]c09a8fd2011-11-21 19:54:50953 history_downloads_[db_handle]->GetId() : 0);
[email protected]e5107ce2011-09-19 20:36:13954 base::debug::Alias(&matching_item_download_id);
955
[email protected]61b75a52011-08-29 16:34:34956 CHECK(!ContainsKey(history_downloads_, db_handle));
[email protected]d8472d92011-08-26 20:15:20957
[email protected]f9a45b02011-06-30 23:49:19958 AddDownloadItemToHistory(download, db_handle);
initial.commit09911bf2008-07-26 23:55:29959
[email protected]93af2272011-09-21 18:29:17960 // If the download is still in progress, try to complete it.
961 //
962 // Otherwise, download has been cancelled or interrupted before we've
963 // received the DB handle. We post one final message to the history
964 // service so that it can be properly in sync with the DownloadItem's
965 // completion status, and also inform any observers so that they get
966 // more than just the start notification.
967 if (download->IsInProgress()) {
968 MaybeCompleteDownload(download);
969 } else {
[email protected]639ddad2011-10-05 02:53:47970 // TODO(rdsmith): Convert to DCHECK() when http://crbug.com/85408
[email protected]93af2272011-09-21 18:29:17971 // is fixed.
972 CHECK(download->IsCancelled())
973 << " download = " << download->DebugString(true);
974 in_progress_.erase(download_id);
975 active_downloads_.erase(download_id);
976 delegate_->UpdateItemInPersistentStore(download);
977 download->UpdateObservers();
978 }
initial.commit09911bf2008-07-26 23:55:29979}
980
[email protected]5656f8a2011-11-17 16:12:58981void DownloadManagerImpl::ShowDownloadInBrowser(DownloadItem* download) {
[email protected]8ddbd66a2010-05-21 16:38:34982 // The 'contents' may no longer exist if the user closed the tab before we
[email protected]99cb7f82011-07-28 17:27:26983 // get this start completion event.
[email protected]ae77da82011-11-01 19:17:29984 TabContents* content = download->GetTabContents();
[email protected]99cb7f82011-07-28 17:27:26985
986 // If the contents no longer exists, we ask the embedder to suggest another
987 // tab.
[email protected]da1a27b2011-07-29 23:16:33988 if (!content)
[email protected]aa9881c2011-08-15 18:01:12989 content = delegate_->GetAlternativeTabContentsToNotifyForDownload();
[email protected]5e595482009-05-06 20:16:53990
[email protected]99cb7f82011-07-28 17:27:26991 if (content)
992 content->OnStartDownload(download);
[email protected]5e595482009-05-06 20:16:53993}
994
[email protected]5656f8a2011-11-17 16:12:58995int DownloadManagerImpl::InProgressCount() const {
996 return static_cast<int>(in_progress_.size());
997}
998
[email protected]6cade212008-12-03 00:32:22999// Clears the last download path, used to initialize "save as" dialogs.
[email protected]5656f8a2011-11-17 16:12:581000void DownloadManagerImpl::ClearLastDownloadPath() {
[email protected]7ae7c2cb2009-01-06 23:31:411001 last_download_path_ = FilePath();
[email protected]eea46622009-07-15 20:49:381002}
[email protected]b0ab1d42010-02-24 19:29:281003
[email protected]5656f8a2011-11-17 16:12:581004void DownloadManagerImpl::NotifyModelChanged() {
[email protected]b0ab1d42010-02-24 19:29:281005 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged());
1006}
1007
[email protected]5656f8a2011-11-17 16:12:581008DownloadItem* DownloadManagerImpl::GetDownloadItem(int download_id) {
[email protected]4cd82f72011-05-23 19:15:011009 // The |history_downloads_| map is indexed by the download's db_handle,
1010 // not its id, so we have to iterate.
[email protected]f04182f32010-12-10 19:12:071011 for (DownloadMap::iterator it = history_downloads_.begin();
1012 it != history_downloads_.end(); ++it) {
[email protected]2e030682010-07-23 19:45:361013 DownloadItem* item = it->second;
[email protected]c09a8fd2011-11-21 19:54:501014 if (item->GetId() == download_id)
[email protected]2e030682010-07-23 19:45:361015 return item;
1016 }
1017 return NULL;
1018}
1019
[email protected]5656f8a2011-11-17 16:12:581020DownloadItem* DownloadManagerImpl::GetActiveDownloadItem(int download_id) {
[email protected]93af2272011-09-21 18:29:171021 DCHECK(ContainsKey(active_downloads_, download_id));
[email protected]4cd82f72011-05-23 19:15:011022 DownloadItem* download = active_downloads_[download_id];
1023 DCHECK(download != NULL);
1024 return download;
1025}
1026
[email protected]57fd1252010-12-23 17:24:091027// Confirm that everything in all maps is also in |downloads_|, and that
1028// everything in |downloads_| is also in some other map.
[email protected]5656f8a2011-11-17 16:12:581029void DownloadManagerImpl::AssertContainersConsistent() const {
[email protected]f04182f32010-12-10 19:12:071030#if !defined(NDEBUG)
[email protected]57fd1252010-12-23 17:24:091031 // Turn everything into sets.
[email protected]6d0146c2011-08-04 19:13:041032 const DownloadMap* input_maps[] = {&active_downloads_,
1033 &history_downloads_,
1034 &save_page_downloads_};
1035 DownloadSet active_set, history_set, save_page_set;
1036 DownloadSet* all_sets[] = {&active_set, &history_set, &save_page_set};
1037 DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(all_sets));
[email protected]57fd1252010-12-23 17:24:091038 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) {
1039 for (DownloadMap::const_iterator it = input_maps[i]->begin();
[email protected]6d0146c2011-08-04 19:13:041040 it != input_maps[i]->end(); ++it) {
1041 all_sets[i]->insert(&*it->second);
[email protected]f04182f32010-12-10 19:12:071042 }
1043 }
[email protected]57fd1252010-12-23 17:24:091044
1045 // Check if each set is fully present in downloads, and create a union.
[email protected]57fd1252010-12-23 17:24:091046 DownloadSet downloads_union;
1047 for (int i = 0; i < static_cast<int>(ARRAYSIZE_UNSAFE(all_sets)); i++) {
1048 DownloadSet remainder;
1049 std::insert_iterator<DownloadSet> insert_it(remainder, remainder.begin());
1050 std::set_difference(all_sets[i]->begin(), all_sets[i]->end(),
1051 downloads_.begin(), downloads_.end(),
1052 insert_it);
1053 DCHECK(remainder.empty());
1054 std::insert_iterator<DownloadSet>
1055 insert_union(downloads_union, downloads_union.end());
1056 std::set_union(downloads_union.begin(), downloads_union.end(),
1057 all_sets[i]->begin(), all_sets[i]->end(),
1058 insert_union);
1059 }
1060
1061 // Is everything in downloads_ present in one of the other sets?
1062 DownloadSet remainder;
1063 std::insert_iterator<DownloadSet>
1064 insert_remainder(remainder, remainder.begin());
1065 std::set_difference(downloads_.begin(), downloads_.end(),
1066 downloads_union.begin(), downloads_union.end(),
1067 insert_remainder);
1068 DCHECK(remainder.empty());
[email protected]f04182f32010-12-10 19:12:071069#endif
1070}
1071
[email protected]6d0146c2011-08-04 19:13:041072// SavePackage will call SavePageDownloadFinished upon completion/cancellation.
[email protected]2588ea9d2011-08-22 20:59:531073// The history callback will call OnSavePageItemAddedToPersistentStore.
[email protected]6d0146c2011-08-04 19:13:041074// If the download finishes before the history callback,
[email protected]2588ea9d2011-08-22 20:59:531075// OnSavePageItemAddedToPersistentStore calls SavePageDownloadFinished, ensuring
1076// that the history event is update regardless of the order in which these two
1077// events complete.
[email protected]6d0146c2011-08-04 19:13:041078// If something removes the download item from the download manager (Remove,
1079// Shutdown) the result will be that the SavePage system will not be able to
1080// properly update the download item (which no longer exists) or the download
1081// history, but the action will complete properly anyway. This may lead to the
1082// history entry being wrong on a reload of chrome (specifically in the case of
1083// Initiation -> History Callback -> Removal -> Completion), but there's no way
1084// to solve that without canceling on Remove (which would then update the DB).
1085
[email protected]5656f8a2011-11-17 16:12:581086void DownloadManagerImpl::OnSavePageItemAddedToPersistentStore(
1087 int32 download_id, int64 db_handle) {
[email protected]6d0146c2011-08-04 19:13:041088 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1089
1090 DownloadMap::const_iterator it = save_page_downloads_.find(download_id);
1091 // This can happen if the download manager is shutting down and all maps
1092 // have been cleared.
1093 if (it == save_page_downloads_.end())
1094 return;
1095
1096 DownloadItem* download = it->second;
1097 if (!download) {
1098 NOTREACHED();
1099 return;
1100 }
1101
[email protected]d8472d92011-08-26 20:15:201102 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
[email protected]d8472d92011-08-26 20:15:201103 int64 largest_handle = largest_db_handle_in_history_;
1104 base::debug::Alias(&largest_handle);
[email protected]61b75a52011-08-29 16:34:341105 CHECK(!ContainsKey(history_downloads_, db_handle));
[email protected]d8472d92011-08-26 20:15:201106
[email protected]6d0146c2011-08-04 19:13:041107 AddDownloadItemToHistory(download, db_handle);
1108
1109 // Finalize this download if it finished before the history callback.
1110 if (!download->IsInProgress())
1111 SavePageDownloadFinished(download);
1112}
1113
[email protected]5656f8a2011-11-17 16:12:581114void DownloadManagerImpl::SavePageDownloadFinished(DownloadItem* download) {
[email protected]c09a8fd2011-11-21 19:54:501115 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) {
[email protected]2588ea9d2011-08-22 20:59:531116 delegate_->UpdateItemInPersistentStore(download);
[email protected]c09a8fd2011-11-21 19:54:501117 DCHECK(ContainsKey(save_page_downloads_, download->GetId()));
1118 save_page_downloads_.erase(download->GetId());
[email protected]6d0146c2011-08-04 19:13:041119
1120 if (download->IsComplete())
[email protected]ad50def52011-10-19 23:17:071121 content::NotificationService::current()->Notify(
[email protected]6d0146c2011-08-04 19:13:041122 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
[email protected]6c2381d2011-10-19 02:52:531123 content::Source<DownloadManager>(this),
1124 content::Details<DownloadItem>(download));
[email protected]6d0146c2011-08-04 19:13:041125 }
1126}
[email protected]da4a5582011-10-17 19:08:061127
[email protected]fc03de22011-12-06 23:28:121128void DownloadManagerImpl::DownloadOpened(DownloadItem* download) {
[email protected]da4a5582011-10-17 19:08:061129 delegate_->UpdateItemInPersistentStore(download);
1130 int num_unopened = 0;
1131 for (DownloadMap::iterator it = history_downloads_.begin();
1132 it != history_downloads_.end(); ++it) {
[email protected]c09a8fd2011-11-21 19:54:501133 if (it->second->IsComplete() && !it->second->GetOpened())
[email protected]da4a5582011-10-17 19:08:061134 ++num_unopened;
1135 }
1136 download_stats::RecordOpensOutstanding(num_unopened);
1137}
[email protected]5656f8a2011-11-17 16:12:581138
1139void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) {
1140 file_manager_ = file_manager;
1141}