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

Side by Side Diff: content/browser/download/download_item_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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); 239 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
240 } 240 }
241 241
242 DownloadItemImpl::~DownloadItemImpl() { 242 DownloadItemImpl::~DownloadItemImpl() {
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); 243 DCHECK_CURRENTLY_ON(BrowserThread::UI);
244 244
245 // Should always have been nuked before now, at worst in 245 // Should always have been nuked before now, at worst in
246 // DownloadManager shutdown. 246 // DownloadManager shutdown.
247 DCHECK(!download_file_.get()); 247 DCHECK(!download_file_.get());
248 248
249 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this)); 249 for (auto& observer : observers_)
250 observer.OnDownloadDestroyed(this);
250 delegate_->AssertStateConsistent(this); 251 delegate_->AssertStateConsistent(this);
251 delegate_->Detach(); 252 delegate_->Detach();
252 } 253 }
253 254
254 void DownloadItemImpl::AddObserver(Observer* observer) { 255 void DownloadItemImpl::AddObserver(Observer* observer) {
255 DCHECK_CURRENTLY_ON(BrowserThread::UI); 256 DCHECK_CURRENTLY_ON(BrowserThread::UI);
256 257
257 observers_.AddObserver(observer); 258 observers_.AddObserver(observer);
258 } 259 }
259 260
260 void DownloadItemImpl::RemoveObserver(Observer* observer) { 261 void DownloadItemImpl::RemoveObserver(Observer* observer) {
261 DCHECK_CURRENTLY_ON(BrowserThread::UI); 262 DCHECK_CURRENTLY_ON(BrowserThread::UI);
262 263
263 observers_.RemoveObserver(observer); 264 observers_.RemoveObserver(observer);
264 } 265 }
265 266
266 void DownloadItemImpl::UpdateObservers() { 267 void DownloadItemImpl::UpdateObservers() {
267 DCHECK_CURRENTLY_ON(BrowserThread::UI); 268 DCHECK_CURRENTLY_ON(BrowserThread::UI);
268 DVLOG(20) << __func__ << "()"; 269 DVLOG(20) << __func__ << "()";
269 270
270 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 271 for (auto& observer : observers_)
272 observer.OnDownloadUpdated(this);
271 } 273 }
272 274
273 void DownloadItemImpl::ValidateDangerousDownload() { 275 void DownloadItemImpl::ValidateDangerousDownload() {
274 DCHECK_CURRENTLY_ON(BrowserThread::UI); 276 DCHECK_CURRENTLY_ON(BrowserThread::UI);
275 DCHECK(!IsDone()); 277 DCHECK(!IsDone());
276 DCHECK(IsDangerous()); 278 DCHECK(IsDangerous());
277 279
278 DVLOG(20) << __func__ << "() download=" << DebugString(true); 280 DVLOG(20) << __func__ << "() download=" << DebugString(true);
279 281
280 if (IsDone() || !IsDangerous()) 282 if (IsDone() || !IsDangerous())
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (state_ != COMPLETE_INTERNAL || file_externally_removed_) 423 if (state_ != COMPLETE_INTERNAL || file_externally_removed_)
422 return; 424 return;
423 425
424 // Ideally, we want to detect errors in opening and report them, but we 426 // Ideally, we want to detect errors in opening and report them, but we
425 // don't generally have the proper interface for that to the external 427 // don't generally have the proper interface for that to the external
426 // program that opens the file. So instead we spawn a check to update 428 // program that opens the file. So instead we spawn a check to update
427 // the UI if the file has been deleted in parallel with the open. 429 // the UI if the file has been deleted in parallel with the open.
428 delegate_->CheckForFileRemoval(this); 430 delegate_->CheckForFileRemoval(this);
429 RecordOpen(GetEndTime(), !GetOpened()); 431 RecordOpen(GetEndTime(), !GetOpened());
430 opened_ = true; 432 opened_ = true;
431 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); 433 for (auto& observer : observers_)
434 observer.OnDownloadOpened(this);
432 delegate_->OpenDownload(this); 435 delegate_->OpenDownload(this);
433 } 436 }
434 437
435 void DownloadItemImpl::ShowDownloadInShell() { 438 void DownloadItemImpl::ShowDownloadInShell() {
436 DCHECK_CURRENTLY_ON(BrowserThread::UI); 439 DCHECK_CURRENTLY_ON(BrowserThread::UI);
437 440
438 delegate_->ShowDownloadInShell(this); 441 delegate_->ShowDownloadInShell(this);
439 } 442 }
440 443
441 uint32_t DownloadItemImpl::GetId() const { 444 uint32_t DownloadItemImpl::GetId() const {
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 etag_ = new_create_info.etag; 970 etag_ = new_create_info.etag;
968 last_modified_time_ = new_create_info.last_modified; 971 last_modified_time_ = new_create_info.last_modified;
969 content_disposition_ = new_create_info.content_disposition; 972 content_disposition_ = new_create_info.content_disposition;
970 973
971 // Don't update observers. This method is expected to be called just before a 974 // Don't update observers. This method is expected to be called just before a
972 // DownloadFile is created and Start() is called. The observers will be 975 // DownloadFile is created and Start() is called. The observers will be
973 // notified when the download transitions to the IN_PROGRESS state. 976 // notified when the download transitions to the IN_PROGRESS state.
974 } 977 }
975 978
976 void DownloadItemImpl::NotifyRemoved() { 979 void DownloadItemImpl::NotifyRemoved() {
977 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); 980 for (auto& observer : observers_)
981 observer.OnDownloadRemoved(this);
978 } 982 }
979 983
980 void DownloadItemImpl::OnDownloadedFileRemoved() { 984 void DownloadItemImpl::OnDownloadedFileRemoved() {
981 file_externally_removed_ = true; 985 file_externally_removed_ = true;
982 DVLOG(20) << __func__ << "() download=" << DebugString(true); 986 DVLOG(20) << __func__ << "() download=" << DebugString(true);
983 UpdateObservers(); 987 UpdateObservers();
984 } 988 }
985 989
986 base::WeakPtr<DownloadDestinationObserver> 990 base::WeakPtr<DownloadDestinationObserver>
987 DownloadItemImpl::DestinationObserverAsWeakPtr() { 991 DownloadItemImpl::DestinationObserverAsWeakPtr() {
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 case RESUME_MODE_USER_CONTINUE: 2093 case RESUME_MODE_USER_CONTINUE:
2090 return "USER_CONTINUE"; 2094 return "USER_CONTINUE";
2091 case RESUME_MODE_USER_RESTART: 2095 case RESUME_MODE_USER_RESTART:
2092 return "USER_RESTART"; 2096 return "USER_RESTART";
2093 } 2097 }
2094 NOTREACHED() << "Unknown resume mode " << mode; 2098 NOTREACHED() << "Unknown resume mode " << mode;
2095 return "unknown"; 2099 return "unknown";
2096 } 2100 }
2097 2101
2098 } // namespace content 2102 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.cc ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698