Chromium Code Reviews| 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/browser/download/download_stats.h" | 9 #include "content/browser/download/download_stats.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 } | 98 } |
| 99 DCHECK_EQ(net::OK, error); | 99 DCHECK_EQ(net::OK, error); |
| 100 download_item_ = item; | 100 download_item_ = item; |
| 101 download_item_->AddObserver(this); | 101 download_item_->AddObserver(this); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // DownloadItem::Observer: | 104 // DownloadItem::Observer: |
| 105 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE { | 105 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE { |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 DCHECK_EQ(download_item_, item); | 107 DCHECK_EQ(download_item_, item); |
| 108 if (download_item_->IsComplete() || | 108 DownloadItem::DownloadState state = download_item_->GetState(); |
| 109 download_item_->IsCancelled() || | 109 if (state == DownloadItem::COMPLETE || |
| 110 download_item_->IsInterrupted()) { | 110 state == DownloadItem::CANCELLED || |
| 111 state == DownloadItem::INTERRUPTED) { | |
| 111 if (!on_completed_.is_null()) { | 112 if (!on_completed_.is_null()) { |
| 112 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 113 on_completed_loop_->PostTask(FROM_HERE, base::Bind( |
| 113 on_completed_, download_item_->IsComplete())); | 114 on_completed_, state == DownloadItem::COMPLETE)); |
| 114 on_completed_.Reset(); | 115 on_completed_.Reset(); |
| 115 } | 116 } |
| 116 download_item_->RemoveObserver(this); | 117 download_item_->RemoveObserver(this); |
| 117 download_item_ = NULL; | 118 download_item_ = NULL; |
| 118 } | 119 } |
| 119 // Ignore other states. | 120 // Ignore other states. |
| 120 } | 121 } |
| 121 | 122 |
| 122 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE { | 123 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 DCHECK_EQ(download_item_, item); | 125 DCHECK_EQ(download_item_, item); |
| 125 if (!on_completed_.is_null()) { | 126 if (!on_completed_.is_null()) { |
| 127 const bool isComplete = | |
|
benjhayden
2013/06/13 19:01:45
is_complete
| |
| 128 download_item_->GetState() == DownloadItem::COMPLETE; | |
| 126 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 129 on_completed_loop_->PostTask(FROM_HERE, base::Bind( |
| 127 on_completed_, download_item_->IsComplete())); | 130 on_completed_, isComplete)); |
| 128 on_completed_.Reset(); | 131 on_completed_.Reset(); |
| 129 } | 132 } |
| 130 download_item_->RemoveObserver(this); | 133 download_item_->RemoveObserver(this); |
| 131 download_item_ = NULL; | 134 download_item_ = NULL; |
| 132 } | 135 } |
| 133 | 136 |
| 134 base::MessageLoop* on_completed_loop_; | 137 base::MessageLoop* on_completed_loop_; |
| 135 OnCompleted on_completed_; | 138 OnCompleted on_completed_; |
| 136 GURL url_; | 139 GURL url_; |
| 137 Referrer referrer_; | 140 Referrer referrer_; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 233 |
| 231 void DragDownloadFile::CheckThread() { | 234 void DragDownloadFile::CheckThread() { |
| 232 #if defined(OS_WIN) | 235 #if defined(OS_WIN) |
| 233 DCHECK(drag_message_loop_ == base::MessageLoop::current()); | 236 DCHECK(drag_message_loop_ == base::MessageLoop::current()); |
| 234 #else | 237 #else |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 236 #endif | 239 #endif |
| 237 } | 240 } |
| 238 | 241 |
| 239 } // namespace content | 242 } // namespace content |
| OLD | NEW |