Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 14955002: [Resumption 6/11] Add a RESUMING_INTERNAL state to DownloadItem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix REMOVED race. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 browser_context_(browser_context), 240 browser_context_(browser_context),
241 delegate_(NULL), 241 delegate_(NULL),
242 net_log_(net_log) { 242 net_log_(net_log) {
243 DCHECK(browser_context); 243 DCHECK(browser_context);
244 } 244 }
245 245
246 DownloadManagerImpl::~DownloadManagerImpl() { 246 DownloadManagerImpl::~DownloadManagerImpl() {
247 DCHECK(!shutdown_needed_); 247 DCHECK(!shutdown_needed_);
248 } 248 }
249 249
250 void DownloadManagerImpl::CreateActiveItem(
251 DownloadId id, const DownloadCreateInfo& info) {
252 net::BoundNetLog bound_net_log =
253 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
254 downloads_[id.local()] =
255 item_factory_->CreateActiveItem(this, id, info, bound_net_log);
256 }
257
258 DownloadId DownloadManagerImpl::GetNextId() { 250 DownloadId DownloadManagerImpl::GetNextId() {
259 DownloadId id; 251 DownloadId id;
260 if (delegate_) 252 if (delegate_)
261 id = delegate_->GetNextId(); 253 id = delegate_->GetNextId();
262 if (!id.IsValid()) { 254 if (!id.IsValid()) {
263 static int next_id; 255 static int next_id;
264 id = DownloadId(browser_context_, ++next_id); 256 id = DownloadId(browser_context_, ++next_id);
265 } 257 }
266 258
267 return id; 259 return id;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (delegate_) 362 if (delegate_)
371 delegate_->Shutdown(); 363 delegate_->Shutdown();
372 delegate_ = NULL; 364 delegate_ = NULL;
373 } 365 }
374 366
375 DownloadItem* DownloadManagerImpl::StartDownload( 367 DownloadItem* DownloadManagerImpl::StartDownload(
376 scoped_ptr<DownloadCreateInfo> info, 368 scoped_ptr<DownloadCreateInfo> info,
377 scoped_ptr<ByteStreamReader> stream) { 369 scoped_ptr<ByteStreamReader> stream) {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
379 371
372 DownloadId id(info->download_id);
373 bool new_download = !id.IsValid();
374 DownloadItemImpl* download = NULL;
375
376 if (new_download) {
377 id = GetNextId();
378 net::BoundNetLog bound_net_log =
379 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
380 download = item_factory_->CreateActiveItem(this, id, *info, bound_net_log);
381 downloads_[id.local()] = download;
382 } else {
383 // Trying to resume an interrupted download.
384 if (!ContainsKey(downloads_, id.local())) {
385 // If the download is no longer known to the DownloadManager, then it was
386 // removed after it was resumed. Ignore.
387 info->request_handle.CancelRequest();
388 return NULL;
389 }
390 download = downloads_[id.local()];
Randy Smith (Not in Mondays) 2013/05/13 15:59:26 I'm tempted to suggest you explicitly look up the
asanka 2013/05/13 19:19:01 Done.
391 DCHECK(download->IsInterrupted());
392 }
393
380 base::FilePath default_download_directory; 394 base::FilePath default_download_directory;
381 if (delegate_) { 395 if (delegate_) {
382 base::FilePath website_save_directory; // Unused 396 base::FilePath website_save_directory; // Unused
383 bool skip_dir_check = false; // Unused 397 bool skip_dir_check = false; // Unused
384 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, 398 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory,
385 &default_download_directory, &skip_dir_check); 399 &default_download_directory, &skip_dir_check);
386 } 400 }
387 401
388 // If we don't have a valid id, that's a signal to generate one.
389 DownloadId id(info->download_id);
390 if (!id.IsValid())
391 id = GetNextId();
392
393 // Create a new download item if this isn't a resumption.
394 bool new_download(!ContainsKey(downloads_, id.local()));
395 if (new_download)
396 CreateActiveItem(id, *info);
397
398 DownloadItemImpl* download(downloads_[id.local()]);
399 DCHECK(download);
400 DCHECK(new_download || download->IsInterrupted());
401
402 // Create the download file and start the download. 402 // Create the download file and start the download.
403 scoped_ptr<DownloadFile> download_file( 403 scoped_ptr<DownloadFile> download_file(
404 file_factory_->CreateFile( 404 file_factory_->CreateFile(
405 info->save_info.Pass(), default_download_directory, 405 info->save_info.Pass(), default_download_directory,
406 info->url(), info->referrer_url, 406 info->url(), info->referrer_url,
407 delegate_->GenerateFileHash(), 407 delegate_->GenerateFileHash(),
408 stream.Pass(), download->GetBoundNetLog(), 408 stream.Pass(), download->GetBoundNetLog(),
409 download->DestinationObserverAsWeakPtr())); 409 download->DestinationObserverAsWeakPtr()));
410 scoped_ptr<DownloadRequestHandleInterface> req_handle( 410 scoped_ptr<DownloadRequestHandleInterface> req_handle(
411 new DownloadRequestHandle(info->request_handle)); 411 new DownloadRequestHandle(info->request_handle));
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 if (delegate_) 655 if (delegate_)
656 delegate_->OpenDownload(download); 656 delegate_->OpenDownload(download);
657 } 657 }
658 658
659 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 659 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
660 if (delegate_) 660 if (delegate_)
661 delegate_->ShowDownloadInShell(download); 661 delegate_->ShowDownloadInShell(download);
662 } 662 }
663 663
664 } // namespace content 664 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698