| 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/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 10 #include "content/browser/download/download_stats.h" | 11 #include "content/browser/download/download_stats.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
| 15 #include "content/public/browser/download_save_info.h" | 16 #include "content/public/browser/download_save_info.h" |
| 16 #include "content/public/browser/download_url_parameters.h" | 17 #include "content/public/browser/download_url_parameters.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 88 if (download_item_) | 89 if (download_item_) |
| 89 download_item_->RemoveObserver(this); | 90 download_item_->RemoveObserver(this); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void OnDownloadStarted(DownloadItem* item, | 93 void OnDownloadStarted(DownloadItem* item, |
| 93 DownloadInterruptReason interrupt_reason) { | 94 DownloadInterruptReason interrupt_reason) { |
| 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 95 if (!item) { | 96 if (!item) { |
| 96 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 97 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 97 on_completed_loop_->PostTask(FROM_HERE, base::Bind(on_completed_, false)); | 98 on_completed_loop_->task_runner()->PostTask( |
| 99 FROM_HERE, base::Bind(on_completed_, false)); |
| 98 return; | 100 return; |
| 99 } | 101 } |
| 100 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 102 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 101 download_item_ = item; | 103 download_item_ = item; |
| 102 download_item_->AddObserver(this); | 104 download_item_->AddObserver(this); |
| 103 } | 105 } |
| 104 | 106 |
| 105 // DownloadItem::Observer: | 107 // DownloadItem::Observer: |
| 106 void OnDownloadUpdated(DownloadItem* item) override { | 108 void OnDownloadUpdated(DownloadItem* item) override { |
| 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 109 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 108 DCHECK_EQ(download_item_, item); | 110 DCHECK_EQ(download_item_, item); |
| 109 DownloadItem::DownloadState state = download_item_->GetState(); | 111 DownloadItem::DownloadState state = download_item_->GetState(); |
| 110 if (state == DownloadItem::COMPLETE || | 112 if (state == DownloadItem::COMPLETE || |
| 111 state == DownloadItem::CANCELLED || | 113 state == DownloadItem::CANCELLED || |
| 112 state == DownloadItem::INTERRUPTED) { | 114 state == DownloadItem::INTERRUPTED) { |
| 113 if (!on_completed_.is_null()) { | 115 if (!on_completed_.is_null()) { |
| 114 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 116 on_completed_loop_->task_runner()->PostTask( |
| 115 on_completed_, state == DownloadItem::COMPLETE)); | 117 FROM_HERE, |
| 118 base::Bind(on_completed_, state == DownloadItem::COMPLETE)); |
| 116 on_completed_.Reset(); | 119 on_completed_.Reset(); |
| 117 } | 120 } |
| 118 download_item_->RemoveObserver(this); | 121 download_item_->RemoveObserver(this); |
| 119 download_item_ = NULL; | 122 download_item_ = NULL; |
| 120 } | 123 } |
| 121 // Ignore other states. | 124 // Ignore other states. |
| 122 } | 125 } |
| 123 | 126 |
| 124 void OnDownloadDestroyed(DownloadItem* item) override { | 127 void OnDownloadDestroyed(DownloadItem* item) override { |
| 125 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 126 DCHECK_EQ(download_item_, item); | 129 DCHECK_EQ(download_item_, item); |
| 127 if (!on_completed_.is_null()) { | 130 if (!on_completed_.is_null()) { |
| 128 const bool is_complete = | 131 const bool is_complete = |
| 129 download_item_->GetState() == DownloadItem::COMPLETE; | 132 download_item_->GetState() == DownloadItem::COMPLETE; |
| 130 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 133 on_completed_loop_->task_runner()->PostTask( |
| 131 on_completed_, is_complete)); | 134 FROM_HERE, base::Bind(on_completed_, is_complete)); |
| 132 on_completed_.Reset(); | 135 on_completed_.Reset(); |
| 133 } | 136 } |
| 134 download_item_->RemoveObserver(this); | 137 download_item_->RemoveObserver(this); |
| 135 download_item_ = NULL; | 138 download_item_ = NULL; |
| 136 } | 139 } |
| 137 | 140 |
| 138 base::MessageLoop* on_completed_loop_; | 141 base::MessageLoop* on_completed_loop_; |
| 139 OnCompleted on_completed_; | 142 OnCompleted on_completed_; |
| 140 GURL url_; | 143 GURL url_; |
| 141 Referrer referrer_; | 144 Referrer referrer_; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 237 |
| 235 void DragDownloadFile::CheckThread() { | 238 void DragDownloadFile::CheckThread() { |
| 236 #if defined(OS_WIN) | 239 #if defined(OS_WIN) |
| 237 DCHECK(drag_message_loop_ == base::MessageLoop::current()); | 240 DCHECK(drag_message_loop_ == base::MessageLoop::current()); |
| 238 #else | 241 #else |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 242 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 240 #endif | 243 #endif |
| 241 } | 244 } |
| 242 | 245 |
| 243 } // namespace content | 246 } // namespace content |
| OLD | NEW |