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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_request_handle.cc
diff --git a/content/browser/download/download_request_handle.cc b/content/browser/download/download_request_handle.cc
index 8a46917023b20b0f809a214688cbd2cee67d2290..f5979b945ad8a0afa38a233ae426bc166f2b4c59 100644
--- a/content/browser/download/download_request_handle.cc
+++ b/content/browser/download/download_request_handle.cc
@@ -6,13 +6,9 @@
#include "base/bind.h"
#include "base/strings/stringprintf.h"
-#include "content/browser/frame_host/navigator.h"
-#include "content/browser/frame_host/render_frame_host_impl.h"
-#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/common/browser_side_navigation_policy.h"
namespace content {
@@ -23,74 +19,26 @@ DownloadRequestHandle::DownloadRequestHandle(
DownloadRequestHandle::~DownloadRequestHandle() {}
-DownloadRequestHandle::DownloadRequestHandle()
- : child_id_(-1),
- render_view_id_(-1),
- request_id_(-1),
- frame_tree_node_id_(-1) {
-}
+DownloadRequestHandle::DownloadRequestHandle() {}
DownloadRequestHandle::DownloadRequestHandle(
const base::WeakPtr<DownloadResourceHandler>& handler,
- int child_id,
- int render_view_id,
- int request_id,
- int frame_tree_node_id)
- : handler_(handler),
- child_id_(child_id),
- render_view_id_(render_view_id),
- request_id_(request_id),
- frame_tree_node_id_(frame_tree_node_id) {
+ const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter)
+ : handler_(handler), web_contents_getter_(web_contents_getter) {
DCHECK(handler_.get());
}
WebContents* DownloadRequestHandle::GetWebContents() const {
- // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the
- // WebContents.
- // TODO(davidben): This logic should be abstracted within the ResourceLoader
- // stack. https://crbug.com/376003
- if (IsBrowserSideNavigationEnabled()) {
- FrameTreeNode* frame_tree_node =
- FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
- if (frame_tree_node) {
- return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
- }
- }
-
- RenderViewHostImpl* render_view_host =
- RenderViewHostImpl::FromID(child_id_, render_view_id_);
- if (!render_view_host)
- return nullptr;
-
- return render_view_host->GetDelegate()->GetAsWebContents();
+ return web_contents_getter_.is_null() ? nullptr : web_contents_getter_.Run();
}
DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
- // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the
- // DownloadManager.
- // TODO(davidben): This logic should be abstracted within the ResourceLoader
- // stack. https://crbug.com/376003
- if (IsBrowserSideNavigationEnabled()) {
- FrameTreeNode* frame_tree_node =
- FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
- if (frame_tree_node) {
- BrowserContext* context =
- frame_tree_node->navigator()->GetController()->GetBrowserContext();
- if (context)
- return BrowserContext::GetDownloadManager(context);
- }
- }
-
- RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
- child_id_, render_view_id_);
- if (rvh == NULL)
- return NULL;
- RenderProcessHost* rph = rvh->GetProcess();
- if (rph == NULL)
- return NULL;
- BrowserContext* context = rph->GetBrowserContext();
- if (context == NULL)
- return NULL;
+ WebContents* web_contents = GetWebContents();
+ if (web_contents == nullptr)
+ return nullptr;
+ BrowserContext* context = web_contents->GetBrowserContext();
+ if (context == nullptr)
+ return nullptr;
return BrowserContext::GetDownloadManager(context);
}
@@ -112,15 +60,4 @@ void DownloadRequestHandle::CancelRequest() const {
base::Bind(&DownloadResourceHandler::CancelRequest, handler_));
}
-std::string DownloadRequestHandle::DebugString() const {
- return base::StringPrintf("{"
- " child_id = %d"
- " render_view_id = %d"
- " request_id = %d"
- "}",
- child_id_,
- render_view_id_,
- request_id_);
-}
-
} // namespace content
« 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