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

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

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, 9 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
7 7
8 #include <string>
9
10 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
12 #include "content/browser/download/download_resource_handler.h" 10 #include "content/browser/download/download_resource_handler.h"
13 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
12 #include "content/public/browser/resource_request_info.h"
14 13
15 namespace content { 14 namespace content {
16 class DownloadManager; 15 class DownloadManager;
17 class WebContents; 16 class WebContents;
18 17
19 // A handle used by the download system for operations on the URLRequest 18 // A handle used by the download system for operations on the URLRequest
20 // or objects conditional on it (e.g. WebContentsImpl). 19 // or objects conditional on it (e.g. WebContentsImpl).
21 // This class needs to be copyable, so we can pass it across threads and not 20 // This class needs to be copyable, so we can pass it across threads and not
22 // worry about lifetime or const-ness. 21 // worry about lifetime or const-ness.
23 // 22 //
24 // DownloadRequestHandleInterface is defined for mocking purposes. 23 // DownloadRequestHandleInterface is defined for mocking purposes.
25 class CONTENT_EXPORT DownloadRequestHandleInterface { 24 class CONTENT_EXPORT DownloadRequestHandleInterface {
26 public: 25 public:
27 virtual ~DownloadRequestHandleInterface(); 26 virtual ~DownloadRequestHandleInterface();
28 27
29 // These functions must be called on the UI thread. 28 // These functions must be called on the UI thread.
30 virtual WebContents* GetWebContents() const = 0; 29 virtual WebContents* GetWebContents() const = 0;
31 virtual DownloadManager* GetDownloadManager() const = 0; 30 virtual DownloadManager* GetDownloadManager() const = 0;
32 31
33 // Pauses or resumes the matching URL request. 32 // Pauses or resumes the matching URL request.
34 virtual void PauseRequest() const = 0; 33 virtual void PauseRequest() const = 0;
35 virtual void ResumeRequest() const = 0; 34 virtual void ResumeRequest() const = 0;
36 35
37 // Cancels the request. 36 // Cancels the request.
38 virtual void CancelRequest() const = 0; 37 virtual void CancelRequest() const = 0;
39
40 // Describes the object.
41 virtual std::string DebugString() const = 0;
42 }; 38 };
43 39
44 40
45 class CONTENT_EXPORT DownloadRequestHandle 41 class CONTENT_EXPORT DownloadRequestHandle
46 : public DownloadRequestHandleInterface { 42 : public DownloadRequestHandleInterface {
47 public: 43 public:
48 DownloadRequestHandle(const DownloadRequestHandle& other); 44 DownloadRequestHandle(const DownloadRequestHandle& other);
49 ~DownloadRequestHandle() override; 45 ~DownloadRequestHandle() override;
50 46
51 // Create a null DownloadRequestHandle: getters will return null, and 47 // Create a null DownloadRequestHandle: getters will return null, and
52 // all actions are no-ops. 48 // all actions are no-ops.
53 // TODO(rdsmith): Ideally, actions would be forbidden rather than 49 // TODO(rdsmith): Ideally, actions would be forbidden rather than
54 // no-ops, to confirm that no non-testing code actually uses 50 // no-ops, to confirm that no non-testing code actually uses
55 // a null DownloadRequestHandle. But for now, we need the no-op 51 // a null DownloadRequestHandle. But for now, we need the no-op
56 // behavior for unit tests. Long-term, this should be fixed by 52 // behavior for unit tests. Long-term, this should be fixed by
57 // allowing mocking of ResourceDispatcherHost in unit tests. 53 // allowing mocking of ResourceDispatcherHost in unit tests.
58 DownloadRequestHandle(); 54 DownloadRequestHandle();
59 55
60 // Note that |rdh| is required to be non-null.
61 DownloadRequestHandle(const base::WeakPtr<DownloadResourceHandler>& handler, 56 DownloadRequestHandle(const base::WeakPtr<DownloadResourceHandler>& handler,
62 int child_id, 57 const content::ResourceRequestInfo::WebContentsGetter&
63 int render_view_id, 58 web_contents_getter);
64 int request_id,
65 int frame_tree_node_id);
66 59
67 // Implement DownloadRequestHandleInterface interface. 60 // Implement DownloadRequestHandleInterface interface.
68 WebContents* GetWebContents() const override; 61 WebContents* GetWebContents() const override;
69 DownloadManager* GetDownloadManager() const override; 62 DownloadManager* GetDownloadManager() const override;
70 void PauseRequest() const override; 63 void PauseRequest() const override;
71 void ResumeRequest() const override; 64 void ResumeRequest() const override;
72 void CancelRequest() const override; 65 void CancelRequest() const override;
73 std::string DebugString() const override;
74 66
75 private: 67 private:
76 base::WeakPtr<DownloadResourceHandler> handler_; 68 base::WeakPtr<DownloadResourceHandler> handler_;
77 69 content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
78 // The ID of the child process that started the download.
79 int child_id_;
80
81 // The ID of the render view that started the download.
82 int render_view_id_;
83
84 // The ID associated with the request used for the download.
85 int request_id_;
86
87 // PlzNavigate
88 // The ID of the FrameTreeNode that started the download.
89 int frame_tree_node_id_;
90 }; 70 };
91 71
92 } // namespace content 72 } // namespace content
93 73
94 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ 74 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_create_info.cc ('k') | content/browser/download/download_request_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698