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

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

Issue 1008613002: favor DCHECK_CURRENTLY_ON for better logs in content/browser/[a-d]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/drag_download_file.h" 5 #include "content/browser/download/drag_download_file.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/download/download_stats.h" 10 #include "content/browser/download/download_stats.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 weak_ptr_factory_(this) { 48 weak_ptr_factory_(this) {
49 DCHECK(on_completed_loop_); 49 DCHECK(on_completed_loop_);
50 DCHECK(!on_completed_.is_null()); 50 DCHECK(!on_completed_.is_null());
51 DCHECK(web_contents_); 51 DCHECK(web_contents_);
52 // May be called on any thread. 52 // May be called on any thread.
53 // Do not call weak_ptr_factory_.GetWeakPtr() outside the UI thread. 53 // Do not call weak_ptr_factory_.GetWeakPtr() outside the UI thread.
54 } 54 }
55 55
56 void InitiateDownload(base::File file, 56 void InitiateDownload(base::File file,
57 const base::FilePath& file_path) { 57 const base::FilePath& file_path) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 58 DCHECK_CURRENTLY_ON(BrowserThread::UI);
59 DownloadManager* download_manager = 59 DownloadManager* download_manager =
60 BrowserContext::GetDownloadManager(web_contents_->GetBrowserContext()); 60 BrowserContext::GetDownloadManager(web_contents_->GetBrowserContext());
61 61
62 RecordDownloadSource(INITIATED_BY_DRAG_N_DROP); 62 RecordDownloadSource(INITIATED_BY_DRAG_N_DROP);
63 scoped_ptr<content::DownloadUrlParameters> params( 63 scoped_ptr<content::DownloadUrlParameters> params(
64 DownloadUrlParameters::FromWebContents(web_contents_, url_)); 64 DownloadUrlParameters::FromWebContents(web_contents_, url_));
65 params->set_referrer(referrer_); 65 params->set_referrer(referrer_);
66 params->set_referrer_encoding(referrer_encoding_); 66 params->set_referrer_encoding(referrer_encoding_);
67 params->set_callback(base::Bind(&DragDownloadFileUI::OnDownloadStarted, 67 params->set_callback(base::Bind(&DragDownloadFileUI::OnDownloadStarted,
68 weak_ptr_factory_.GetWeakPtr())); 68 weak_ptr_factory_.GetWeakPtr()));
69 params->set_file_path(file_path); 69 params->set_file_path(file_path);
70 params->set_file(file.Pass()); // Nulls file. 70 params->set_file(file.Pass()); // Nulls file.
71 download_manager->DownloadUrl(params.Pass()); 71 download_manager->DownloadUrl(params.Pass());
72 } 72 }
73 73
74 void Cancel() { 74 void Cancel() {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
76 if (download_item_) 76 if (download_item_)
77 download_item_->Cancel(true); 77 download_item_->Cancel(true);
78 } 78 }
79 79
80 void Delete() { 80 void Delete() {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 81 DCHECK_CURRENTLY_ON(BrowserThread::UI);
82 delete this; 82 delete this;
83 } 83 }
84 84
85 private: 85 private:
86 ~DragDownloadFileUI() override { 86 ~DragDownloadFileUI() override {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 87 DCHECK_CURRENTLY_ON(BrowserThread::UI);
88 if (download_item_) 88 if (download_item_)
89 download_item_->RemoveObserver(this); 89 download_item_->RemoveObserver(this);
90 } 90 }
91 91
92 void OnDownloadStarted(DownloadItem* item, 92 void OnDownloadStarted(DownloadItem* item,
93 DownloadInterruptReason interrupt_reason) { 93 DownloadInterruptReason interrupt_reason) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 DCHECK_CURRENTLY_ON(BrowserThread::UI);
95 if (!item) { 95 if (!item) {
96 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); 96 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
97 on_completed_loop_->PostTask(FROM_HERE, base::Bind(on_completed_, false)); 97 on_completed_loop_->PostTask(FROM_HERE, base::Bind(on_completed_, false));
98 return; 98 return;
99 } 99 }
100 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); 100 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
101 download_item_ = item; 101 download_item_ = item;
102 download_item_->AddObserver(this); 102 download_item_->AddObserver(this);
103 } 103 }
104 104
105 // DownloadItem::Observer: 105 // DownloadItem::Observer:
106 void OnDownloadUpdated(DownloadItem* item) override { 106 void OnDownloadUpdated(DownloadItem* item) override {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK_CURRENTLY_ON(BrowserThread::UI);
108 DCHECK_EQ(download_item_, item); 108 DCHECK_EQ(download_item_, item);
109 DownloadItem::DownloadState state = download_item_->GetState(); 109 DownloadItem::DownloadState state = download_item_->GetState();
110 if (state == DownloadItem::COMPLETE || 110 if (state == DownloadItem::COMPLETE ||
111 state == DownloadItem::CANCELLED || 111 state == DownloadItem::CANCELLED ||
112 state == DownloadItem::INTERRUPTED) { 112 state == DownloadItem::INTERRUPTED) {
113 if (!on_completed_.is_null()) { 113 if (!on_completed_.is_null()) {
114 on_completed_loop_->PostTask(FROM_HERE, base::Bind( 114 on_completed_loop_->PostTask(FROM_HERE, base::Bind(
115 on_completed_, state == DownloadItem::COMPLETE)); 115 on_completed_, state == DownloadItem::COMPLETE));
116 on_completed_.Reset(); 116 on_completed_.Reset();
117 } 117 }
118 download_item_->RemoveObserver(this); 118 download_item_->RemoveObserver(this);
119 download_item_ = NULL; 119 download_item_ = NULL;
120 } 120 }
121 // Ignore other states. 121 // Ignore other states.
122 } 122 }
123 123
124 void OnDownloadDestroyed(DownloadItem* item) override { 124 void OnDownloadDestroyed(DownloadItem* item) override {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 125 DCHECK_CURRENTLY_ON(BrowserThread::UI);
126 DCHECK_EQ(download_item_, item); 126 DCHECK_EQ(download_item_, item);
127 if (!on_completed_.is_null()) { 127 if (!on_completed_.is_null()) {
128 const bool is_complete = 128 const bool is_complete =
129 download_item_->GetState() == DownloadItem::COMPLETE; 129 download_item_->GetState() == DownloadItem::COMPLETE;
130 on_completed_loop_->PostTask(FROM_HERE, base::Bind( 130 on_completed_loop_->PostTask(FROM_HERE, base::Bind(
131 on_completed_, is_complete)); 131 on_completed_, is_complete));
132 on_completed_.Reset(); 132 on_completed_.Reset();
133 } 133 }
134 download_item_->RemoveObserver(this); 134 download_item_->RemoveObserver(this);
135 download_item_ = NULL; 135 download_item_ = NULL;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 observer_ = NULL; 229 observer_ = NULL;
230 230
231 if (nested_loop_.running()) 231 if (nested_loop_.running())
232 nested_loop_.Quit(); 232 nested_loop_.Quit();
233 } 233 }
234 234
235 void DragDownloadFile::CheckThread() { 235 void DragDownloadFile::CheckThread() {
236 #if defined(OS_WIN) 236 #if defined(OS_WIN)
237 DCHECK(drag_message_loop_ == base::MessageLoop::current()); 237 DCHECK(drag_message_loop_ == base::MessageLoop::current());
238 #else 238 #else
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 239 DCHECK_CURRENTLY_ON(BrowserThread::UI);
240 #endif 240 #endif
241 } 241 }
242 242
243 } // namespace content 243 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_resource_handler.cc ('k') | content/browser/download/mhtml_generation_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698