OLD | NEW |
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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "content/browser/download/download_stats.h" | 10 #include "content/browser/download/download_stats.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 if ((*i)->GetOriginalUrl() == url_) { | 189 if ((*i)->GetOriginalUrl() == url_) { |
190 download_item_ = *i; | 190 download_item_ = *i; |
191 download_item_->AddObserver(this); | 191 download_item_->AddObserver(this); |
192 break; | 192 break; |
193 } | 193 } |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 void DragDownloadFile::OnDownloadUpdated(content::DownloadItem* download) { | 197 void DragDownloadFile::OnDownloadUpdated(content::DownloadItem* download) { |
198 AssertCurrentlyOnUIThread(); | 198 AssertCurrentlyOnUIThread(); |
199 if (download->IsCancelled() || | 199 if (download->IsCancelled()) { |
200 (download->GetState() == DownloadItem::REMOVING)) { | |
201 RemoveObservers(); | 200 RemoveObservers(); |
202 DownloadCompleted(false); | 201 DownloadCompleted(false); |
203 } else if (download->IsComplete()) { | 202 } else if (download->IsComplete()) { |
204 RemoveObservers(); | 203 RemoveObservers(); |
205 DownloadCompleted(true); | 204 DownloadCompleted(true); |
206 } | 205 } |
207 // Ignore other states. | 206 // Ignore other states. |
208 } | 207 } |
209 | 208 |
| 209 // If the download completes or is cancelled, then OnDownloadUpdated() will |
| 210 // handle it and RemoveObserver() so that OnDownloadDestroyed is never called. |
| 211 // OnDownloadDestroyed is only called if OnDownloadUpdated() does not detect |
| 212 // completion or cancellation (in which cases it removes this observer). |
| 213 // TODO(benjhayden): Try to change this to NOTREACHED()? |
| 214 void DragDownloadFile::OnDownloadDestroyed(content::DownloadItem* download) { |
| 215 AssertCurrentlyOnUIThread(); |
| 216 RemoveObservers(); |
| 217 DownloadCompleted(false); |
| 218 } |
| 219 |
210 void DragDownloadFile::AssertCurrentlyOnDragThread() { | 220 void DragDownloadFile::AssertCurrentlyOnDragThread() { |
211 // Only do the check on Windows where two threads are involved. | 221 // Only do the check on Windows where two threads are involved. |
212 #if defined(OS_WIN) | 222 #if defined(OS_WIN) |
213 DCHECK(drag_message_loop_ == MessageLoop::current()); | 223 DCHECK(drag_message_loop_ == MessageLoop::current()); |
214 #endif | 224 #endif |
215 } | 225 } |
216 | 226 |
217 void DragDownloadFile::AssertCurrentlyOnUIThread() { | 227 void DragDownloadFile::AssertCurrentlyOnUIThread() { |
218 // Only do the check on Windows where two threads are involved. | 228 // Only do the check on Windows where two threads are involved. |
219 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
(...skipping 13 matching lines...) Expand all Loading... |
233 | 243 |
234 void DragDownloadFile::QuitNestedMessageLoop() { | 244 void DragDownloadFile::QuitNestedMessageLoop() { |
235 AssertCurrentlyOnDragThread(); | 245 AssertCurrentlyOnDragThread(); |
236 | 246 |
237 if (is_running_nested_message_loop_) { | 247 if (is_running_nested_message_loop_) { |
238 is_running_nested_message_loop_ = false; | 248 is_running_nested_message_loop_ = false; |
239 MessageLoop::current()->Quit(); | 249 MessageLoop::current()->Quit(); |
240 } | 250 } |
241 } | 251 } |
242 #endif | 252 #endif |
OLD | NEW |