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

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

Issue 1229933010: move file access permission logic to DownloadResourceThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 5 months 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>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
230 const Callback& orig_callback, 221 const Callback& orig_callback,
231 bool allow); 222 bool allow);
232 223
233 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io
234 // thread.
235 void ScheduleNotification(const Callback& callback, bool allow);
236
237 // Removes the specified TabDownloadState from the internal map and deletes 224 // Removes the specified TabDownloadState from the internal map and deletes
238 // 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
239 // ALLOW_ONE_DOWNLOAD. 226 // ALLOW_ONE_DOWNLOAD.
240 void Remove(TabDownloadState* state, content::WebContents* contents); 227 void Remove(TabDownloadState* state, content::WebContents* contents);
241 228
242 static HostContentSettingsMap* content_settings_; 229 static HostContentSettingsMap* content_settings_;
243 static HostContentSettingsMap* GetContentSettings( 230 static HostContentSettingsMap* GetContentSettings(
244 content::WebContents* contents); 231 content::WebContents* contents);
245 232
246 // 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
247 // 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
248 // 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
249 // the TabDownloadState is removed and deleted (by way of Remove). 236 // the TabDownloadState is removed and deleted (by way of Remove).
250 typedef std::map<content::WebContents*, TabDownloadState*> StateMap; 237 typedef std::map<content::WebContents*, TabDownloadState*> StateMap;
251 StateMap state_map_; 238 StateMap state_map_;
252 239
253 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously 240 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously
254 // about the download. 241 // about the download.
255 base::WeakPtrFactory<DownloadRequestLimiter> factory_; 242 base::WeakPtrFactory<DownloadRequestLimiter> factory_;
256 243
257 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); 244 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter);
258 }; 245 };
259 246
260 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 247 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698