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

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

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
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 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
12 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. 60 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4.
60 scoped_ptr<net::URLRequest> request( 61 scoped_ptr<net::URLRequest> request(
61 params->resource_context()->GetRequestContext()->CreateRequest( 62 params->resource_context()->GetRequestContext()->CreateRequest(
62 params->url(), net::DEFAULT_PRIORITY, NULL)); 63 params->url(), net::DEFAULT_PRIORITY, NULL));
63 request->set_method(params->method()); 64 request->set_method(params->method());
64 if (!params->post_body().empty()) { 65 if (!params->post_body().empty()) {
65 const std::string& body = params->post_body(); 66 const std::string& body = params->post_body();
66 scoped_ptr<net::UploadElementReader> reader( 67 scoped_ptr<net::UploadElementReader> reader(
67 net::UploadOwnedBytesElementReader::CreateWithString(body)); 68 net::UploadOwnedBytesElementReader::CreateWithString(body));
68 request->set_upload( 69 request->set_upload(
69 net::ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); 70 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0));
70 } 71 }
71 if (params->post_id() >= 0) { 72 if (params->post_id() >= 0) {
72 // The POST in this case does not have an actual body, and only works 73 // The POST in this case does not have an actual body, and only works
73 // when retrieving data from cache. This is done because we don't want 74 // when retrieving data from cache. This is done because we don't want
74 // to do a re-POST without user consent, and currently don't have a good 75 // to do a re-POST without user consent, and currently don't have a good
75 // plan on how to display the UI for that. 76 // plan on how to display the UI for that.
76 DCHECK(params->prefer_cache()); 77 DCHECK(params->prefer_cache());
77 DCHECK_EQ("POST", params->method()); 78 DCHECK_EQ("POST", params->method());
78 std::vector<scoped_ptr<net::UploadElementReader>> element_readers; 79 std::vector<scoped_ptr<net::UploadElementReader>> element_readers;
79 request->set_upload(make_scoped_ptr(new net::ElementsUploadDataStream( 80 request->set_upload(make_scoped_ptr(new net::ElementsUploadDataStream(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 199
199 DownloadItemImpl* CreateSavePageItem( 200 DownloadItemImpl* CreateSavePageItem(
200 DownloadItemImplDelegate* delegate, 201 DownloadItemImplDelegate* delegate,
201 uint32_t download_id, 202 uint32_t download_id,
202 const base::FilePath& path, 203 const base::FilePath& path,
203 const GURL& url, 204 const GURL& url,
204 const std::string& mime_type, 205 const std::string& mime_type,
205 scoped_ptr<DownloadRequestHandleInterface> request_handle, 206 scoped_ptr<DownloadRequestHandleInterface> request_handle,
206 const net::BoundNetLog& bound_net_log) override { 207 const net::BoundNetLog& bound_net_log) override {
207 return new DownloadItemImpl(delegate, download_id, path, url, 208 return new DownloadItemImpl(delegate, download_id, path, url, mime_type,
208 mime_type, request_handle.Pass(), 209 std::move(request_handle), bound_net_log);
209 bound_net_log);
210 } 210 }
211 }; 211 };
212 212
213 } // namespace 213 } // namespace
214 214
215 DownloadManagerImpl::DownloadManagerImpl( 215 DownloadManagerImpl::DownloadManagerImpl(
216 net::NetLog* net_log, 216 net::NetLog* net_log,
217 BrowserContext* browser_context) 217 BrowserContext* browser_context)
218 : item_factory_(new DownloadItemFactoryImpl()), 218 : item_factory_(new DownloadItemFactoryImpl()),
219 file_factory_(new DownloadFileFactory()), 219 file_factory_(new DownloadFileFactory()),
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 456
457 void DownloadManagerImpl::CreateSavePackageDownloadItem( 457 void DownloadManagerImpl::CreateSavePackageDownloadItem(
458 const base::FilePath& main_file_path, 458 const base::FilePath& main_file_path,
459 const GURL& page_url, 459 const GURL& page_url,
460 const std::string& mime_type, 460 const std::string& mime_type,
461 scoped_ptr<DownloadRequestHandleInterface> request_handle, 461 scoped_ptr<DownloadRequestHandleInterface> request_handle,
462 const DownloadItemImplCreated& item_created) { 462 const DownloadItemImplCreated& item_created) {
463 DCHECK_CURRENTLY_ON(BrowserThread::UI); 463 DCHECK_CURRENTLY_ON(BrowserThread::UI);
464 GetNextId(base::Bind( 464 GetNextId(base::Bind(
465 &DownloadManagerImpl::CreateSavePackageDownloadItemWithId, 465 &DownloadManagerImpl::CreateSavePackageDownloadItemWithId,
466 weak_factory_.GetWeakPtr(), 466 weak_factory_.GetWeakPtr(), main_file_path, page_url, mime_type,
467 main_file_path, 467 base::Passed(std::move(request_handle)), item_created));
468 page_url,
469 mime_type,
470 base::Passed(request_handle.Pass()),
471 item_created));
472 } 468 }
473 469
474 void DownloadManagerImpl::CreateSavePackageDownloadItemWithId( 470 void DownloadManagerImpl::CreateSavePackageDownloadItemWithId(
475 const base::FilePath& main_file_path, 471 const base::FilePath& main_file_path,
476 const GURL& page_url, 472 const GURL& page_url,
477 const std::string& mime_type, 473 const std::string& mime_type,
478 scoped_ptr<DownloadRequestHandleInterface> request_handle, 474 scoped_ptr<DownloadRequestHandleInterface> request_handle,
479 const DownloadItemImplCreated& item_created, 475 const DownloadItemImplCreated& item_created,
480 uint32_t id) { 476 uint32_t id) {
481 DCHECK_CURRENTLY_ON(BrowserThread::UI); 477 DCHECK_CURRENTLY_ON(BrowserThread::UI);
482 DCHECK_NE(content::DownloadItem::kInvalidId, id); 478 DCHECK_NE(content::DownloadItem::kInvalidId, id);
483 DCHECK(!ContainsKey(downloads_, id)); 479 DCHECK(!ContainsKey(downloads_, id));
484 net::BoundNetLog bound_net_log = 480 net::BoundNetLog bound_net_log =
485 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); 481 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
486 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( 482 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem(
487 this, 483 this, id, main_file_path, page_url, mime_type, std::move(request_handle),
488 id,
489 main_file_path,
490 page_url,
491 mime_type,
492 request_handle.Pass(),
493 bound_net_log); 484 bound_net_log);
494 downloads_[download_item->GetId()] = download_item; 485 downloads_[download_item->GetId()] = download_item;
495 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( 486 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(
496 this, download_item)); 487 this, download_item));
497 if (!item_created.is_null()) 488 if (!item_created.is_null())
498 item_created.Run(download_item); 489 item_created.Run(download_item);
499 } 490 }
500 491
501 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished( 492 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished(
502 DownloadItem* download_item) { 493 DownloadItem* download_item) {
(...skipping 11 matching lines...) Expand all
514 BrowserThread::PostTaskAndReplyWithResult( 505 BrowserThread::PostTaskAndReplyWithResult(
515 BrowserThread::IO, FROM_HERE, 506 BrowserThread::IO, FROM_HERE,
516 base::Bind(&BeginDownload, base::Passed(&params), id, 507 base::Bind(&BeginDownload, base::Passed(&params), id,
517 weak_factory_.GetWeakPtr()), 508 weak_factory_.GetWeakPtr()),
518 base::Bind(&DownloadManagerImpl::AddUrlDownloader, 509 base::Bind(&DownloadManagerImpl::AddUrlDownloader,
519 weak_factory_.GetWeakPtr())); 510 weak_factory_.GetWeakPtr()));
520 } 511 }
521 512
522 void DownloadManagerImpl::SetDownloadItemFactoryForTesting( 513 void DownloadManagerImpl::SetDownloadItemFactoryForTesting(
523 scoped_ptr<DownloadItemFactory> item_factory) { 514 scoped_ptr<DownloadItemFactory> item_factory) {
524 item_factory_ = item_factory.Pass(); 515 item_factory_ = std::move(item_factory);
525 } 516 }
526 517
527 void DownloadManagerImpl::SetDownloadFileFactoryForTesting( 518 void DownloadManagerImpl::SetDownloadFileFactoryForTesting(
528 scoped_ptr<DownloadFileFactory> file_factory) { 519 scoped_ptr<DownloadFileFactory> file_factory) {
529 file_factory_ = file_factory.Pass(); 520 file_factory_ = std::move(file_factory);
530 } 521 }
531 522
532 DownloadFileFactory* DownloadManagerImpl::GetDownloadFileFactoryForTesting() { 523 DownloadFileFactory* DownloadManagerImpl::GetDownloadFileFactoryForTesting() {
533 return file_factory_.get(); 524 return file_factory_.get();
534 } 525 }
535 526
536 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { 527 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
537 if (!download) 528 if (!download)
538 return; 529 return;
539 530
540 uint32_t download_id = download->GetId(); 531 uint32_t download_id = download->GetId();
541 if (downloads_.erase(download_id) == 0) 532 if (downloads_.erase(download_id) == 0)
542 return; 533 return;
543 delete download; 534 delete download;
544 } 535 }
545 536
546 void DownloadManagerImpl::AddUrlDownloader( 537 void DownloadManagerImpl::AddUrlDownloader(
547 scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> downloader) { 538 scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> downloader) {
548 if (downloader) 539 if (downloader)
549 url_downloaders_.push_back(downloader.Pass()); 540 url_downloaders_.push_back(std::move(downloader));
550 } 541 }
551 542
552 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) { 543 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) {
553 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end(); 544 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end();
554 ++ptr) { 545 ++ptr) {
555 if (ptr->get() == downloader) { 546 if (ptr->get() == downloader) {
556 url_downloaders_.erase(ptr); 547 url_downloaders_.erase(ptr);
557 return; 548 return;
558 } 549 }
559 } 550 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (delegate_) 735 if (delegate_)
745 delegate_->OpenDownload(download); 736 delegate_->OpenDownload(download);
746 } 737 }
747 738
748 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 739 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
749 if (delegate_) 740 if (delegate_)
750 delegate_->ShowDownloadInShell(download); 741 delegate_->ShowDownloadInShell(download);
751 } 742 }
752 743
753 } // namespace content 744 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698