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

Side by Side Diff: content/browser/download/download_resource_handler.cc

Issue 2251643003: Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize tab_info_ in OnStart instead of OnResponseStart because we need a central place where al… Created 4 years, 4 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 #include "content/browser/download/download_resource_handler.h" 5 #include "content/browser/download/download_resource_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 void DeleteOnUIThread( 100 void DeleteOnUIThread(
101 std::unique_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info) {} 101 std::unique_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info) {}
102 102
103 } // namespace 103 } // namespace
104 104
105 DownloadResourceHandler::DownloadResourceHandler(net::URLRequest* request) 105 DownloadResourceHandler::DownloadResourceHandler(net::URLRequest* request)
106 : ResourceHandler(request), 106 : ResourceHandler(request),
107 tab_info_(new DownloadTabInfo()), 107 tab_info_(new DownloadTabInfo()),
108 core_(request, this) { 108 core_(request, this) {
109 // Do UI thread initialization for tab_info_ asap after
110 // DownloadResourceHandler creation since the tab could be navigated
111 // before StartOnUIThread gets called. This is safe because deletion
112 // will occur via PostTask() as well, which will serialized behind this
113 // PostTask()
114 const ResourceRequestInfoImpl* request_info = GetRequestInfo();
115 BrowserThread::PostTask(
116 BrowserThread::UI, FROM_HERE,
117 base::Bind(
118 &InitializeDownloadTabInfoOnUIThread,
119 DownloadRequestHandle(AsWeakPtr(),
120 request_info->GetWebContentsGetterForRequest()),
121 tab_info_.get()));
122 } 109 }
123 110
124 DownloadResourceHandler::~DownloadResourceHandler() { 111 DownloadResourceHandler::~DownloadResourceHandler() {
125 if (tab_info_) { 112 if (tab_info_) {
126 BrowserThread::PostTask( 113 BrowserThread::PostTask(
127 BrowserThread::UI, FROM_HERE, 114 BrowserThread::UI, FROM_HERE,
128 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); 115 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_)));
129 } 116 }
130 } 117 }
131 118
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (create_info->result == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED && 177 if (create_info->result == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED &&
191 create_info->download_id == DownloadItem::kInvalidId) { 178 create_info->download_id == DownloadItem::kInvalidId) {
192 if (!callback.is_null()) 179 if (!callback.is_null())
193 BrowserThread::PostTask( 180 BrowserThread::PostTask(
194 BrowserThread::UI, FROM_HERE, 181 BrowserThread::UI, FROM_HERE,
195 base::Bind(callback, nullptr, create_info->result)); 182 base::Bind(callback, nullptr, create_info->result));
196 return; 183 return;
197 } 184 }
198 185
199 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); 186 const ResourceRequestInfoImpl* request_info = GetRequestInfo();
187 // Post the task (InitializeDownloadTabInfoOnUIThread) to initialize the
188 // tab_info_ structure on the UI thread before posting the StartOnUIThread()
189 // task. The tab could be navigated away before either of these tasks run,
190 // which is safe because the deletion of the tab_info_ structure also occurs
191 // on the UI thread via PostTask() which will be serialized behind these
192 // tasks.
Randy Smith (Not in Mondays) 2016/08/21 23:32:57 I'm sorry, I don't understand what drove moving th
ananta 2016/08/22 19:14:57 The ResourceRequestInfoImpl instance which is asso
Randy Smith (Not in Mondays) 2016/08/23 19:54:45 So the code is squirrelly, so I may be mistaken, b
193 BrowserThread::PostTask(
194 BrowserThread::UI, FROM_HERE,
195 base::Bind(
196 &InitializeDownloadTabInfoOnUIThread,
197 DownloadRequestHandle(
198 AsWeakPtr(), request_info->GetWebContentsGetterForRequest()),
199 tab_info_.get()));
200
200 create_info->has_user_gesture = request_info->HasUserGesture(); 201 create_info->has_user_gesture = request_info->HasUserGesture();
201 create_info->transition_type = request_info->GetPageTransition(); 202 create_info->transition_type = request_info->GetPageTransition();
202 203
203 create_info->request_handle.reset(new DownloadRequestHandle( 204 create_info->request_handle.reset(new DownloadRequestHandle(
204 AsWeakPtr(), request_info->GetWebContentsGetterForRequest())); 205 AsWeakPtr(), request_info->GetWebContentsGetterForRequest()));
205 206
206 int render_process_id = -1; 207 int render_process_id = -1;
207 int render_frame_id = -1; 208 int render_frame_id = -1;
208 request_info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id); 209 request_info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id);
209 210
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 " }", 243 " }",
243 request() ? 244 request() ?
244 request()->url().spec().c_str() : 245 request()->url().spec().c_str() :
245 "<NULL request>", 246 "<NULL request>",
246 info->GetChildID(), 247 info->GetChildID(),
247 info->GetRequestID(), 248 info->GetRequestID(),
248 info->GetRouteID()); 249 info->GetRouteID());
249 } 250 }
250 251
251 } // namespace content 252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698