Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Side by Side Diff: chrome/browser/download/download_request_limiter.h

Issue 1467563002: Use ResourceRequestInfo::GetWebContents in DownloadRequestLimiter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-contents-callback
Patch Set: Addressed Asanka's comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "components/content_settings/core/common/content_settings.h" 16 #include "components/content_settings/core/common/content_settings.h"
17 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/resource_request_info.h"
19 #include "content/public/browser/web_contents_observer.h" 20 #include "content/public/browser/web_contents_observer.h"
20 21
21 class HostContentSettingsMap; 22 class HostContentSettingsMap;
22 class DownloadRequestInfoBarDelegateAndroid; 23 class DownloadRequestInfoBarDelegateAndroid;
23 24
24 namespace content { 25 namespace content {
25 class NavigationController; 26 class NavigationController;
26 class WebContents; 27 class WebContents;
27 } 28 }
28 29
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 176
176 static void SetContentSettingsForTesting(HostContentSettingsMap* settings); 177 static void SetContentSettingsForTesting(HostContentSettingsMap* settings);
177 178
178 DownloadRequestLimiter(); 179 DownloadRequestLimiter();
179 180
180 // Returns the download status for a page. This does not change the state in 181 // Returns the download status for a page. This does not change the state in
181 // anyway. 182 // anyway.
182 DownloadStatus GetDownloadStatus(content::WebContents* tab); 183 DownloadStatus GetDownloadStatus(content::WebContents* tab);
183 184
184 // Check if download can proceed and notifies the callback on UI thread. 185 // Check if download can proceed and notifies the callback on UI thread.
185 void CanDownload(int render_process_host_id, 186 void CanDownload(const content::ResourceRequestInfo::WebContentsGetter&
186 int render_view_id, 187 web_contents_getter,
davidben 2015/12/01 22:15:15 [Hrmf. I was going to suggest this ought to be a W
clamy 2015/12/02 09:34:00 Acknowledged.
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);
190 191
191 private: 192 private:
192 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels); 193 FRIEND_TEST_ALL_PREFIXES(DownloadTest, DownloadResourceThrottleCancels);
193 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; 194 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>;
194 friend class DownloadRequestLimiterTest; 195 friend class DownloadRequestLimiterTest;
195 friend class TabDownloadState; 196 friend class TabDownloadState;
196 197
(...skipping 11 matching lines...) Expand all
208 content::WebContents* originating_web_contents, 209 content::WebContents* originating_web_contents,
209 bool create); 210 bool create);
210 211
211 // Does the work of updating the download status on the UI thread and 212 // Does the work of updating the download status on the UI thread and
212 // potentially prompting the user. 213 // potentially prompting the user.
213 void CanDownloadImpl(content::WebContents* originating_contents, 214 void CanDownloadImpl(content::WebContents* originating_contents,
214 const std::string& request_method, 215 const std::string& request_method,
215 const Callback& callback); 216 const Callback& callback);
216 217
217 // Invoked when decision to download has been made. 218 // Invoked when decision to download has been made.
218 void OnCanDownloadDecided(int render_process_host_id, 219 void OnCanDownloadDecided(
219 int render_view_id, 220 const content::ResourceRequestInfo::WebContentsGetter&
220 const std::string& request_method, 221 web_contents_getter,
221 const Callback& orig_callback, 222 const std::string& request_method,
222 bool allow); 223 const Callback& orig_callback,
224 bool allow);
223 225
224 // Removes the specified TabDownloadState from the internal map and deletes 226 // Removes the specified TabDownloadState from the internal map and deletes
225 // it. This has the effect of resetting the status for the tab to 227 // it. This has the effect of resetting the status for the tab to
226 // ALLOW_ONE_DOWNLOAD. 228 // ALLOW_ONE_DOWNLOAD.
227 void Remove(TabDownloadState* state, content::WebContents* contents); 229 void Remove(TabDownloadState* state, content::WebContents* contents);
228 230
229 static HostContentSettingsMap* content_settings_; 231 static HostContentSettingsMap* content_settings_;
230 static HostContentSettingsMap* GetContentSettings( 232 static HostContentSettingsMap* GetContentSettings(
231 content::WebContents* contents); 233 content::WebContents* contents);
232 234
233 // Maps from tab to download state. The download state for a tab only exists 235 // 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 236 // 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 237 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD
236 // the TabDownloadState is removed and deleted (by way of Remove). 238 // the TabDownloadState is removed and deleted (by way of Remove).
237 typedef std::map<content::WebContents*, TabDownloadState*> StateMap; 239 typedef std::map<content::WebContents*, TabDownloadState*> StateMap;
238 StateMap state_map_; 240 StateMap state_map_;
239 241
240 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously 242 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously
241 // about the download. 243 // about the download.
242 base::WeakPtrFactory<DownloadRequestLimiter> factory_; 244 base::WeakPtrFactory<DownloadRequestLimiter> factory_;
243 245
244 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); 246 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter);
245 }; 247 };
246 248
247 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 249 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698