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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 }; | 174 }; |
175 | 175 |
176 static void SetContentSettingsForTesting(HostContentSettingsMap* settings); | 176 static void SetContentSettingsForTesting(HostContentSettingsMap* settings); |
177 | 177 |
178 DownloadRequestLimiter(); | 178 DownloadRequestLimiter(); |
179 | 179 |
180 // Returns the download status for a page. This does not change the state in | 180 // Returns the download status for a page. This does not change the state in |
181 // anyway. | 181 // anyway. |
182 DownloadStatus GetDownloadStatus(content::WebContents* tab); | 182 DownloadStatus GetDownloadStatus(content::WebContents* tab); |
183 | 183 |
184 // Updates the state of the page as necessary and notifies the callback. | 184 // Check if download can proceed and notifies the callback on UI thread. |
185 // WARNING: both this call and the callback are invoked on the io thread. | 185 void CanDownload(int render_process_host_id, |
186 void CanDownloadOnIOThread(int render_process_host_id, | 186 int render_view_id, |
187 int render_view_id, | 187 const GURL& url, |
188 const GURL& url, | 188 const std::string& request_method, |
189 const std::string& request_method, | 189 const Callback& callback); |
190 const Callback& callback); | |
191 | 190 |
192 private: | 191 private: |
193 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); | 192 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); |
194 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; | 193 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; |
195 friend class DownloadRequestLimiterTest; | 194 friend class DownloadRequestLimiterTest; |
196 friend class TabDownloadState; | 195 friend class TabDownloadState; |
197 | 196 |
198 ~DownloadRequestLimiter(); | 197 ~DownloadRequestLimiter(); |
199 | 198 |
200 // Gets the download state for the specified controller. If the | 199 // Gets the download state for the specified controller. If the |
201 // TabDownloadState does not exist and |create| is true, one is created. | 200 // TabDownloadState does not exist and |create| is true, one is created. |
202 // See TabDownloadState's constructor description for details on the two | 201 // See TabDownloadState's constructor description for details on the two |
203 // controllers. | 202 // controllers. |
204 // | 203 // |
205 // The returned TabDownloadState is owned by the DownloadRequestLimiter and | 204 // The returned TabDownloadState is owned by the DownloadRequestLimiter and |
206 // deleted when no longer needed (the Remove method is invoked). | 205 // deleted when no longer needed (the Remove method is invoked). |
207 TabDownloadState* GetDownloadState( | 206 TabDownloadState* GetDownloadState( |
208 content::WebContents* web_contents, | 207 content::WebContents* web_contents, |
209 content::WebContents* originating_web_contents, | 208 content::WebContents* originating_web_contents, |
210 bool create); | 209 bool create); |
211 | 210 |
212 // CanDownloadOnIOThread invokes this on the UI thread. This determines the | |
213 // tab and invokes CanDownloadImpl. | |
214 void CanDownload(int render_process_host_id, | |
215 int render_view_id, | |
216 const GURL& url, | |
217 const std::string& request_method, | |
218 const Callback& callback); | |
219 | |
220 // Does the work of updating the download status on the UI thread and | 211 // Does the work of updating the download status on the UI thread and |
221 // potentially prompting the user. | 212 // potentially prompting the user. |
222 void CanDownloadImpl(content::WebContents* originating_contents, | 213 void CanDownloadImpl(content::WebContents* originating_contents, |
223 const std::string& request_method, | 214 const std::string& request_method, |
224 const Callback& callback); | 215 const Callback& callback); |
225 | 216 |
226 // Invoked when decision to download has been made. | 217 // Invoked when decision to download has been made. |
227 void OnCanDownloadDecided(int render_process_host_id, | 218 void OnCanDownloadDecided(int render_process_host_id, |
228 int render_view_id, | 219 int render_view_id, |
229 const std::string& request_method, | 220 const std::string& request_method, |
(...skipping 21 matching lines...) Expand all Loading... |
251 StateMap state_map_; | 242 StateMap state_map_; |
252 | 243 |
253 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously | 244 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously |
254 // about the download. | 245 // about the download. |
255 base::WeakPtrFactory<DownloadRequestLimiter> factory_; | 246 base::WeakPtrFactory<DownloadRequestLimiter> factory_; |
256 | 247 |
257 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); | 248 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); |
258 }; | 249 }; |
259 | 250 |
260 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 251 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
OLD | NEW |