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

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

Issue 2422923002: Reduce usage of FOR_EACH_OBSERVER macro in content/browser (Closed)
Patch Set: skip cases in 2418143004 and 2418373002 Created 4 years, 2 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 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 DownloadManagerDelegate* DownloadManagerImpl::GetDelegate() const { 267 DownloadManagerDelegate* DownloadManagerImpl::GetDelegate() const {
268 return delegate_; 268 return delegate_;
269 } 269 }
270 270
271 void DownloadManagerImpl::Shutdown() { 271 void DownloadManagerImpl::Shutdown() {
272 DVLOG(20) << __func__ << "() shutdown_needed_ = " << shutdown_needed_; 272 DVLOG(20) << __func__ << "() shutdown_needed_ = " << shutdown_needed_;
273 if (!shutdown_needed_) 273 if (!shutdown_needed_)
274 return; 274 return;
275 shutdown_needed_ = false; 275 shutdown_needed_ = false;
276 276
277 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this)); 277 for (auto& observer : observers_)
278 observer.ManagerGoingDown(this);
278 // TODO(benjhayden): Consider clearing observers_. 279 // TODO(benjhayden): Consider clearing observers_.
279 280
280 // If there are in-progress downloads, cancel them. This also goes for 281 // If there are in-progress downloads, cancel them. This also goes for
281 // dangerous downloads which will remain in history if they aren't explicitly 282 // dangerous downloads which will remain in history if they aren't explicitly
282 // accepted or discarded. Canceling will remove the intermediate download 283 // accepted or discarded. Canceling will remove the intermediate download
283 // file. 284 // file.
284 for (const auto& it : downloads_) { 285 for (const auto& it : downloads_) {
285 DownloadItemImpl* download = it.second; 286 DownloadItemImpl* download = it.second;
286 if (download->GetState() == DownloadItem::IN_PROGRESS) 287 if (download->GetState() == DownloadItem::IN_PROGRESS)
287 download->Cancel(false); 288 download->Cancel(false);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // attempt. 377 // attempt.
377 378
378 download->Start(std::move(download_file), std::move(info->request_handle), 379 download->Start(std::move(download_file), std::move(info->request_handle),
379 *info); 380 *info);
380 381
381 // For interrupted downloads, Start() will transition the state to 382 // For interrupted downloads, Start() will transition the state to
382 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). 383 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated().
383 // For new downloads, we notify here, rather than earlier, so that 384 // For new downloads, we notify here, rather than earlier, so that
384 // the download_file is bound to download and all the usual 385 // the download_file is bound to download and all the usual
385 // setters (e.g. Cancel) work. 386 // setters (e.g. Cancel) work.
386 if (new_download) 387 if (new_download) {
387 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); 388 for (auto& observer : observers_)
389 observer.OnDownloadCreated(this, download);
390 }
388 391
389 if (!on_started.is_null()) 392 if (!on_started.is_null())
390 on_started.Run(download, DOWNLOAD_INTERRUPT_REASON_NONE); 393 on_started.Run(download, DOWNLOAD_INTERRUPT_REASON_NONE);
391 } 394 }
392 395
393 void DownloadManagerImpl::CheckForHistoryFilesRemoval() { 396 void DownloadManagerImpl::CheckForHistoryFilesRemoval() {
394 DCHECK_CURRENTLY_ON(BrowserThread::UI); 397 DCHECK_CURRENTLY_ON(BrowserThread::UI);
395 for (const auto& it : downloads_) { 398 for (const auto& it : downloads_) {
396 DownloadItemImpl* item = it.second; 399 DownloadItemImpl* item = it.second;
397 CheckForFileRemoval(item); 400 CheckForFileRemoval(item);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 DCHECK_NE(content::DownloadItem::kInvalidId, id); 456 DCHECK_NE(content::DownloadItem::kInvalidId, id);
454 DCHECK(!base::ContainsKey(downloads_, id)); 457 DCHECK(!base::ContainsKey(downloads_, id));
455 net::NetLogWithSource net_log = 458 net::NetLogWithSource net_log =
456 net::NetLogWithSource::Make(net_log_, net::NetLogSourceType::DOWNLOAD); 459 net::NetLogWithSource::Make(net_log_, net::NetLogSourceType::DOWNLOAD);
457 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem( 460 DownloadItemImpl* download_item = item_factory_->CreateSavePageItem(
458 this, id, main_file_path, page_url, mime_type, std::move(request_handle), 461 this, id, main_file_path, page_url, mime_type, std::move(request_handle),
459 net_log); 462 net_log);
460 downloads_[download_item->GetId()] = download_item; 463 downloads_[download_item->GetId()] = download_item;
461 DCHECK(!base::ContainsKey(downloads_by_guid_, download_item->GetGuid())); 464 DCHECK(!base::ContainsKey(downloads_by_guid_, download_item->GetGuid()));
462 downloads_by_guid_[download_item->GetGuid()] = download_item; 465 downloads_by_guid_[download_item->GetGuid()] = download_item;
463 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( 466 for (auto& observer : observers_)
464 this, download_item)); 467 observer.OnDownloadCreated(this, download_item);
465 if (!item_created.is_null()) 468 if (!item_created.is_null())
466 item_created.Run(download_item); 469 item_created.Run(download_item);
467 } 470 }
468 471
469 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished( 472 void DownloadManagerImpl::OnSavePackageSuccessfullyFinished(
470 DownloadItem* download_item) { 473 DownloadItem* download_item) {
471 FOR_EACH_OBSERVER(Observer, observers_, 474 for (auto& observer : observers_)
472 OnSavePackageSuccessfullyFinished(this, download_item)); 475 observer.OnSavePackageSuccessfullyFinished(this, download_item);
473 } 476 }
474 477
475 // Resume a download of a specific URL. We send the request to the 478 // Resume a download of a specific URL. We send the request to the
476 // ResourceDispatcherHost, and let it send us responses like a regular 479 // ResourceDispatcherHost, and let it send us responses like a regular
477 // download. 480 // download.
478 void DownloadManagerImpl::ResumeInterruptedDownload( 481 void DownloadManagerImpl::ResumeInterruptedDownload(
479 std::unique_ptr<content::DownloadUrlParameters> params, 482 std::unique_ptr<content::DownloadUrlParameters> params,
480 uint32_t id) { 483 uint32_t id) {
481 BrowserThread::PostTaskAndReplyWithResult( 484 BrowserThread::PostTaskAndReplyWithResult(
482 BrowserThread::IO, FROM_HERE, 485 BrowserThread::IO, FROM_HERE,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 701 }
699 DCHECK(!base::ContainsKey(downloads_by_guid_, guid)); 702 DCHECK(!base::ContainsKey(downloads_by_guid_, guid));
700 DownloadItemImpl* item = item_factory_->CreatePersistedItem( 703 DownloadItemImpl* item = item_factory_->CreatePersistedItem(
701 this, guid, id, current_path, target_path, url_chain, referrer_url, 704 this, guid, id, current_path, target_path, url_chain, referrer_url,
702 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type, 705 site_url, tab_url, tab_refererr_url, mime_type, original_mime_type,
703 start_time, end_time, etag, last_modified, received_bytes, total_bytes, 706 start_time, end_time, etag, last_modified, received_bytes, total_bytes,
704 hash, state, danger_type, interrupt_reason, opened, 707 hash, state, danger_type, interrupt_reason, opened,
705 net::NetLogWithSource::Make(net_log_, net::NetLogSourceType::DOWNLOAD)); 708 net::NetLogWithSource::Make(net_log_, net::NetLogSourceType::DOWNLOAD));
706 downloads_[id] = item; 709 downloads_[id] = item;
707 downloads_by_guid_[guid] = item; 710 downloads_by_guid_[guid] = item;
708 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); 711 for (auto& observer : observers_)
712 observer.OnDownloadCreated(this, item);
709 DVLOG(20) << __func__ << "() download = " << item->DebugString(true); 713 DVLOG(20) << __func__ << "() download = " << item->DebugString(true);
710 return item; 714 return item;
711 } 715 }
712 716
713 int DownloadManagerImpl::InProgressCount() const { 717 int DownloadManagerImpl::InProgressCount() const {
714 int count = 0; 718 int count = 0;
715 for (const auto& it : downloads_) { 719 for (const auto& it : downloads_) {
716 if (it.second->GetState() == DownloadItem::IN_PROGRESS) 720 if (it.second->GetState() == DownloadItem::IN_PROGRESS)
717 ++count; 721 ++count;
718 } 722 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 if (delegate_) 768 if (delegate_)
765 delegate_->OpenDownload(download); 769 delegate_->OpenDownload(download);
766 } 770 }
767 771
768 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 772 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
769 if (delegate_) 773 if (delegate_)
770 delegate_->ShowDownloadInShell(download); 774 delegate_->ShowDownloadInShell(download);
771 } 775 }
772 776
773 } // namespace content 777 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/frame_host/frame_tree_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698