| 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 OnDownloadDestructed is never called. |
| 211 // OnDownloadDestructed is only called if OnDownloadUpdated() does not detect |
| 212 // completion or cancellation (in which cases it removes this observer). |
| 213 void DragDownloadFile::OnDownloadDestructed(content::DownloadItem* download) { |
| 214 AssertCurrentlyOnUIThread(); |
| 215 RemoveObservers(); |
| 216 DownloadCompleted(false); |
| 217 } |
| 218 |
| 210 void DragDownloadFile::AssertCurrentlyOnDragThread() { | 219 void DragDownloadFile::AssertCurrentlyOnDragThread() { |
| 211 // Only do the check on Windows where two threads are involved. | 220 // Only do the check on Windows where two threads are involved. |
| 212 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
| 213 DCHECK(drag_message_loop_ == MessageLoop::current()); | 222 DCHECK(drag_message_loop_ == MessageLoop::current()); |
| 214 #endif | 223 #endif |
| 215 } | 224 } |
| 216 | 225 |
| 217 void DragDownloadFile::AssertCurrentlyOnUIThread() { | 226 void DragDownloadFile::AssertCurrentlyOnUIThread() { |
| 218 // Only do the check on Windows where two threads are involved. | 227 // Only do the check on Windows where two threads are involved. |
| 219 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 233 | 242 |
| 234 void DragDownloadFile::QuitNestedMessageLoop() { | 243 void DragDownloadFile::QuitNestedMessageLoop() { |
| 235 AssertCurrentlyOnDragThread(); | 244 AssertCurrentlyOnDragThread(); |
| 236 | 245 |
| 237 if (is_running_nested_message_loop_) { | 246 if (is_running_nested_message_loop_) { |
| 238 is_running_nested_message_loop_ = false; | 247 is_running_nested_message_loop_ = false; |
| 239 MessageLoop::current()->Quit(); | 248 MessageLoop::current()->Quit(); |
| 240 } | 249 } |
| 241 } | 250 } |
| 242 #endif | 251 #endif |
| OLD | NEW |