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/message_loop/message_loop.h" |
10 #include "content/browser/download/download_stats.h" | 10 #include "content/browser/download/download_stats.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (download_item_) | 76 if (download_item_) |
77 download_item_->Cancel(true); | 77 download_item_->Cancel(true); |
78 } | 78 } |
79 | 79 |
80 void Delete() { | 80 void Delete() { |
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
82 delete this; | 82 delete this; |
83 } | 83 } |
84 | 84 |
85 private: | 85 private: |
86 virtual ~DragDownloadFileUI() { | 86 ~DragDownloadFileUI() override { |
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
88 if (download_item_) | 88 if (download_item_) |
89 download_item_->RemoveObserver(this); | 89 download_item_->RemoveObserver(this); |
90 } | 90 } |
91 | 91 |
92 void OnDownloadStarted(DownloadItem* item, | 92 void OnDownloadStarted(DownloadItem* item, |
93 DownloadInterruptReason interrupt_reason) { | 93 DownloadInterruptReason interrupt_reason) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
95 if (!item) { | 95 if (!item) { |
96 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 96 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
97 on_completed_loop_->PostTask(FROM_HERE, base::Bind(on_completed_, false)); | 97 on_completed_loop_->PostTask(FROM_HERE, base::Bind(on_completed_, false)); |
98 return; | 98 return; |
99 } | 99 } |
100 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 100 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
101 download_item_ = item; | 101 download_item_ = item; |
102 download_item_->AddObserver(this); | 102 download_item_->AddObserver(this); |
103 } | 103 } |
104 | 104 |
105 // DownloadItem::Observer: | 105 // DownloadItem::Observer: |
106 virtual void OnDownloadUpdated(DownloadItem* item) override { | 106 void OnDownloadUpdated(DownloadItem* item) override { |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
108 DCHECK_EQ(download_item_, item); | 108 DCHECK_EQ(download_item_, item); |
109 DownloadItem::DownloadState state = download_item_->GetState(); | 109 DownloadItem::DownloadState state = download_item_->GetState(); |
110 if (state == DownloadItem::COMPLETE || | 110 if (state == DownloadItem::COMPLETE || |
111 state == DownloadItem::CANCELLED || | 111 state == DownloadItem::CANCELLED || |
112 state == DownloadItem::INTERRUPTED) { | 112 state == DownloadItem::INTERRUPTED) { |
113 if (!on_completed_.is_null()) { | 113 if (!on_completed_.is_null()) { |
114 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 114 on_completed_loop_->PostTask(FROM_HERE, base::Bind( |
115 on_completed_, state == DownloadItem::COMPLETE)); | 115 on_completed_, state == DownloadItem::COMPLETE)); |
116 on_completed_.Reset(); | 116 on_completed_.Reset(); |
117 } | 117 } |
118 download_item_->RemoveObserver(this); | 118 download_item_->RemoveObserver(this); |
119 download_item_ = NULL; | 119 download_item_ = NULL; |
120 } | 120 } |
121 // Ignore other states. | 121 // Ignore other states. |
122 } | 122 } |
123 | 123 |
124 virtual void OnDownloadDestroyed(DownloadItem* item) override { | 124 void OnDownloadDestroyed(DownloadItem* item) override { |
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
126 DCHECK_EQ(download_item_, item); | 126 DCHECK_EQ(download_item_, item); |
127 if (!on_completed_.is_null()) { | 127 if (!on_completed_.is_null()) { |
128 const bool is_complete = | 128 const bool is_complete = |
129 download_item_->GetState() == DownloadItem::COMPLETE; | 129 download_item_->GetState() == DownloadItem::COMPLETE; |
130 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 130 on_completed_loop_->PostTask(FROM_HERE, base::Bind( |
131 on_completed_, is_complete)); | 131 on_completed_, is_complete)); |
132 on_completed_.Reset(); | 132 on_completed_.Reset(); |
133 } | 133 } |
134 download_item_->RemoveObserver(this); | 134 download_item_->RemoveObserver(this); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 234 |
235 void DragDownloadFile::CheckThread() { | 235 void DragDownloadFile::CheckThread() { |
236 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
237 DCHECK(drag_message_loop_ == base::MessageLoop::current()); | 237 DCHECK(drag_message_loop_ == base::MessageLoop::current()); |
238 #else | 238 #else |
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
240 #endif | 240 #endif |
241 } | 241 } |
242 | 242 |
243 } // namespace content | 243 } // namespace content |
OLD | NEW |