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