Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: content/public/test/download_test_observer.cc

Issue 14947007: [Downloads] Allow acquiring dangerous download file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/browser/download_item.h ('k') | content/public/test/mock_download_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/test/download_test_observer.h" 5 #include "content/public/test/download_test_observer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 downloads_observed_.erase(it); 134 downloads_observed_.erase(it);
135 download->RemoveObserver(this); 135 download->RemoveObserver(this);
136 } 136 }
137 137
138 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { 138 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
139 // Real UI code gets the user's response after returning from the observer. 139 // Real UI code gets the user's response after returning from the observer.
140 if (download->IsDangerous() && 140 if (download->IsDangerous() &&
141 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { 141 !ContainsKey(dangerous_downloads_seen_, download->GetId())) {
142 dangerous_downloads_seen_.insert(download->GetId()); 142 dangerous_downloads_seen_.insert(download->GetId());
143 143
144 // Calling DangerousDownloadValidated() at this point will 144 // Calling ValidateDangerousDownload() at this point will
145 // cause the download to be completed twice. Do what the real UI 145 // cause the download to be completed twice. Do what the real UI
146 // code does: make the call as a delayed task. 146 // code does: make the call as a delayed task.
147 switch (dangerous_download_action_) { 147 switch (dangerous_download_action_) {
148 case ON_DANGEROUS_DOWNLOAD_ACCEPT: 148 case ON_DANGEROUS_DOWNLOAD_ACCEPT:
149 // Fake user click on "Accept". Delay the actual click, as the 149 // Fake user click on "Accept". Delay the actual click, as the
150 // real UI would. 150 // real UI would.
151 BrowserThread::PostTask( 151 BrowserThread::PostTask(
152 BrowserThread::UI, FROM_HERE, 152 BrowserThread::UI, FROM_HERE,
153 base::Bind(&DownloadTestObserver::AcceptDangerousDownload, 153 base::Bind(&DownloadTestObserver::AcceptDangerousDownload,
154 weak_factory_.GetWeakPtr(), 154 weak_factory_.GetWeakPtr(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 base::MessageLoopForUI::current()->Quit(); 215 base::MessageLoopForUI::current()->Quit();
216 } 216 }
217 217
218 void DownloadTestObserver::AcceptDangerousDownload(int32 download_id) { 218 void DownloadTestObserver::AcceptDangerousDownload(int32 download_id) {
219 // Download manager was shutdown before the UI thread could accept the 219 // Download manager was shutdown before the UI thread could accept the
220 // download. 220 // download.
221 if (!download_manager_) 221 if (!download_manager_)
222 return; 222 return;
223 DownloadItem* download = download_manager_->GetDownload(download_id); 223 DownloadItem* download = download_manager_->GetDownload(download_id);
224 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) 224 if (download && (download->GetState() == DownloadItem::IN_PROGRESS))
225 download->DangerousDownloadValidated(); 225 download->ValidateDangerousDownload();
226 } 226 }
227 227
228 void DownloadTestObserver::DenyDangerousDownload(int32 download_id) { 228 void DownloadTestObserver::DenyDangerousDownload(int32 download_id) {
229 // Download manager was shutdown before the UI thread could deny the 229 // Download manager was shutdown before the UI thread could deny the
230 // download. 230 // download.
231 if (!download_manager_) 231 if (!download_manager_)
232 return; 232 return;
233 DownloadItem* download = download_manager_->GetDownload(download_id); 233 DownloadItem* download = download_manager_->GetDownload(download_id);
234 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) { 234 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) {
235 download->Cancel(true); 235 download->Remove();
236 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
237 } 236 }
238 } 237 }
239 238
240 DownloadTestObserverTerminal::DownloadTestObserverTerminal( 239 DownloadTestObserverTerminal::DownloadTestObserverTerminal(
241 DownloadManager* download_manager, 240 DownloadManager* download_manager,
242 size_t wait_count, 241 size_t wait_count,
243 DangerousDownloadAction dangerous_download_action) 242 DangerousDownloadAction dangerous_download_action)
244 : DownloadTestObserver(download_manager, 243 : DownloadTestObserver(download_manager,
245 wait_count, 244 wait_count,
246 dangerous_download_action) { 245 dangerous_download_action) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 base::MessageLoopForUI::current()->Quit(); 420 base::MessageLoopForUI::current()->Quit();
422 } 421 }
423 422
424 const DownloadUrlParameters::OnStartedCallback 423 const DownloadUrlParameters::OnStartedCallback
425 DownloadTestItemCreationObserver::callback() { 424 DownloadTestItemCreationObserver::callback() {
426 return base::Bind( 425 return base::Bind(
427 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 426 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
428 } 427 }
429 428
430 } // namespace content 429 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/download_item.h ('k') | content/public/test/mock_download_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698