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

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

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Rebase, and adjust unittests with recent landed CLs. 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_WORKER_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "content/browser/byte_stream.h" 12 #include "content/browser/byte_stream.h"
13 #include "content/browser/download/download_request_handle.h" 13 #include "content/browser/download/download_request_handle.h"
14 #include "content/browser/download/url_downloader.h" 14 #include "content/browser/download/url_downloader.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/download_url_parameters.h" 16 #include "content/public/browser/download_url_parameters.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 // Helper class used to send subsequent range requests to fetch slices of the 20 // Helper class used to send subsequent range requests to fetch slices of the
21 // file after handling response of the original non-range request. 21 // file after handling response of the original non-range request.
22 // TODO(xingliu): we should consider to reuse this class for single connection 22 // TODO(xingliu): we should consider to reuse this class for single connection
23 // download. 23 // download.
24 class DownloadWorker : public UrlDownloader::Delegate { 24 class DownloadWorker : public UrlDownloader::Delegate {
25 public: 25 public:
26 DownloadWorker(); 26 class Delegate {
27 public:
28 // Called when the the byte stream is established after server response is
29 // handled. The stream contains data starts from |offset| of the
30 // destination file.
31 virtual void OnByteStreamReady(
32 DownloadWorker* worker,
33 std::unique_ptr<ByteStreamReader> stream_reader) = 0;
34 };
35
36 DownloadWorker(DownloadWorker::Delegate* delegate,
37 int64_t offset,
38 int64_t length);
27 virtual ~DownloadWorker(); 39 virtual ~DownloadWorker();
28 40
41 int64_t offset() const { return offset_; }
42 int64_t length() const { return length_; }
43
29 // Send network request to ask for a download. 44 // Send network request to ask for a download.
30 void SendRequest(std::unique_ptr<DownloadUrlParameters> params); 45 void SendRequest(std::unique_ptr<DownloadUrlParameters> params);
31 46
32 // Download operations. 47 // Download operations.
33 void Pause(); 48 void Pause();
34 void Resume(); 49 void Resume();
35 void Cancel(); 50 void Cancel();
36 51
37 private: 52 private:
38 // UrlDownloader::Delegate implementation. 53 // UrlDownloader::Delegate implementation.
39 void OnUrlDownloaderStarted( 54 void OnUrlDownloaderStarted(
40 std::unique_ptr<DownloadCreateInfo> create_info, 55 std::unique_ptr<DownloadCreateInfo> create_info,
41 std::unique_ptr<ByteStreamReader> stream_reader, 56 std::unique_ptr<ByteStreamReader> stream_reader,
42 const DownloadUrlParameters::OnStartedCallback& callback) override; 57 const DownloadUrlParameters::OnStartedCallback& callback) override;
43 void OnUrlDownloaderStopped(UrlDownloader* downloader) override; 58 void OnUrlDownloaderStopped(UrlDownloader* downloader) override;
44 59
45 void AddUrlDownloader( 60 void AddUrlDownloader(
46 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 61 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
47 downloader); 62 downloader);
48 63
64 DownloadWorker::Delegate* delegate_;
65
66 // The starting position of the content for this worker to download.
67 int64_t offset_;
68
69 // The length of the request. May be 0 to fetch to the end of the file.
70 int64_t length_;
71
49 // Used to control the network request. Live on UI thread. 72 // Used to control the network request. Live on UI thread.
50 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; 73 std::unique_ptr<DownloadRequestHandleInterface> request_handle_;
51 74
52 // Used to handle the url request. Live and die on IO thread. 75 // Used to handle the url request. Live and die on IO thread.
53 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 76 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
54 url_downloader_; 77 url_downloader_;
55 78
56 base::WeakPtrFactory<DownloadWorker> weak_factory_; 79 base::WeakPtrFactory<DownloadWorker> weak_factory_;
57 80
58 DISALLOW_COPY_AND_ASSIGN(DownloadWorker); 81 DISALLOW_COPY_AND_ASSIGN(DownloadWorker);
59 }; 82 };
60 83
61 } // namespace content 84 } // namespace content
62 85
63 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ 86 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_request_core.cc ('k') | content/browser/download/download_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698