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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: nits. Created 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_URL_DOWNLOADER_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/download/download_request_core.h" 13 #include "content/browser/download/download_request_core.h"
14 #include "content/public/browser/download_interrupt_reasons.h" 14 #include "content/public/browser/download_interrupt_reasons.h"
15 #include "content/public/browser/download_save_info.h" 15 #include "content/public/browser/download_save_info.h"
16 #include "content/public/browser/download_url_parameters.h" 16 #include "content/public/browser/download_url_parameters.h"
17 #include "content/public/common/referrer.h" 17 #include "content/public/common/referrer.h"
18 #include "net/url_request/redirect_info.h" 18 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
20 20
21 namespace content { 21 namespace content {
22 class ByteStreamReader; 22 class ByteStreamReader;
23 struct DownloadCreateInfo; 23 struct DownloadCreateInfo;
24 class DownloadManagerImpl;
25 24
26 class UrlDownloader : public net::URLRequest::Delegate, 25 class UrlDownloader : public net::URLRequest::Delegate,
27 public DownloadRequestCore::Delegate { 26 public DownloadRequestCore::Delegate {
28 public: 27 public:
28 // Implemented by the owner of UrlDownloader, functions need to be called on
29 // UI thread.
30 class Delegate {
31 public:
32 // Called after response is handled and the byte stream is established.
33 virtual void OnUrlDownloaderStarted(
34 std::unique_ptr<DownloadCreateInfo> download_create_info,
35 std::unique_ptr<ByteStreamReader> stream_reader,
36 const DownloadUrlParameters::OnStartedCallback& callback) = 0;
37
38 // Called after the connection is cannceled or finished.
39 virtual void OnUrlDownloaderStopped(UrlDownloader* downloader) = 0;
40 };
41
29 UrlDownloader(std::unique_ptr<net::URLRequest> request, 42 UrlDownloader(std::unique_ptr<net::URLRequest> request,
30 base::WeakPtr<DownloadManagerImpl> manager); 43 base::WeakPtr<Delegate> delegate);
31 ~UrlDownloader() override; 44 ~UrlDownloader() override;
32 45
33 static std::unique_ptr<UrlDownloader> BeginDownload( 46 static std::unique_ptr<UrlDownloader> BeginDownload(
34 base::WeakPtr<DownloadManagerImpl> download_manager, 47 base::WeakPtr<UrlDownloader::Delegate> delegate,
35 std::unique_ptr<net::URLRequest> request, 48 std::unique_ptr<net::URLRequest> request,
36 const Referrer& referrer); 49 const Referrer& referrer);
37 50
38 private: 51 private:
39 class RequestHandle; 52 class RequestHandle;
40 53
41 void Start(); 54 void Start();
42 55
43 // URLRequest::Delegate: 56 // URLRequest::Delegate:
44 void OnReceivedRedirect(net::URLRequest* request, 57 void OnReceivedRedirect(net::URLRequest* request,
(...skipping 15 matching lines...) Expand all
60 void PauseRequest(); 73 void PauseRequest();
61 void ResumeRequest(); 74 void ResumeRequest();
62 void CancelRequest(); 75 void CancelRequest();
63 76
64 // Called when the UrlDownloader is done with the request. Posts a task to 77 // Called when the UrlDownloader is done with the request. Posts a task to
65 // remove itself from its download manager, which in turn would cause the 78 // remove itself from its download manager, which in turn would cause the
66 // UrlDownloader to be freed. 79 // UrlDownloader to be freed.
67 void Destroy(); 80 void Destroy();
68 81
69 std::unique_ptr<net::URLRequest> request_; 82 std::unique_ptr<net::URLRequest> request_;
70 base::WeakPtr<DownloadManagerImpl> manager_; 83
84 // Live on UI thread, post task to call |delegate_| functions.
85 base::WeakPtr<Delegate> delegate_;
71 DownloadRequestCore core_; 86 DownloadRequestCore core_;
72 87
73 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_; 88 base::WeakPtrFactory<UrlDownloader> weak_ptr_factory_;
74 }; 89 };
75 90
76 } // namespace content 91 } // namespace content
77 92
78 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_ 93 #endif // CONTENT_BROWSER_DOWNLOAD_URL_DOWNLOADER_H_
OLDNEW
« no previous file with comments | « content/browser/download/parallel_download_job_unittest.cc ('k') | content/browser/download/url_downloader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698