| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 DownloadRequestLimiter(); | 182 DownloadRequestLimiter(); |
| 183 | 183 |
| 184 // Returns the download status for a page. This does not change the state in | 184 // Returns the download status for a page. This does not change the state in |
| 185 // anyway. | 185 // anyway. |
| 186 DownloadStatus GetDownloadStatus(content::WebContents* tab); | 186 DownloadStatus GetDownloadStatus(content::WebContents* tab); |
| 187 | 187 |
| 188 // Updates the state of the page as necessary and notifies the callback. | 188 // Updates the state of the page as necessary and notifies the callback. |
| 189 // WARNING: both this call and the callback are invoked on the io thread. | 189 // WARNING: both this call and the callback are invoked on the io thread. |
| 190 void CanDownloadOnIOThread(int render_process_host_id, | 190 void CanDownloadOnIOThread(int render_process_host_id, |
| 191 int render_view_id, | 191 int render_view_id, |
| 192 int request_id, | 192 const GURL& url, |
| 193 const std::string& request_method, | 193 const std::string& request_method, |
| 194 const Callback& callback); | 194 const Callback& callback); |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); | 197 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); |
| 198 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; | 198 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; |
| 199 friend class DownloadRequestLimiterTest; | 199 friend class DownloadRequestLimiterTest; |
| 200 friend class TabDownloadState; | 200 friend class TabDownloadState; |
| 201 | 201 |
| 202 ~DownloadRequestLimiter(); | 202 ~DownloadRequestLimiter(); |
| 203 | 203 |
| 204 // Gets the download state for the specified controller. If the | 204 // Gets the download state for the specified controller. If the |
| 205 // TabDownloadState does not exist and |create| is true, one is created. | 205 // TabDownloadState does not exist and |create| is true, one is created. |
| 206 // See TabDownloadState's constructor description for details on the two | 206 // See TabDownloadState's constructor description for details on the two |
| 207 // controllers. | 207 // controllers. |
| 208 // | 208 // |
| 209 // The returned TabDownloadState is owned by the DownloadRequestLimiter and | 209 // The returned TabDownloadState is owned by the DownloadRequestLimiter and |
| 210 // deleted when no longer needed (the Remove method is invoked). | 210 // deleted when no longer needed (the Remove method is invoked). |
| 211 TabDownloadState* GetDownloadState( | 211 TabDownloadState* GetDownloadState( |
| 212 content::WebContents* web_contents, | 212 content::WebContents* web_contents, |
| 213 content::WebContents* originating_web_contents, | 213 content::WebContents* originating_web_contents, |
| 214 bool create); | 214 bool create); |
| 215 | 215 |
| 216 // CanDownloadOnIOThread invokes this on the UI thread. This determines the | 216 // CanDownloadOnIOThread invokes this on the UI thread. This determines the |
| 217 // tab and invokes CanDownloadImpl. | 217 // tab and invokes CanDownloadImpl. |
| 218 void CanDownload(int render_process_host_id, | 218 void CanDownload(int render_process_host_id, |
| 219 int render_view_id, | 219 int render_view_id, |
| 220 int request_id, | 220 const GURL& url, |
| 221 const std::string& request_method, | 221 const std::string& request_method, |
| 222 const Callback& callback); | 222 const Callback& callback); |
| 223 | 223 |
| 224 // Does the work of updating the download status on the UI thread and | 224 // Does the work of updating the download status on the UI thread and |
| 225 // potentially prompting the user. | 225 // potentially prompting the user. |
| 226 void CanDownloadImpl(content::WebContents* originating_contents, | 226 void CanDownloadImpl(content::WebContents* originating_contents, |
| 227 int request_id, | |
| 228 const std::string& request_method, | 227 const std::string& request_method, |
| 229 const Callback& callback); | 228 const Callback& callback); |
| 230 | 229 |
| 231 // Invoked when decision to download has been made. | 230 // Invoked when decision to download has been made. |
| 232 void OnCanDownloadDecided(int render_process_host_id, | 231 void OnCanDownloadDecided(int render_process_host_id, |
| 233 int render_view_id, | 232 int render_view_id, |
| 234 int request_id, | |
| 235 const std::string& request_method, | 233 const std::string& request_method, |
| 236 const Callback& orig_callback, | 234 const Callback& orig_callback, |
| 237 bool allow); | 235 bool allow); |
| 238 | 236 |
| 239 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io | 237 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io |
| 240 // thread. | 238 // thread. |
| 241 void ScheduleNotification(const Callback& callback, bool allow); | 239 void ScheduleNotification(const Callback& callback, bool allow); |
| 242 | 240 |
| 243 // Removes the specified TabDownloadState from the internal map and deletes | 241 // Removes the specified TabDownloadState from the internal map and deletes |
| 244 // it. This has the effect of resetting the status for the tab to | 242 // it. This has the effect of resetting the status for the tab to |
| (...skipping 12 matching lines...) Expand all Loading... |
| 257 StateMap state_map_; | 255 StateMap state_map_; |
| 258 | 256 |
| 259 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously | 257 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously |
| 260 // about the download. | 258 // about the download. |
| 261 base::WeakPtrFactory<DownloadRequestLimiter> factory_; | 259 base::WeakPtrFactory<DownloadRequestLimiter> factory_; |
| 262 | 260 |
| 263 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); | 261 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); |
| 264 }; | 262 }; |
| 265 | 263 |
| 266 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 264 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
| OLD | NEW |