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

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

Issue 1728583002: Simplify DownloadRequestHandle by using WebContentsGetter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: default callback constructor Created 4 years, 10 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_request_handle.h" 5 #include "content/browser/download/download_request_handle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/browser/frame_host/navigator.h"
10 #include "content/browser/frame_host/render_frame_host_impl.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
15 #include "content/public/common/browser_side_navigation_policy.h"
16 12
17 namespace content { 13 namespace content {
18 14
19 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {} 15 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {}
20 16
21 DownloadRequestHandle::DownloadRequestHandle( 17 DownloadRequestHandle::DownloadRequestHandle(
22 const DownloadRequestHandle& other) = default; 18 const DownloadRequestHandle& other) = default;
23 19
24 DownloadRequestHandle::~DownloadRequestHandle() {} 20 DownloadRequestHandle::~DownloadRequestHandle() {}
25 21
26 DownloadRequestHandle::DownloadRequestHandle() 22 DownloadRequestHandle::DownloadRequestHandle() {}
27 : child_id_(-1),
28 render_view_id_(-1),
29 request_id_(-1),
30 frame_tree_node_id_(-1) {
31 }
32 23
33 DownloadRequestHandle::DownloadRequestHandle( 24 DownloadRequestHandle::DownloadRequestHandle(
34 const base::WeakPtr<DownloadResourceHandler>& handler, 25 const base::WeakPtr<DownloadResourceHandler>& handler,
35 int child_id, 26 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter)
36 int render_view_id, 27 : handler_(handler), web_contents_getter_(web_contents_getter) {
37 int request_id,
38 int frame_tree_node_id)
39 : handler_(handler),
40 child_id_(child_id),
41 render_view_id_(render_view_id),
42 request_id_(request_id),
43 frame_tree_node_id_(frame_tree_node_id) {
44 DCHECK(handler_.get()); 28 DCHECK(handler_.get());
45 } 29 }
46 30
47 WebContents* DownloadRequestHandle::GetWebContents() const { 31 WebContents* DownloadRequestHandle::GetWebContents() const {
48 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the 32 return web_contents_getter_.is_null() ? nullptr : web_contents_getter_.Run();
49 // WebContents.
50 // TODO(davidben): This logic should be abstracted within the ResourceLoader
51 // stack. https://crbug.com/376003
52 if (IsBrowserSideNavigationEnabled()) {
53 FrameTreeNode* frame_tree_node =
54 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
55 if (frame_tree_node) {
56 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
57 }
58 }
59
60 RenderViewHostImpl* render_view_host =
61 RenderViewHostImpl::FromID(child_id_, render_view_id_);
62 if (!render_view_host)
63 return nullptr;
64
65 return render_view_host->GetDelegate()->GetAsWebContents();
66 } 33 }
67 34
68 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { 35 DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
69 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the 36 WebContents* web_contents = GetWebContents();
70 // DownloadManager. 37 if (web_contents == nullptr)
71 // TODO(davidben): This logic should be abstracted within the ResourceLoader 38 return nullptr;
72 // stack. https://crbug.com/376003 39 BrowserContext* context = web_contents->GetBrowserContext();
73 if (IsBrowserSideNavigationEnabled()) { 40 if (context == nullptr)
74 FrameTreeNode* frame_tree_node = 41 return nullptr;
75 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
76 if (frame_tree_node) {
77 BrowserContext* context =
78 frame_tree_node->navigator()->GetController()->GetBrowserContext();
79 if (context)
80 return BrowserContext::GetDownloadManager(context);
81 }
82 }
83
84 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
85 child_id_, render_view_id_);
86 if (rvh == NULL)
87 return NULL;
88 RenderProcessHost* rph = rvh->GetProcess();
89 if (rph == NULL)
90 return NULL;
91 BrowserContext* context = rph->GetBrowserContext();
92 if (context == NULL)
93 return NULL;
94 return BrowserContext::GetDownloadManager(context); 42 return BrowserContext::GetDownloadManager(context);
95 } 43 }
96 44
97 void DownloadRequestHandle::PauseRequest() const { 45 void DownloadRequestHandle::PauseRequest() const {
98 BrowserThread::PostTask( 46 BrowserThread::PostTask(
99 BrowserThread::IO, FROM_HERE, 47 BrowserThread::IO, FROM_HERE,
100 base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); 48 base::Bind(&DownloadResourceHandler::PauseRequest, handler_));
101 } 49 }
102 50
103 void DownloadRequestHandle::ResumeRequest() const { 51 void DownloadRequestHandle::ResumeRequest() const {
104 BrowserThread::PostTask( 52 BrowserThread::PostTask(
105 BrowserThread::IO, FROM_HERE, 53 BrowserThread::IO, FROM_HERE,
106 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); 54 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_));
107 } 55 }
108 56
109 void DownloadRequestHandle::CancelRequest() const { 57 void DownloadRequestHandle::CancelRequest() const {
110 BrowserThread::PostTask( 58 BrowserThread::PostTask(
111 BrowserThread::IO, FROM_HERE, 59 BrowserThread::IO, FROM_HERE,
112 base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); 60 base::Bind(&DownloadResourceHandler::CancelRequest, handler_));
113 } 61 }
114 62
115 std::string DownloadRequestHandle::DebugString() const {
116 return base::StringPrintf("{"
117 " child_id = %d"
118 " render_view_id = %d"
119 " request_id = %d"
120 "}",
121 child_id_,
122 render_view_id_,
123 request_id_);
124 }
125
126 } // namespace content 63 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_request_handle.h ('k') | content/browser/download/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698