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(info.Pass(), false); |
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::WebContentsGetter& web_contents_getter, |
69 int render_view_id, | |
70 const GURL& url, | 69 const GURL& url, |
71 const std::string& request_method, | 70 const std::string& request_method, |
72 const DownloadRequestLimiter::Callback& continue_callback) | 71 const DownloadRequestLimiter::Callback& continue_callback) |
73 : limiter(limiter), | 72 : limiter(limiter), |
74 render_process_id(render_process_id), | 73 web_contents_getter(web_contents_getter), |
75 render_view_id(render_view_id), | |
76 url(url), | 74 url(url), |
77 request_method(request_method), | 75 request_method(request_method), |
78 continue_callback(continue_callback) {} | 76 continue_callback(continue_callback) {} |
79 | 77 |
80 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} | 78 DownloadResourceThrottle::DownloadRequestInfo::~DownloadRequestInfo() {} |
81 | 79 |
82 DownloadResourceThrottle::DownloadResourceThrottle( | 80 DownloadResourceThrottle::DownloadResourceThrottle( |
83 scoped_refptr<DownloadRequestLimiter> limiter, | 81 scoped_refptr<DownloadRequestLimiter> limiter, |
84 int render_process_id, | 82 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
85 int render_view_id, | |
86 const GURL& url, | 83 const GURL& url, |
87 const std::string& request_method) | 84 const std::string& request_method) |
88 : querying_limiter_(true), | 85 : querying_limiter_(true), |
89 request_allowed_(false), | 86 request_allowed_(false), |
90 request_deferred_(false) { | 87 request_deferred_(false) { |
91 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
92 BrowserThread::PostTask( | 89 BrowserThread::PostTask( |
93 BrowserThread::UI, FROM_HERE, | 90 BrowserThread::UI, FROM_HERE, |
94 base::Bind( | 91 base::Bind( |
95 &CanDownloadOnUIThread, | 92 &CanDownloadOnUIThread, |
96 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( | 93 base::Passed(scoped_ptr<DownloadRequestInfo>(new DownloadRequestInfo( |
97 limiter, render_process_id, render_view_id, url, request_method, | 94 limiter, web_contents_getter, url, request_method, |
98 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); | 95 base::Bind(&OnCanDownloadDecided, AsWeakPtr())))))); |
99 } | 96 } |
100 | 97 |
101 DownloadResourceThrottle::~DownloadResourceThrottle() { | 98 DownloadResourceThrottle::~DownloadResourceThrottle() { |
102 } | 99 } |
103 | 100 |
104 void DownloadResourceThrottle::WillStartRequest(bool* defer) { | 101 void DownloadResourceThrottle::WillStartRequest(bool* defer) { |
105 WillDownload(defer); | 102 WillDownload(defer); |
106 } | 103 } |
107 | 104 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 145 |
149 if (request_deferred_) { | 146 if (request_deferred_) { |
150 request_deferred_ = false; | 147 request_deferred_ = false; |
151 if (allow) { | 148 if (allow) { |
152 controller()->Resume(); | 149 controller()->Resume(); |
153 } else { | 150 } else { |
154 controller()->Cancel(); | 151 controller()->Cancel(); |
155 } | 152 } |
156 } | 153 } |
157 } | 154 } |
OLD | NEW |