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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Check if download can proceed and notifies the callback on UI thread. | 184 // Check if download can proceed and notifies the callback on UI thread. |
185 void CanDownload(int render_process_host_id, | 185 void CanDownload( |
186 int render_view_id, | 186 const base::Callback<content::WebContents*(void)>& web_contents_getter, |
asanka
2015/11/24 16:13:19
Instead of a bunch of naked base::Callback<>s, cou
clamy
2015/11/25 14:02:02
I went back to having a typedef in ResourceRequest
| |
187 const GURL& url, | 187 const GURL& url, |
188 const std::string& request_method, | 188 const std::string& request_method, |
189 const Callback& callback); | 189 const Callback& callback); |
190 | 190 |
191 private: | 191 private: |
192 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); | 192 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); |
193 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; | 193 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; |
194 friend class DownloadRequestLimiterTest; | 194 friend class DownloadRequestLimiterTest; |
195 friend class TabDownloadState; | 195 friend class TabDownloadState; |
196 | 196 |
197 ~DownloadRequestLimiter(); | 197 ~DownloadRequestLimiter(); |
198 | 198 |
199 // Gets the download state for the specified controller. If the | 199 // Gets the download state for the specified controller. If the |
200 // TabDownloadState does not exist and |create| is true, one is created. | 200 // TabDownloadState does not exist and |create| is true, one is created. |
201 // See TabDownloadState's constructor description for details on the two | 201 // See TabDownloadState's constructor description for details on the two |
202 // controllers. | 202 // controllers. |
203 // | 203 // |
204 // The returned TabDownloadState is owned by the DownloadRequestLimiter and | 204 // The returned TabDownloadState is owned by the DownloadRequestLimiter and |
205 // deleted when no longer needed (the Remove method is invoked). | 205 // deleted when no longer needed (the Remove method is invoked). |
206 TabDownloadState* GetDownloadState( | 206 TabDownloadState* GetDownloadState( |
207 content::WebContents* web_contents, | 207 content::WebContents* web_contents, |
208 content::WebContents* originating_web_contents, | 208 content::WebContents* originating_web_contents, |
209 bool create); | 209 bool create); |
210 | 210 |
211 // 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 |
212 // potentially prompting the user. | 212 // potentially prompting the user. |
213 void CanDownloadImpl(content::WebContents* originating_contents, | 213 void CanDownloadImpl(content::WebContents* originating_contents, |
214 const std::string& request_method, | 214 const std::string& request_method, |
215 const Callback& callback); | 215 const Callback& callback); |
216 | 216 |
217 // Invoked when decision to download has been made. | 217 // Invoked when decision to download has been made. |
218 void OnCanDownloadDecided(int render_process_host_id, | 218 void OnCanDownloadDecided( |
219 int render_view_id, | 219 const base::Callback<content::WebContents*(void)>& web_contents_getter, |
220 const std::string& request_method, | 220 const std::string& request_method, |
221 const Callback& orig_callback, | 221 const Callback& orig_callback, |
222 bool allow); | 222 bool allow); |
223 | 223 |
224 // Removes the specified TabDownloadState from the internal map and deletes | 224 // Removes the specified TabDownloadState from the internal map and deletes |
225 // it. This has the effect of resetting the status for the tab to | 225 // it. This has the effect of resetting the status for the tab to |
226 // ALLOW_ONE_DOWNLOAD. | 226 // ALLOW_ONE_DOWNLOAD. |
227 void Remove(TabDownloadState* state, content::WebContents* contents); | 227 void Remove(TabDownloadState* state, content::WebContents* contents); |
228 | 228 |
229 static HostContentSettingsMap* content_settings_; | 229 static HostContentSettingsMap* content_settings_; |
230 static HostContentSettingsMap* GetContentSettings( | 230 static HostContentSettingsMap* GetContentSettings( |
231 content::WebContents* contents); | 231 content::WebContents* contents); |
232 | 232 |
233 // Maps from tab to download state. The download state for a tab only exists | 233 // Maps from tab to download state. The download state for a tab only exists |
234 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state | 234 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state |
235 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD | 235 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD |
236 // the TabDownloadState is removed and deleted (by way of Remove). | 236 // the TabDownloadState is removed and deleted (by way of Remove). |
237 typedef std::map<content::WebContents*, TabDownloadState*> StateMap; | 237 typedef std::map<content::WebContents*, TabDownloadState*> StateMap; |
238 StateMap state_map_; | 238 StateMap state_map_; |
239 | 239 |
240 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously | 240 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously |
241 // about the download. | 241 // about the download. |
242 base::WeakPtrFactory<DownloadRequestLimiter> factory_; | 242 base::WeakPtrFactory<DownloadRequestLimiter> factory_; |
243 | 243 |
244 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); | 244 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); |
245 }; | 245 }; |
246 | 246 |
247 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 247 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
OLD | NEW |