Index: chrome/browser/download/download_resource_throttle.cc |
diff --git a/chrome/browser/download/download_resource_throttle.cc b/chrome/browser/download/download_resource_throttle.cc |
index a8e2afa02b153b8f36aa26d8c0ec260aabac9a95..b4a8f0216d02f8470b42dd14add4b94fec3a95ae 100644 |
--- a/chrome/browser/download/download_resource_throttle.cc |
+++ b/chrome/browser/download/download_resource_throttle.cc |
@@ -6,10 +6,80 @@ |
#include "base/bind.h" |
#include "chrome/browser/download/download_stats.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/resource_controller.h" |
+#if defined(OS_ANDROID) |
+#include "content/public/browser/android/download_controller_android.h" |
+#include "content/public/browser/render_view_host.h" |
+ |
+using content::DownloadControllerAndroid; |
+#endif |
+ |
+using content::BrowserThread; |
+ |
+namespace { |
+ |
+void OnCanDownloadDecided( |
+ const DownloadRequestLimiter::Callback& callback, bool allow) { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, base::Bind(callback, allow)); |
+} |
+ |
+void CanDownload( |
+ scoped_refptr<DownloadRequestLimiter> limiter, |
+ int render_process_id, |
+ int render_view_id, |
+ const GURL& url, |
+ const std::string& request_method, |
+ const DownloadRequestLimiter::Callback& continue_callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ limiter->CanDownload(render_process_id, render_view_id, url, request_method, |
+ base::Bind(&OnCanDownloadDecided, continue_callback)); |
+} |
+ |
+#if defined(OS_ANDROID) |
+void OnAcquireFileAccessPermissionDone( |
+ scoped_refptr<DownloadRequestLimiter> limiter, |
+ int render_process_id, |
+ int render_view_id, |
+ const GURL& url, |
+ const std::string& request_method, |
+ const DownloadRequestLimiter::Callback& continue_callback, |
+ bool granted) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ if (granted) { |
+ CanDownload(limiter, render_process_id, render_view_id, url, |
+ request_method, continue_callback); |
+ } else { |
+ OnCanDownloadDecided(continue_callback, false); |
+ } |
+} |
+#endif |
+ |
+void CanDownloadOnUIThread( |
+ scoped_refptr<DownloadRequestLimiter> limiter, |
+ int render_process_id, |
+ int render_view_id, |
+ const GURL& url, |
+ const std::string& request_method, |
+ const DownloadRequestLimiter::Callback& continue_callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+#if defined(OS_ANDROID) |
+ content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( |
+ render_process_id, render_view_id, base::Bind( |
+ &OnAcquireFileAccessPermissionDone, limiter, render_process_id, |
+ render_view_id, url, request_method, continue_callback)); |
+#else |
+ CanDownload(limiter, render_process_id, render_view_id, url, |
+ request_method, continue_callback); |
+#endif |
+} |
+ |
+} // namespace |
+ |
DownloadResourceThrottle::DownloadResourceThrottle( |
- DownloadRequestLimiter* limiter, |
+ scoped_refptr<DownloadRequestLimiter> limiter, |
int render_process_id, |
int render_view_id, |
const GURL& url, |
@@ -17,13 +87,12 @@ DownloadResourceThrottle::DownloadResourceThrottle( |
: querying_limiter_(true), |
request_allowed_(false), |
request_deferred_(false) { |
- limiter->CanDownloadOnIOThread( |
- render_process_id, |
- render_view_id, |
- url, |
- request_method, |
- base::Bind(&DownloadResourceThrottle::ContinueDownload, |
- AsWeakPtr())); |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, base::Bind( |
+ &CanDownloadOnUIThread, limiter, render_process_id, render_view_id, |
asanka
2015/07/21 01:14:00
Nit: When you find yourself binding / unpacking /
qinmin
2015/07/21 22:42:17
Done.
|
+ url, request_method,base::Bind( |
asanka
2015/07/21 01:14:00
Nit: space after ,
Also run through 'git cl forma
qinmin
2015/07/21 22:42:17
Done.
|
+ &DownloadResourceThrottle::ContinueDownload, AsWeakPtr()))); |
asanka
2015/07/21 01:14:00
Nit: Rather than passing up a callback that must b
qinmin
2015/07/21 22:42:17
In that case, I need to make DownloadResourceThrot
|
} |
DownloadResourceThrottle::~DownloadResourceThrottle() { |
@@ -62,6 +131,7 @@ void DownloadResourceThrottle::WillDownload(bool* defer) { |
} |
void DownloadResourceThrottle::ContinueDownload(bool allow) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
querying_limiter_ = false; |
request_allowed_ = allow; |