Chromium Code Reviews| 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_resource_throttle.h" | 5 #include "chrome/browser/download/download_resource_throttle.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/download/download_stats.h" | 8 #include "chrome/browser/download/download_stats.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/resource_controller.h" | 10 #include "content/public/browser/resource_controller.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 void OnCanDownloadDecided(base::WeakPtr<DownloadResourceThrottle> throttle, | 23 void OnCanDownloadDecided(base::WeakPtr<DownloadResourceThrottle> throttle, |
| 24 bool allow) { | 24 bool allow) { |
| 25 BrowserThread::PostTask( | 25 BrowserThread::PostTask( |
| 26 BrowserThread::IO, FROM_HERE, | 26 BrowserThread::IO, FROM_HERE, |
| 27 base::Bind(&DownloadResourceThrottle::ContinueDownload, throttle, allow)); | 27 base::Bind(&DownloadResourceThrottle::ContinueDownload, throttle, allow)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void CanDownload( | 30 void CanDownload( |
| 31 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) { | 31 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 33 info->limiter->CanDownload(info->render_process_id, info->render_view_id, | 33 info->limiter->CanDownload(info->web_contents_getter, info->url, |
| 34 info->url, info->request_method, | 34 info->request_method, info->continue_callback); |
| 35 info->continue_callback); | |
| 36 } | 35 } |
| 37 | 36 |
| 38 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
| 39 void OnAcquireFileAccessPermissionDone( | 38 void OnAcquireFileAccessPermissionDone( |
| 40 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info, | 39 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info, |
| 41 bool granted) { | 40 bool granted) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 if (granted) | 42 if (granted) |
| 44 CanDownload(info.Pass()); | 43 CanDownload(info.Pass()); |
| 45 else | 44 else |
| 46 info->continue_callback.Run(false); | 45 info->continue_callback.Run(false); |
| 47 } | 46 } |
| 48 #endif | 47 #endif |
| 49 | 48 |
| 50 void CanDownloadOnUIThread( | 49 void CanDownloadOnUIThread( |
| 51 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) { | 50 scoped_ptr<DownloadResourceThrottle::DownloadRequestInfo> info) { |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 53 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
| 54 int process_id = info->render_process_id; | 53 content::WebContents* contents = info->web_contents_getter.Run(); |
| 55 int render_view_id = info->render_view_id; | 54 if (!contents) |
| 55 OnAcquireFileAccessPermissionDone(false); | |
|
asanka
2015/11/25 19:33:02
Need to pass info.
clamy
2015/11/27 13:29:06
Done.
| |
| 56 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( | 56 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( |
| 57 process_id, render_view_id, base::Bind(&OnAcquireFileAccessPermissionDone, | 57 contents, base::Bind(&OnAcquireFileAccessPermissionDone, |
| 58 base::Passed(info.Pass()))); | 58 base::Passed(info.Pass()))); |
| 59 #else | 59 #else |
| 60 CanDownload(info.Pass()); | 60 CanDownload(info.Pass()); |
| 61 #endif | 61 #endif |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 DownloadResourceThrottle::DownloadRequestInfo::DownloadRequestInfo( | 66 DownloadResourceThrottle::DownloadRequestInfo::DownloadRequestInfo( |
| 67 scoped_refptr<DownloadRequestLimiter> limiter, | 67 scoped_refptr<DownloadRequestLimiter> limiter, |
| 68 int render_process_id, | 68 const content::ResourceRequestInfo::WebContentsGetterOnUIThread& |
| 69 int render_view_id, | 69 web_contents_getter, |
| 70 const GURL& url, | 70 const GURL& url, |
| 71 const std::string& request_method, | 71 const std::string& request_method, |
| 72 const DownloadRequestLimiter::Callback& continue_callback) | 72 const DownloadRequestLimiter::Callback& continue_callback) |
| 73 : limiter(limiter), | 73 : limiter(limiter), |
| 74 render_process_id(render_process_id), | 74 web_contents_getter(web_contents_getter), |
| 75 render_view_id(render_view_id), | |
| 76 url(url), | 75 url(url), |
| 77 request_method(request_method), | 76 request_method(request_method), |
| 78 continue_callback(continue_callback) {} | 77 continue_callback(continue_callback) {} |
| 79 | 78 |
| 80 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} | 79 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} |
| 81 | 80 |
| 82 DownloadResourceThrottle::DownloadResourceThrottle( | 81 DownloadResourceThrottle::DownloadResourceThrottle( |
| 83 scoped_refptr<DownloadRequestLimiter> limiter, | 82 scoped_refptr<DownloadRequestLimiter> limiter, |
| 84 int render_process_id, | 83 const content::ResourceRequestInfo::WebContentsGetterOnUIThread& |
| 85 int render_view_id, | 84 web_contents_getter, |
| 86 const GURL& url, | 85 const GURL& url, |
| 87 const std::string& request_method) | 86 const std::string& request_method) |
| 88 : querying_limiter_(true), | 87 : querying_limiter_(true), |
| 89 request_allowed_(false), | 88 request_allowed_(false), |
| 90 request_deferred_(false) { | 89 request_deferred_(false) { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 92 BrowserThread::PostTask( | 91 BrowserThread::PostTask( |
| 93 BrowserThread::UI, FROM_HERE, | 92 BrowserThread::UI, FROM_HERE, |
| 94 base::Bind( | 93 base::Bind( |
| 95 &CanDownloadOnUIThread, | 94 &CanDownloadOnUIThread, |
| 96 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( | 95 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( |
| 97 limiter, render_process_id, render_view_id, url, request_method, | 96 limiter, web_contents_getter, url, request_method, |
| 98 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); | 97 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); |
| 99 } | 98 } |
| 100 | 99 |
| 101 DownloadResourceThrottle::~DownloadResourceThrottle() { | 100 DownloadResourceThrottle::~DownloadResourceThrottle() { |
| 102 } | 101 } |
| 103 | 102 |
| 104 void DownloadResourceThrottle::WillStartRequest(bool* defer) { | 103 void DownloadResourceThrottle::WillStartRequest(bool* defer) { |
| 105 WillDownload(defer); | 104 WillDownload(defer); |
| 106 } | 105 } |
| 107 | 106 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 147 |
| 149 if (request_deferred_) { | 148 if (request_deferred_) { |
| 150 request_deferred_ = false; | 149 request_deferred_ = false; |
| 151 if (allow) { | 150 if (allow) { |
| 152 controller()->Resume(); | 151 controller()->Resume(); |
| 153 } else { | 152 } else { |
| 154 controller()->Cancel(); | 153 controller()->Cancel(); |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 } | 156 } |
| OLD | NEW |