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

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

Issue 6713008: Don't destroy a request while it is being processed (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased. Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_request_limiter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 }; 52 };
53 53
54 // Max number of downloads before a "Prompt Before Download" Dialog is shown. 54 // Max number of downloads before a "Prompt Before Download" Dialog is shown.
55 static const size_t kMaxDownloadsAtOnce = 50; 55 static const size_t kMaxDownloadsAtOnce = 50;
56 56
57 // The callback from CanDownloadOnIOThread. This is invoked on the io thread. 57 // The callback from CanDownloadOnIOThread. This is invoked on the io thread.
58 class Callback { 58 class Callback {
59 public: 59 public:
60 virtual void ContinueDownload() = 0; 60 virtual void ContinueDownload() = 0;
61 virtual void CancelDownload() = 0; 61 virtual void CancelDownload() = 0;
62 virtual int GetRequestId() = 0;
63 62
64 protected: 63 protected:
65 virtual ~Callback() {} 64 virtual ~Callback() {}
66 }; 65 };
67 66
68 // TabDownloadState maintains the download state for a particular tab. 67 // TabDownloadState maintains the download state for a particular tab.
69 // TabDownloadState prompts the user with an infobar as necessary. 68 // TabDownloadState prompts the user with an infobar as necessary.
70 // TabDownloadState deletes itself (by invoking 69 // TabDownloadState deletes itself (by invoking
71 // DownloadRequestLimiter::Remove) as necessary. 70 // DownloadRequestLimiter::Remove) as necessary.
72 class TabDownloadState : public NotificationObserver { 71 class TabDownloadState : public NotificationObserver {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // anyway. 170 // anyway.
172 DownloadStatus GetDownloadStatus(TabContents* tab); 171 DownloadStatus GetDownloadStatus(TabContents* tab);
173 172
174 // Updates the state of the page as necessary and notifies the callback. 173 // Updates the state of the page as necessary and notifies the callback.
175 // WARNING: both this call and the callback are invoked on the io thread. 174 // WARNING: both this call and the callback are invoked on the io thread.
176 // 175 //
177 // DownloadRequestLimiter does not retain/release the Callback. It is up to 176 // DownloadRequestLimiter does not retain/release the Callback. It is up to
178 // the caller to ensure the callback is valid until the request is complete. 177 // the caller to ensure the callback is valid until the request is complete.
179 void CanDownloadOnIOThread(int render_process_host_id, 178 void CanDownloadOnIOThread(int render_process_host_id,
180 int render_view_id, 179 int render_view_id,
180 int request_id,
181 Callback* callback); 181 Callback* callback);
182 182
183 // Invoked when the user presses the mouse, enter key or space bar. This may 183 // Invoked when the user presses the mouse, enter key or space bar. This may
184 // change the download status for the page. See the class description for 184 // change the download status for the page. See the class description for
185 // details. 185 // details.
186 void OnUserGesture(TabContents* tab); 186 void OnUserGesture(TabContents* tab);
187 187
188 private: 188 private:
189 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>; 189 friend class base::RefCountedThreadSafe<DownloadRequestLimiter>;
190 friend class DownloadRequestLimiterTest; 190 friend class DownloadRequestLimiterTest;
(...skipping 20 matching lines...) Expand all
211 // deleted when no longer needed (the Remove method is invoked). 211 // deleted when no longer needed (the Remove method is invoked).
212 TabDownloadState* GetDownloadState( 212 TabDownloadState* GetDownloadState(
213 NavigationController* controller, 213 NavigationController* controller,
214 NavigationController* originating_controller, 214 NavigationController* originating_controller,
215 bool create); 215 bool create);
216 216
217 // CanDownloadOnIOThread invokes this on the UI thread. This determines the 217 // CanDownloadOnIOThread invokes this on the UI thread. This determines the
218 // tab and invokes CanDownloadImpl. 218 // tab and invokes CanDownloadImpl.
219 void CanDownload(int render_process_host_id, 219 void CanDownload(int render_process_host_id,
220 int render_view_id, 220 int render_view_id,
221 int request_id,
221 Callback* callback); 222 Callback* callback);
222 223
223 // 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
224 // potentially prompting the user. 225 // potentially prompting the user.
225 void CanDownloadImpl(TabContents* originating_tab, 226 void CanDownloadImpl(TabContents* originating_tab,
227 int request_id,
226 Callback* callback); 228 Callback* callback);
227 229
228 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io 230 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io
229 // thread. 231 // thread.
230 void ScheduleNotification(Callback* callback, bool allow); 232 void ScheduleNotification(Callback* callback, bool allow);
231 233
232 // Notifies the callback. This *must* be invoked on the IO thread. 234 // Notifies the callback. This *must* be invoked on the IO thread.
233 void NotifyCallback(Callback* callback, bool allow); 235 void NotifyCallback(Callback* callback, bool allow);
234 236
235 // Removes the specified TabDownloadState from the internal map and deletes 237 // Removes the specified TabDownloadState from the internal map and deletes
236 // it. This has the effect of resetting the status for the tab to 238 // it. This has the effect of resetting the status for the tab to
237 // ALLOW_ONE_DOWNLOAD. 239 // ALLOW_ONE_DOWNLOAD.
238 void Remove(TabDownloadState* state); 240 void Remove(TabDownloadState* state);
239 241
240 // Maps from tab to download state. The download state for a tab only exists 242 // Maps from tab to download state. The download state for a tab only exists
241 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state 243 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state
242 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD 244 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD
243 // the TabDownloadState is removed and deleted (by way of Remove). 245 // the TabDownloadState is removed and deleted (by way of Remove).
244 typedef std::map<NavigationController*, TabDownloadState*> StateMap; 246 typedef std::map<NavigationController*, TabDownloadState*> StateMap;
245 StateMap state_map_; 247 StateMap state_map_;
246 248
247 static TestingDelegate* delegate_; 249 static TestingDelegate* delegate_;
248 250
249 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); 251 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter);
250 }; 252 };
251 253
252 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 254 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_request_limiter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698