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, |
davidben
2015/11/24 15:51:16
Since we're already on the UI thread, I'd probably
clamy
2015/11/25 14:02:02
If I do that though I have to get back a RPH + RFH
| |
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; | |
55 int render_view_id = info->render_view_id; | |
56 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( | 53 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( |
57 process_id, render_view_id, base::Bind(&OnAcquireFileAccessPermissionDone, | 54 info->web_contents_getter.Run(), |
58 base::Passed(info.Pass()))); | 55 base::Bind(&OnAcquireFileAccessPermissionDone, |
56 base::Passed(info.Pass()))); | |
59 #else | 57 #else |
60 CanDownload(info.Pass()); | 58 CanDownload(info.Pass()); |
61 #endif | 59 #endif |
62 } | 60 } |
63 | 61 |
64 } // namespace | 62 } // namespace |
65 | 63 |
66 DownloadResourceThrottle::DownloadRequestInfo::DownloadRequestInfo( | 64 DownloadResourceThrottle::DownloadRequestInfo::DownloadRequestInfo( |
67 scoped_refptr<DownloadRequestLimiter> limiter, | 65 scoped_refptr<DownloadRequestLimiter> limiter, |
68 int render_process_id, | 66 const base::Callback<content::WebContents*(void)>& web_contents_getter, |
69 int render_view_id, | |
70 const GURL& url, | 67 const GURL& url, |
71 const std::string& request_method, | 68 const std::string& request_method, |
72 const DownloadRequestLimiter::Callback& continue_callback) | 69 const DownloadRequestLimiter::Callback& continue_callback) |
73 : limiter(limiter), | 70 : limiter(limiter), |
74 render_process_id(render_process_id), | 71 web_contents_getter(web_contents_getter), |
75 render_view_id(render_view_id), | |
76 url(url), | 72 url(url), |
77 request_method(request_method), | 73 request_method(request_method), |
78 continue_callback(continue_callback) {} | 74 continue_callback(continue_callback) {} |
79 | 75 |
80 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} | 76 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} |
81 | 77 |
82 DownloadResourceThrottle::DownloadResourceThrottle( | 78 DownloadResourceThrottle::DownloadResourceThrottle( |
83 scoped_refptr<DownloadRequestLimiter> limiter, | 79 scoped_refptr<DownloadRequestLimiter> limiter, |
84 int render_process_id, | 80 const base::Callback<content::WebContents*(void)>& web_contents_getter, |
85 int render_view_id, | |
86 const GURL& url, | 81 const GURL& url, |
87 const std::string& request_method) | 82 const std::string& request_method) |
88 : querying_limiter_(true), | 83 : querying_limiter_(true), |
89 request_allowed_(false), | 84 request_allowed_(false), |
90 request_deferred_(false) { | 85 request_deferred_(false) { |
91 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
92 BrowserThread::PostTask( | 87 BrowserThread::PostTask( |
93 BrowserThread::UI, FROM_HERE, | 88 BrowserThread::UI, FROM_HERE, |
94 base::Bind( | 89 base::Bind( |
95 &CanDownloadOnUIThread, | 90 &CanDownloadOnUIThread, |
96 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( | 91 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( |
97 limiter, render_process_id, render_view_id, url, request_method, | 92 limiter, web_contents_getter, url, request_method, |
98 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); | 93 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); |
99 } | 94 } |
100 | 95 |
101 DownloadResourceThrottle::~DownloadResourceThrottle() { | 96 DownloadResourceThrottle::~DownloadResourceThrottle() { |
102 } | 97 } |
103 | 98 |
104 void DownloadResourceThrottle::WillStartRequest(bool* defer) { | 99 void DownloadResourceThrottle::WillStartRequest(bool* defer) { |
105 WillDownload(defer); | 100 WillDownload(defer); |
106 } | 101 } |
107 | 102 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 143 |
149 if (request_deferred_) { | 144 if (request_deferred_) { |
150 request_deferred_ = false; | 145 request_deferred_ = false; |
151 if (allow) { | 146 if (allow) { |
152 controller()->Resume(); | 147 controller()->Resume(); |
153 } else { | 148 } else { |
154 controller()->Cancel(); | 149 controller()->Cancel(); |
155 } | 150 } |
156 } | 151 } |
157 } | 152 } |
OLD | NEW |