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

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

Issue 2752603002: Propagate server response error and interrupt the download. (Closed)
Patch Set: 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 there is an error caused by the server response.
29 virtual void OnServerResponseError(DownloadWorker* worker,
30 DownloadInterruptReason reason) = 0;
31 };
32
33 DownloadWorker(DownloadWorker::Delegate* delegate,
34 int64_t offset,
35 int64_t length);
27 virtual ~DownloadWorker(); 36 virtual ~DownloadWorker();
28 37
38 int64_t offset() const { return offset_; }
39 int64_t length() const { return length_; }
40
29 // Send network request to ask for a download. 41 // Send network request to ask for a download.
30 void SendRequest(std::unique_ptr<DownloadUrlParameters> params); 42 void SendRequest(std::unique_ptr<DownloadUrlParameters> params);
31 43
32 // Download operations. 44 // Download operations.
33 void Pause(); 45 void Pause();
34 void Resume(); 46 void Resume();
35 void Cancel(); 47 void Cancel();
36 48
37 private: 49 private:
38 // UrlDownloader::Delegate implementation. 50 // UrlDownloader::Delegate implementation.
39 void OnUrlDownloaderStarted( 51 void OnUrlDownloaderStarted(
40 std::unique_ptr<DownloadCreateInfo> create_info, 52 std::unique_ptr<DownloadCreateInfo> create_info,
41 std::unique_ptr<ByteStreamReader> stream_reader, 53 std::unique_ptr<ByteStreamReader> stream_reader,
42 const DownloadUrlParameters::OnStartedCallback& callback) override; 54 const DownloadUrlParameters::OnStartedCallback& callback) override;
43 void OnUrlDownloaderStopped(UrlDownloader* downloader) override; 55 void OnUrlDownloaderStopped(UrlDownloader* downloader) override;
44 56
45 void AddUrlDownloader( 57 void AddUrlDownloader(
46 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 58 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
47 downloader); 59 downloader);
48 60
61 DownloadWorker::Delegate* delegate_;
David Trainor- moved to gerrit 2017/03/14 18:01:43 DownloadWorker::Delegate* const delegate_?
xingliu 2017/03/14 21:33:21 Done.
62
63 // The starting position of the content for this worker to download.
64 int64_t offset_;
65
66 // The length of the request. May be 0 to fetch to the end of the file.
67 int64_t length_;
68
49 // Used to control the network request. Live on UI thread. 69 // Used to control the network request. Live on UI thread.
50 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; 70 std::unique_ptr<DownloadRequestHandleInterface> request_handle_;
51 71
52 // Used to handle the url request. Live and die on IO thread. 72 // Used to handle the url request. Live and die on IO thread.
53 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 73 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
54 url_downloader_; 74 url_downloader_;
55 75
56 base::WeakPtrFactory<DownloadWorker> weak_factory_; 76 base::WeakPtrFactory<DownloadWorker> weak_factory_;
57 77
58 DISALLOW_COPY_AND_ASSIGN(DownloadWorker); 78 DISALLOW_COPY_AND_ASSIGN(DownloadWorker);
59 }; 79 };
60 80
61 } // namespace content 81 } // namespace content
62 82
63 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_ 83 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_WORKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698