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

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

Issue 10412061: Fix crashes in DownloadRequestLimiter when extension popups/bubbles initiate downloads automatically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 8 years, 7 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
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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 18
19 class DownloadRequestInfoBarDelegate; 19 class DownloadRequestInfoBarDelegate;
20 class DownloadRequestLimiterObserver;
20 class TabContentsWrapper; 21 class TabContentsWrapper;
21 22
22 namespace content { 23 namespace content {
23 class NavigationController; 24 class NavigationController;
24 class WebContents; 25 class WebContents;
25 } 26 }
26 27
27 // DownloadRequestLimiter is responsible for determining whether a download 28 // DownloadRequestLimiter is responsible for determining whether a download
28 // should be allowed or not. It is designed to keep pages from downloading 29 // should be allowed or not. It is designed to keep pages from downloading
29 // multiple files without user interaction. DownloadRequestLimiter is invoked 30 // multiple files without user interaction. DownloadRequestLimiter is invoked
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // CanDownloadOnIOThread invokes this on the UI thread. This determines the 218 // CanDownloadOnIOThread invokes this on the UI thread. This determines the
218 // tab and invokes CanDownloadImpl. 219 // tab and invokes CanDownloadImpl.
219 void CanDownload(int render_process_host_id, 220 void CanDownload(int render_process_host_id,
220 int render_view_id, 221 int render_view_id,
221 int request_id, 222 int request_id,
222 const std::string& request_method, 223 const std::string& request_method,
223 const Callback& callback); 224 const Callback& callback);
224 225
225 // Does the work of updating the download status on the UI thread and 226 // Does the work of updating the download status on the UI thread and
226 // potentially prompting the user. 227 // potentially prompting the user.
227 void CanDownloadImpl(TabContentsWrapper* originating_tab, 228 void CanDownloadImpl(content::WebContents* originating_contents,
228 int request_id, 229 int request_id,
229 const std::string& request_method, 230 const std::string& request_method,
230 const Callback& callback); 231 const Callback& callback);
231 232
232 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io 233 // Invoked on the UI thread. Schedules a call to NotifyCallback on the io
233 // thread. 234 // thread.
234 void ScheduleNotification(const Callback& callback, bool allow); 235 void ScheduleNotification(const Callback& callback, bool allow);
235 236
236 // Removes the specified TabDownloadState from the internal map and deletes 237 // Removes the specified TabDownloadState from the internal map and deletes
237 // 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
238 // ALLOW_ONE_DOWNLOAD. 239 // ALLOW_ONE_DOWNLOAD.
239 void Remove(TabDownloadState* state); 240 void Remove(TabDownloadState* state);
240 241
242 void RemoveObserver(content::WebContents* web_contents,
243 DownloadRequestLimiterObserver* observer);
244
241 // Maps from tab to download state. The download state for a tab only exists 245 // Maps from tab to download state. The download state for a tab only exists
242 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state 246 // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state
243 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD 247 // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD
244 // the TabDownloadState is removed and deleted (by way of Remove). 248 // the TabDownloadState is removed and deleted (by way of Remove).
245 typedef std::map<content::NavigationController*, TabDownloadState*> StateMap; 249 typedef std::map<content::NavigationController*, TabDownloadState*> StateMap;
246 StateMap state_map_; 250 StateMap state_map_;
247 251
252 typedef std::map<content::WebContents*, DownloadRequestLimiterObserver*>
253 ObserverMap;
254 ObserverMap observer_map_;
255
248 static TestingDelegate* delegate_; 256 static TestingDelegate* delegate_;
249 257
250 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); 258 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter);
251 }; 259 };
252 260
253 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ 261 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698