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

Side by Side Diff: chrome/browser/download/download_test_observer.cc

Issue 8960010: base::Bind: Convert NewRunnableMethod in chrome/browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix 55. Created 9 years 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
OLDNEW
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/bind.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "base/task.h"
11 #include "chrome/browser/download/download_test_observer.h" 11 #include "chrome/browser/download/download_test_observer.h"
12 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 using content::DownloadItem; 16 using content::DownloadItem;
17 using content::DownloadManager; 17 using content::DownloadManager;
18 18
19 // These functions take scoped_refptr's to DownloadManager because they 19 // These functions take scoped_refptr's to DownloadManager because they
20 // are posted to message queues, and hence may execute arbitrarily after 20 // are posted to message queues, and hence may execute arbitrarily after
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 // Calling DangerousDownloadValidated() at this point will 101 // Calling DangerousDownloadValidated() at this point will
102 // cause the download to be completed twice. Do what the real UI 102 // cause the download to be completed twice. Do what the real UI
103 // code does: make the call as a delayed task. 103 // code does: make the call as a delayed task.
104 switch (dangerous_download_action_) { 104 switch (dangerous_download_action_) {
105 case ON_DANGEROUS_DOWNLOAD_ACCEPT: 105 case ON_DANGEROUS_DOWNLOAD_ACCEPT:
106 // Fake user click on "Accept". Delay the actual click, as the 106 // Fake user click on "Accept". Delay the actual click, as the
107 // real UI would. 107 // real UI would.
108 BrowserThread::PostTask( 108 BrowserThread::PostTask(
109 BrowserThread::UI, FROM_HERE, 109 BrowserThread::UI, FROM_HERE,
110 NewRunnableFunction( 110 base::Bind(&AcceptDangerousDownload, download_manager_,
111 &AcceptDangerousDownload, 111 download->GetId()));
112 download_manager_,
113 download->GetId()));
114 break; 112 break;
115 113
116 case ON_DANGEROUS_DOWNLOAD_DENY: 114 case ON_DANGEROUS_DOWNLOAD_DENY:
117 // 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
118 // real UI would. 116 // real UI would.
119 BrowserThread::PostTask( 117 BrowserThread::PostTask(
120 BrowserThread::UI, FROM_HERE, 118 BrowserThread::UI, FROM_HERE,
121 NewRunnableFunction( 119 base::Bind(&DenyDangerousDownload, download_manager_,
122 &DenyDangerousDownload, 120 download->GetId()));
123 download_manager_,
124 download->GetId()));
125 break; 121 break;
126 122
127 case ON_DANGEROUS_DOWNLOAD_FAIL: 123 case ON_DANGEROUS_DOWNLOAD_FAIL:
128 ADD_FAILURE() << "Unexpected dangerous download item."; 124 ADD_FAILURE() << "Unexpected dangerous download item.";
129 break; 125 break;
130 126
131 default: 127 default:
132 NOTREACHED(); 128 NOTREACHED();
133 } 129 }
134 } 130 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 for (DownloadSet::iterator it = downloads_observed_.begin(); 268 for (DownloadSet::iterator it = downloads_observed_.begin();
273 it != downloads_observed_.end(); ++it) { 269 it != downloads_observed_.end(); ++it) {
274 (*it)->RemoveObserver(this); 270 (*it)->RemoveObserver(this);
275 } 271 }
276 downloads_observed_.clear(); 272 downloads_observed_.clear();
277 273
278 // Trigger next step. We need to go past the IO thread twice, as 274 // Trigger next step. We need to go past the IO thread twice, as
279 // there's a self-task posting in the IO thread cancel path. 275 // there's a self-task posting in the IO thread cancel path.
280 BrowserThread::PostTask( 276 BrowserThread::PostTask(
281 BrowserThread::FILE, FROM_HERE, 277 BrowserThread::FILE, FROM_HERE,
282 NewRunnableMethod(this, 278 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, 2));
283 &DownloadTestFlushObserver::PingFileThread, 2));
284 } 279 }
285 } 280 }
286 } 281 }
287 282
288 void DownloadTestFlushObserver::PingFileThread(int cycle) { 283 void DownloadTestFlushObserver::PingFileThread(int cycle) {
289 BrowserThread::PostTask( 284 BrowserThread::PostTask(
290 BrowserThread::IO, FROM_HERE, 285 BrowserThread::IO, FROM_HERE,
291 NewRunnableMethod(this, &DownloadTestFlushObserver::PingIOThread, 286 base::Bind(&DownloadTestFlushObserver::PingIOThread, this, cycle));
292 cycle));
293 } 287 }
294 288
295 void DownloadTestFlushObserver::PingIOThread(int cycle) { 289 void DownloadTestFlushObserver::PingIOThread(int cycle) {
296 if (--cycle) { 290 if (--cycle) {
297 BrowserThread::PostTask( 291 BrowserThread::PostTask(
298 BrowserThread::UI, FROM_HERE, 292 BrowserThread::UI, FROM_HERE,
299 NewRunnableMethod(this, &DownloadTestFlushObserver::PingFileThread, 293 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle));
300 cycle));
301 } else { 294 } else {
302 BrowserThread::PostTask( 295 BrowserThread::PostTask(
303 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 296 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
304 } 297 }
305 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_prefs.cc ('k') | chrome/browser/extensions/extension_page_capture_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698