Chromium Code Reviews

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: Replace typedef with using Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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...)
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 if (ResourceDispatcherHostImpl::Get()->is_shutdown())
294 render_view_routing_id, render_frame_routing_id, context); 302 return;
Randy Smith (Not in Mondays) 2016/08/18 17:38:57 Save question as previous--can this be lowered int
ananta 2016/08/18 22:27:09 Done.
303
304 const net::URLRequestContext* request_context = context->GetRequestContext();
305 bool known_proto = request_context->job_factory()->IsHandledURL(url);
306 if (!known_proto) {
307 // Since any URLs which have non-standard scheme have been filtered
308 // by save manager(see GURL::SchemeIsStandard). This situation
309 // should not happen.
310 NOTREACHED();
311 return;
312 }
313
314 std::unique_ptr<net::URLRequest> request(
315 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
316 request->set_method("GET");
317
318 // So far, for saving page, we need fetch content from cache, in the
319 // future, maybe we can use a configuration to configure this behavior.
320 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE);
321
322 // Since we're just saving some resources we need, disallow downloading.
323 ResourceRequestInfoImpl* extra_info =
324 ResourceDispatcherHostImpl::Get()->CreateRequestInfo(
325 render_process_host_id, render_view_routing_id,
326 render_frame_routing_id, false, context);
327 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
Randy Smith (Not in Mondays) 2016/08/18 17:38:57 Same question as elsewhere: Can we pass this into
ananta 2016/08/18 22:27:09 Done.
328
329 // Check if the renderer is permitted to request the requested URL.
330 using AuthorizationState = SaveFileResourceHandler::AuthorizationState;
331 AuthorizationState authorization_state = AuthorizationState::AUTHORIZED;
332 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
333 render_process_host_id, url)) {
334 DVLOG(1) << "Denying unauthorized save of " << url.possibly_invalid_spec();
335 authorization_state = AuthorizationState::NOT_AUTHORIZED;
336 // No need to return here (i.e. okay to begin processing the request below),
337 // because NOT_AUTHORIZED will cause the request to be cancelled. See also
338 // doc comments for AuthorizationState enum.
339 }
340
341 std::unique_ptr<SaveFileResourceHandler> handler(new SaveFileResourceHandler(
342 request.get(), save_item_id, save_package_id, render_process_host_id,
343 render_frame_routing_id, url, authorization_state));
344
345 ResourceDispatcherHostImpl::Get()->BeginURLRequest(std::move(request),
346 referrer,
347 std::move(handler));
295 } 348 }
296 349
297 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, 350 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id,
298 int request_id) { 351 int request_id) {
299 DCHECK_CURRENTLY_ON(BrowserThread::IO); 352 DCHECK_CURRENTLY_ON(BrowserThread::IO);
300 ResourceDispatcherHostImpl::Get()->CancelRequest( 353 ResourceDispatcherHostImpl::Get()->CancelRequest(
301 render_process_id, request_id); 354 render_process_id, request_id);
302 } 355 }
303 356
304 // Notifications sent from the UI thread and run on the file thread. 357 // Notifications sent from the UI thread and run on the file thread.
(...skipping 93 matching lines...)
398 SaveFile* save_file = it->second; 451 SaveFile* save_file = it->second;
399 DCHECK(!save_file->InProgress()); 452 DCHECK(!save_file->InProgress());
400 base::DeleteFile(save_file->FullPath(), false); 453 base::DeleteFile(save_file->FullPath(), false);
401 delete save_file; 454 delete save_file;
402 save_file_map_.erase(it); 455 save_file_map_.erase(it);
403 } 456 }
404 } 457 }
405 } 458 }
406 459
407 } // namespace content 460 } // namespace content
OLDNEW

Powered by Google App Engine