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 "chrome/browser/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
10 #include "chrome/browser/download/download_permission_request.h" | 10 #include "chrome/browser/download/download_permission_request.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 280 } |
281 | 281 |
282 void DownloadRequestLimiter::CanDownloadOnIOThread( | 282 void DownloadRequestLimiter::CanDownloadOnIOThread( |
283 int render_process_host_id, | 283 int render_process_host_id, |
284 int render_view_id, | 284 int render_view_id, |
285 const GURL& url, | 285 const GURL& url, |
286 const std::string& request_method, | 286 const std::string& request_method, |
287 const Callback& callback) { | 287 const Callback& callback) { |
288 // This is invoked on the IO thread. Schedule the task to run on the UI | 288 // This is invoked on the IO thread. Schedule the task to run on the UI |
289 // thread so that we can query UI state. | 289 // thread so that we can query UI state. |
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
291 BrowserThread::PostTask( | 291 BrowserThread::PostTask( |
292 BrowserThread::UI, FROM_HERE, | 292 BrowserThread::UI, FROM_HERE, |
293 base::Bind(&DownloadRequestLimiter::CanDownload, this, | 293 base::Bind(&DownloadRequestLimiter::CanDownload, this, |
294 render_process_host_id, render_view_id, url, | 294 render_process_host_id, render_view_id, url, |
295 request_method, callback)); | 295 request_method, callback)); |
296 } | 296 } |
297 | 297 |
298 DownloadRequestLimiter::TabDownloadState* | 298 DownloadRequestLimiter::TabDownloadState* |
299 DownloadRequestLimiter::GetDownloadState( | 299 DownloadRequestLimiter::GetDownloadState( |
300 content::WebContents* web_contents, | 300 content::WebContents* web_contents, |
(...skipping 11 matching lines...) Expand all Loading... |
312 new TabDownloadState(this, web_contents, originating_web_contents); | 312 new TabDownloadState(this, web_contents, originating_web_contents); |
313 state_map_[web_contents] = state; | 313 state_map_[web_contents] = state; |
314 return state; | 314 return state; |
315 } | 315 } |
316 | 316 |
317 void DownloadRequestLimiter::CanDownload(int render_process_host_id, | 317 void DownloadRequestLimiter::CanDownload(int render_process_host_id, |
318 int render_view_id, | 318 int render_view_id, |
319 const GURL& url, | 319 const GURL& url, |
320 const std::string& request_method, | 320 const std::string& request_method, |
321 const Callback& callback) { | 321 const Callback& callback) { |
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
323 | 323 |
324 content::WebContents* originating_contents = | 324 content::WebContents* originating_contents = |
325 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); | 325 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); |
326 if (!originating_contents) { | 326 if (!originating_contents) { |
327 // The WebContents was closed, don't allow the download. | 327 // The WebContents was closed, don't allow the download. |
328 ScheduleNotification(callback, false); | 328 ScheduleNotification(callback, false); |
329 return; | 329 return; |
330 } | 330 } |
331 | 331 |
332 if (!originating_contents->GetDelegate()) { | 332 if (!originating_contents->GetDelegate()) { |
(...skipping 17 matching lines...) Expand all Loading... |
350 url, | 350 url, |
351 request_method, | 351 request_method, |
352 can_download_callback); | 352 can_download_callback); |
353 } | 353 } |
354 | 354 |
355 void DownloadRequestLimiter::OnCanDownloadDecided( | 355 void DownloadRequestLimiter::OnCanDownloadDecided( |
356 int render_process_host_id, | 356 int render_process_host_id, |
357 int render_view_id, | 357 int render_view_id, |
358 const std::string& request_method, | 358 const std::string& request_method, |
359 const Callback& orig_callback, bool allow) { | 359 const Callback& orig_callback, bool allow) { |
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 360 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
361 content::WebContents* originating_contents = | 361 content::WebContents* originating_contents = |
362 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); | 362 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); |
363 if (!originating_contents || !allow) { | 363 if (!originating_contents || !allow) { |
364 ScheduleNotification(orig_callback, false); | 364 ScheduleNotification(orig_callback, false); |
365 return; | 365 return; |
366 } | 366 } |
367 | 367 |
368 CanDownloadImpl(originating_contents, | 368 CanDownloadImpl(originating_contents, |
369 request_method, | 369 request_method, |
370 orig_callback); | 370 orig_callback); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 BrowserThread::PostTask( | 457 BrowserThread::PostTask( |
458 BrowserThread::IO, FROM_HERE, base::Bind(callback, allow)); | 458 BrowserThread::IO, FROM_HERE, base::Bind(callback, allow)); |
459 } | 459 } |
460 | 460 |
461 void DownloadRequestLimiter::Remove(TabDownloadState* state, | 461 void DownloadRequestLimiter::Remove(TabDownloadState* state, |
462 content::WebContents* contents) { | 462 content::WebContents* contents) { |
463 DCHECK(ContainsKey(state_map_, contents)); | 463 DCHECK(ContainsKey(state_map_, contents)); |
464 state_map_.erase(contents); | 464 state_map_.erase(contents); |
465 delete state; | 465 delete state; |
466 } | 466 } |
OLD | NEW |