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

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

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
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 #include "chrome/browser/download/download_request_limiter.h" 5 #include "chrome/browser/download/download_request_limiter.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "chrome/browser/download/download_request_infobar_delegate.h" 8 #include "chrome/browser/download/download_request_infobar_delegate.h"
9 #include "chrome/browser/tab_contents/tab_util.h" 9 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 184
185 DownloadRequestLimiter::DownloadStatus 185 DownloadRequestLimiter::DownloadStatus
186 DownloadRequestLimiter::GetDownloadStatus(TabContents* tab) { 186 DownloadRequestLimiter::GetDownloadStatus(TabContents* tab) {
187 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false); 187 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false);
188 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD; 188 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD;
189 } 189 }
190 190
191 void DownloadRequestLimiter::CanDownloadOnIOThread(int render_process_host_id, 191 void DownloadRequestLimiter::CanDownloadOnIOThread(int render_process_host_id,
192 int render_view_id, 192 int render_view_id,
193 int request_id,
193 Callback* callback) { 194 Callback* callback) {
194 // This is invoked on the IO thread. Schedule the task to run on the UI 195 // This is invoked on the IO thread. Schedule the task to run on the UI
195 // thread so that we can query UI state. 196 // thread so that we can query UI state.
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
197 BrowserThread::PostTask( 198 BrowserThread::PostTask(
198 BrowserThread::UI, FROM_HERE, 199 BrowserThread::UI, FROM_HERE,
199 NewRunnableMethod(this, &DownloadRequestLimiter::CanDownload, 200 NewRunnableMethod(this, &DownloadRequestLimiter::CanDownload,
200 render_process_host_id, render_view_id, callback)); 201 render_process_host_id, render_view_id, request_id,
202 callback));
201 } 203 }
202 204
203 void DownloadRequestLimiter::OnUserGesture(TabContents* tab) { 205 void DownloadRequestLimiter::OnUserGesture(TabContents* tab) {
204 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false); 206 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false);
205 if (!state) 207 if (!state)
206 return; 208 return;
207 209
208 state->OnUserGesture(); 210 state->OnUserGesture();
209 } 211 }
210 212
(...skipping 15 matching lines...) Expand all
226 return NULL; 228 return NULL;
227 229
228 TabDownloadState* state = 230 TabDownloadState* state =
229 new TabDownloadState(this, controller, originating_controller); 231 new TabDownloadState(this, controller, originating_controller);
230 state_map_[controller] = state; 232 state_map_[controller] = state;
231 return state; 233 return state;
232 } 234 }
233 235
234 void DownloadRequestLimiter::CanDownload(int render_process_host_id, 236 void DownloadRequestLimiter::CanDownload(int render_process_host_id,
235 int render_view_id, 237 int render_view_id,
238 int request_id,
236 Callback* callback) { 239 Callback* callback) {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
238 241
239 TabContents* originating_tab = 242 TabContents* originating_tab =
240 tab_util::GetTabContentsByID(render_process_host_id, render_view_id); 243 tab_util::GetTabContentsByID(render_process_host_id, render_view_id);
241 if (!originating_tab) { 244 if (!originating_tab) {
242 // The tab was closed, don't allow the download. 245 // The tab was closed, don't allow the download.
243 ScheduleNotification(callback, false); 246 ScheduleNotification(callback, false);
244 return; 247 return;
245 } 248 }
246 CanDownloadImpl(originating_tab, callback); 249 CanDownloadImpl(originating_tab, request_id, callback);
247 } 250 }
248 251
249 void DownloadRequestLimiter::CanDownloadImpl( 252 void DownloadRequestLimiter::CanDownloadImpl(
250 TabContents* originating_tab, 253 TabContents* originating_tab,
254 int request_id,
251 Callback* callback) { 255 Callback* callback) {
252 // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order 256 // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order
253 // to cancel the download operation in chrome and let the host browser 257 // to cancel the download operation in chrome and let the host browser
254 // take care of it. 258 // take care of it.
255 if (!originating_tab->CanDownload(callback->GetRequestId())) { 259 if (!originating_tab->CanDownload(request_id)) {
256 ScheduleNotification(callback, false); 260 ScheduleNotification(callback, false);
257 return; 261 return;
258 } 262 }
259 263
260 // If the tab requesting the download is a constrained popup that is not 264 // If the tab requesting the download is a constrained popup that is not
261 // shown, treat the request as if it came from the parent. 265 // shown, treat the request as if it came from the parent.
262 TabContents* effective_tab = originating_tab; 266 TabContents* effective_tab = originating_tab;
263 if (effective_tab->delegate()) { 267 if (effective_tab->delegate()) {
264 effective_tab = 268 effective_tab =
265 effective_tab->delegate()->GetConstrainingContents(effective_tab); 269 effective_tab->delegate()->GetConstrainingContents(effective_tab);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 317
314 void DownloadRequestLimiter::Remove(TabDownloadState* state) { 318 void DownloadRequestLimiter::Remove(TabDownloadState* state) {
315 DCHECK(ContainsKey(state_map_, state->controller())); 319 DCHECK(ContainsKey(state_map_, state->controller()));
316 state_map_.erase(state->controller()); 320 state_map_.erase(state->controller());
317 delete state; 321 delete state;
318 } 322 }
319 323
320 // static 324 // static
321 DownloadRequestLimiter::TestingDelegate* DownloadRequestLimiter::delegate_ = 325 DownloadRequestLimiter::TestingDelegate* DownloadRequestLimiter::delegate_ =
322 NULL; 326 NULL;
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_limiter.h ('k') | chrome/browser/download/download_request_limiter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698