OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 bool DownloadTestObserver::IsFinished() const { | 76 bool DownloadTestObserver::IsFinished() const { |
77 if (finished_downloads_.size() - finished_downloads_at_construction_ >= | 77 if (finished_downloads_.size() - finished_downloads_at_construction_ >= |
78 wait_count_) | 78 wait_count_) |
79 return true; | 79 return true; |
80 return (finish_on_select_file_ && select_file_dialog_seen_); | 80 return (finish_on_select_file_ && select_file_dialog_seen_); |
81 } | 81 } |
82 | 82 |
83 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { | 83 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { |
84 // The REMOVING state indicates that the download is being destroyed. | 84 // The REMOVING state indicates that the download is being destroyed. |
85 // Stop observing. Do not do anything with it, as it is about to be gone. | 85 // Stop observing. Do not do anything with it, as it is about to be gone. |
86 if (download->state() == DownloadItem::REMOVING) { | 86 if (download->GetState() == DownloadItem::REMOVING) { |
87 DownloadSet::iterator it = downloads_observed_.find(download); | 87 DownloadSet::iterator it = downloads_observed_.find(download); |
88 ASSERT_TRUE(it != downloads_observed_.end()); | 88 ASSERT_TRUE(it != downloads_observed_.end()); |
89 downloads_observed_.erase(it); | 89 downloads_observed_.erase(it); |
90 download->RemoveObserver(this); | 90 download->RemoveObserver(this); |
91 return; | 91 return; |
92 } | 92 } |
93 | 93 |
94 // Real UI code gets the user's response after returning from the observer. | 94 // Real UI code gets the user's response after returning from the observer. |
95 if (download->safety_state() == DownloadItem::DANGEROUS && | 95 if (download->GetSafetyState() == DownloadItem::DANGEROUS && |
96 !ContainsKey(dangerous_downloads_seen_, download->id())) { | 96 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { |
97 dangerous_downloads_seen_.insert(download->id()); | 97 dangerous_downloads_seen_.insert(download->GetId()); |
98 | 98 |
99 // Calling DangerousDownloadValidated() at this point will | 99 // Calling DangerousDownloadValidated() at this point will |
100 // cause the download to be completed twice. Do what the real UI | 100 // cause the download to be completed twice. Do what the real UI |
101 // code does: make the call as a delayed task. | 101 // code does: make the call as a delayed task. |
102 switch (dangerous_download_action_) { | 102 switch (dangerous_download_action_) { |
103 case ON_DANGEROUS_DOWNLOAD_ACCEPT: | 103 case ON_DANGEROUS_DOWNLOAD_ACCEPT: |
104 // Fake user click on "Accept". Delay the actual click, as the | 104 // Fake user click on "Accept". Delay the actual click, as the |
105 // real UI would. | 105 // real UI would. |
106 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
107 BrowserThread::UI, FROM_HERE, | 107 BrowserThread::UI, FROM_HERE, |
108 NewRunnableFunction( | 108 NewRunnableFunction( |
109 &AcceptDangerousDownload, | 109 &AcceptDangerousDownload, |
110 download_manager_, | 110 download_manager_, |
111 download->id())); | 111 download->GetId())); |
112 break; | 112 break; |
113 | 113 |
114 case ON_DANGEROUS_DOWNLOAD_DENY: | 114 case ON_DANGEROUS_DOWNLOAD_DENY: |
115 // Fake a user click on "Deny". Delay the actual click, as the | 115 // Fake a user click on "Deny". Delay the actual click, as the |
116 // real UI would. | 116 // real UI would. |
117 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
118 BrowserThread::UI, FROM_HERE, | 118 BrowserThread::UI, FROM_HERE, |
119 NewRunnableFunction( | 119 NewRunnableFunction( |
120 &DenyDangerousDownload, | 120 &DenyDangerousDownload, |
121 download_manager_, | 121 download_manager_, |
122 download->id())); | 122 download->GetId())); |
123 break; | 123 break; |
124 | 124 |
125 case ON_DANGEROUS_DOWNLOAD_FAIL: | 125 case ON_DANGEROUS_DOWNLOAD_FAIL: |
126 ADD_FAILURE() << "Unexpected dangerous download item."; | 126 ADD_FAILURE() << "Unexpected dangerous download item."; |
127 break; | 127 break; |
128 | 128 |
129 default: | 129 default: |
130 NOTREACHED(); | 130 NOTREACHED(); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 if (download->state() == download_finished_state_) { | 134 if (download->GetState() == download_finished_state_) { |
135 DownloadInFinalState(download); | 135 DownloadInFinalState(download); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void DownloadTestObserver::ModelChanged() { | 139 void DownloadTestObserver::ModelChanged() { |
140 // Regenerate DownloadItem observers. If there are any download items | 140 // Regenerate DownloadItem observers. If there are any download items |
141 // in our final state, note them in |finished_downloads_| | 141 // in our final state, note them in |finished_downloads_| |
142 // (done by |OnDownloadUpdated()|). | 142 // (done by |OnDownloadUpdated()|). |
143 std::vector<DownloadItem*> downloads; | 143 std::vector<DownloadItem*> downloads; |
144 download_manager_->GetAllDownloads(FilePath(), &downloads); | 144 download_manager_->GetAllDownloads(FilePath(), &downloads); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 206 } |
207 | 207 |
208 void DownloadTestFlushObserver::ModelChanged() { | 208 void DownloadTestFlushObserver::ModelChanged() { |
209 // Model has changed, so there may be more DownloadItems to observe. | 209 // Model has changed, so there may be more DownloadItems to observe. |
210 CheckDownloadsInProgress(true); | 210 CheckDownloadsInProgress(true); |
211 } | 211 } |
212 | 212 |
213 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { | 213 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { |
214 // The REMOVING state indicates that the download is being destroyed. | 214 // The REMOVING state indicates that the download is being destroyed. |
215 // Stop observing. Do not do anything with it, as it is about to be gone. | 215 // Stop observing. Do not do anything with it, as it is about to be gone. |
216 if (download->state() == DownloadItem::REMOVING) { | 216 if (download->GetState() == DownloadItem::REMOVING) { |
217 DownloadSet::iterator it = downloads_observed_.find(download); | 217 DownloadSet::iterator it = downloads_observed_.find(download); |
218 ASSERT_TRUE(it != downloads_observed_.end()); | 218 ASSERT_TRUE(it != downloads_observed_.end()); |
219 downloads_observed_.erase(it); | 219 downloads_observed_.erase(it); |
220 download->RemoveObserver(this); | 220 download->RemoveObserver(this); |
221 return; | 221 return; |
222 } | 222 } |
223 | 223 |
224 // No change in DownloadItem set on manager. | 224 // No change in DownloadItem set on manager. |
225 CheckDownloadsInProgress(false); | 225 CheckDownloadsInProgress(false); |
226 } | 226 } |
(...skipping 11 matching lines...) Expand all Loading... |
238 // action. If requested, also observes all downloads while iterating. | 238 // action. If requested, also observes all downloads while iterating. |
239 void DownloadTestFlushObserver::CheckDownloadsInProgress( | 239 void DownloadTestFlushObserver::CheckDownloadsInProgress( |
240 bool observe_downloads) { | 240 bool observe_downloads) { |
241 if (waiting_for_zero_inprogress_) { | 241 if (waiting_for_zero_inprogress_) { |
242 int count = 0; | 242 int count = 0; |
243 | 243 |
244 std::vector<DownloadItem*> downloads; | 244 std::vector<DownloadItem*> downloads; |
245 download_manager_->SearchDownloads(string16(), &downloads); | 245 download_manager_->SearchDownloads(string16(), &downloads); |
246 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 246 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
247 it != downloads.end(); ++it) { | 247 it != downloads.end(); ++it) { |
248 if ((*it)->state() == DownloadItem::IN_PROGRESS) | 248 if ((*it)->GetState() == DownloadItem::IN_PROGRESS) |
249 count++; | 249 count++; |
250 if (observe_downloads) { | 250 if (observe_downloads) { |
251 if (downloads_observed_.find(*it) == downloads_observed_.end()) { | 251 if (downloads_observed_.find(*it) == downloads_observed_.end()) { |
252 (*it)->AddObserver(this); | 252 (*it)->AddObserver(this); |
253 downloads_observed_.insert(*it); | 253 downloads_observed_.insert(*it); |
254 } | 254 } |
255 // Download items are forever, and we don't want to make | 255 // Download items are forever, and we don't want to make |
256 // assumptions about future state transitions, so once we | 256 // assumptions about future state transitions, so once we |
257 // start observing them, we don't stop until destruction. | 257 // start observing them, we don't stop until destruction. |
258 } | 258 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 if (--cycle) { | 290 if (--cycle) { |
291 BrowserThread::PostTask( | 291 BrowserThread::PostTask( |
292 BrowserThread::UI, FROM_HERE, | 292 BrowserThread::UI, FROM_HERE, |
293 NewRunnableMethod(this, &DownloadTestFlushObserver::PingFileThread, | 293 NewRunnableMethod(this, &DownloadTestFlushObserver::PingFileThread, |
294 cycle)); | 294 cycle)); |
295 } else { | 295 } else { |
296 BrowserThread::PostTask( | 296 BrowserThread::PostTask( |
297 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask()); | 297 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask()); |
298 } | 298 } |
299 } | 299 } |
OLD | NEW |