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

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

Issue 2251643003: Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix browser test redness by ensuring that the ResourceDispatcherHostDelegate is notified in CreateR… 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "content/browser/download/save_file_manager.h" 7 #include "content/browser/download/save_file_manager.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "content/browser/child_process_security_policy_impl.h"
15 #include "content/browser/download/save_file.h" 16 #include "content/browser/download/save_file.h"
17 #include "content/browser/download/save_file_resource_handler.h"
16 #include "content/browser/download/save_package.h" 18 #include "content/browser/download/save_package.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 19 #include "content/browser/loader/resource_dispatcher_host_impl.h"
20 #include "content/browser/loader/resource_request_info_impl.h"
18 #include "content/browser/renderer_host/render_view_host_impl.h" 21 #include "content/browser/renderer_host/render_view_host_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 22 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/resource_context.h"
22 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
27 #include "net/base/load_flags.h"
28 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_job_factory.h"
23 #include "url/gurl.h" 31 #include "url/gurl.h"
24 32
25 namespace content { 33 namespace content {
26 34
27 namespace { 35 namespace {
28 36
29 // Pointer to the singleton SaveFileManager instance. 37 // Pointer to the singleton SaveFileManager instance.
30 static SaveFileManager* g_save_file_manager = nullptr; 38 static SaveFileManager* g_save_file_manager = nullptr;
31 39
32 } // namespace 40 } // namespace
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 290
283 void SaveFileManager::OnSaveURL(const GURL& url, 291 void SaveFileManager::OnSaveURL(const GURL& url,
284 const Referrer& referrer, 292 const Referrer& referrer,
285 SaveItemId save_item_id, 293 SaveItemId save_item_id,
286 SavePackageId save_package_id, 294 SavePackageId save_package_id,
287 int render_process_host_id, 295 int render_process_host_id,
288 int render_view_routing_id, 296 int render_view_routing_id,
289 int render_frame_routing_id, 297 int render_frame_routing_id,
290 ResourceContext* context) { 298 ResourceContext* context) {
291 DCHECK_CURRENTLY_ON(BrowserThread::IO); 299 DCHECK_CURRENTLY_ON(BrowserThread::IO);
292 ResourceDispatcherHostImpl::Get()->BeginSaveFile( 300
293 url, referrer, save_item_id, save_package_id, render_process_host_id, 301 const net::URLRequestContext* request_context = context->GetRequestContext();
294 render_view_routing_id, render_frame_routing_id, context); 302 bool known_proto = request_context->job_factory()->IsHandledURL(url);
303 if (!known_proto) {
svaldez 2016/08/19 17:05:14 Combine these two lines.
ananta 2016/08/19 19:02:14 Done.
304 // Since any URLs which have non-standard scheme have been filtered
305 // by save manager(see GURL::SchemeIsStandard). This situation
306 // should not happen.
307 NOTREACHED();
308 return;
309 }
310
311 std::unique_ptr<net::URLRequest> request(
312 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
313 request->set_method("GET");
314
315 // So far, for saving page, we need fetch content from cache, in the
316 // future, maybe we can use a configuration to configure this behavior.
317 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE);
318
319 // Check if the renderer is permitted to request the requested URL.
320 using AuthorizationState = SaveFileResourceHandler::AuthorizationState;
321 AuthorizationState authorization_state = AuthorizationState::AUTHORIZED;
322 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
323 render_process_host_id, url)) {
324 DVLOG(1) << "Denying unauthorized save of " << url.possibly_invalid_spec();
325 authorization_state = AuthorizationState::NOT_AUTHORIZED;
326 // No need to return here (i.e. okay to begin processing the request below),
327 // because NOT_AUTHORIZED will cause the request to be cancelled. See also
328 // doc comments for AuthorizationState enum.
329 }
330
331 std::unique_ptr<SaveFileResourceHandler> handler(new SaveFileResourceHandler(
332 request.get(), save_item_id, save_package_id, render_process_host_id,
333 render_frame_routing_id, url, authorization_state));
334
335 ResourceDispatcherHostImpl::Get()->BeginURLRequest(
336 std::move(request), std::move(handler), referrer,
337 false, // download
338 false, // content_initiated (download specific)
339 false, // do_not_prompt_for_login (download specific),
340 render_process_host_id, render_view_routing_id, render_frame_routing_id,
341 context);
295 } 342 }
296 343
297 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, 344 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id,
298 int request_id) { 345 int request_id) {
299 DCHECK_CURRENTLY_ON(BrowserThread::IO); 346 DCHECK_CURRENTLY_ON(BrowserThread::IO);
300 ResourceDispatcherHostImpl::Get()->CancelRequest( 347 ResourceDispatcherHostImpl::Get()->CancelRequest(
301 render_process_id, request_id); 348 render_process_id, request_id);
302 } 349 }
303 350
304 // Notifications sent from the UI thread and run on the file thread. 351 // Notifications sent from the UI thread and run on the file thread.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 SaveFile* save_file = it->second; 445 SaveFile* save_file = it->second;
399 DCHECK(!save_file->InProgress()); 446 DCHECK(!save_file->InProgress());
400 base::DeleteFile(save_file->FullPath(), false); 447 base::DeleteFile(save_file->FullPath(), false);
401 delete save_file; 448 delete save_file;
402 save_file_map_.erase(it); 449 save_file_map_.erase(it);
403 } 450 }
404 } 451 }
405 } 452 }
406 453
407 } // namespace content 454 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698