blob: 14f8354881ab8aa59ff51240eb9cc0a24bbc3aba [file] [log] [blame]
xingliuf61d39f2017-01-27 22:46:461// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_
6#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_
7
8#include "base/macros.h"
9#include "base/time/time.h"
xingliu6719c202017-03-18 03:45:2110#include "content/browser/byte_stream.h"
xingliuf61d39f2017-01-27 22:46:4611#include "content/common/content_export.h"
12#include "content/public/browser/download_danger_type.h"
13#include "content/public/browser/download_interrupt_reasons.h"
14
15namespace content {
xingliu468824d2017-02-28 02:59:2516
17class DownloadItemImpl;
xingliuf61d39f2017-01-27 22:46:4618class WebContents;
19
xingliu468824d2017-02-28 02:59:2520// DownloadJob lives on UI thread and subclasses implement actual download logic
21// and interact with DownloadItemImpl.
22// The base class is a friend class of DownloadItemImpl.
xingliuf61d39f2017-01-27 22:46:4623class CONTENT_EXPORT DownloadJob {
24 public:
xingliu468824d2017-02-28 02:59:2525 explicit DownloadJob(DownloadItemImpl* download_item);
xingliuf61d39f2017-01-27 22:46:4626 virtual ~DownloadJob();
27
xingliuf61d39f2017-01-27 22:46:4628 // Download operations.
xingliu468824d2017-02-28 02:59:2529 virtual void Start() = 0;
xingliuf61d39f2017-01-27 22:46:4630 virtual void Cancel(bool user_cancel) = 0;
xingliu468824d2017-02-28 02:59:2531 virtual void Pause();
32 virtual void Resume(bool resume_request);
xingliuf61d39f2017-01-27 22:46:4633
xingliu468824d2017-02-28 02:59:2534 bool is_paused() const { return is_paused_; }
xingliuf61d39f2017-01-27 22:46:4635
36 // Return the WebContents associated with the download. Usually used to
37 // associate a browser window for any UI that needs to be displayed to the
38 // user.
39 // Or return nullptr if the download is not associated with an active
40 // WebContents.
41 virtual WebContents* GetWebContents() const = 0;
42
qinmin1c18f0d2017-03-23 02:01:0743 // Returns whether the download uses parallel requests.
44 virtual bool UsesParallelRequests() const;
45
xingliuf61d39f2017-01-27 22:46:4646 protected:
xingliu468824d2017-02-28 02:59:2547 void StartDownload() const;
xingliu391c49d742017-03-21 19:47:3748 void Interrupt(DownloadInterruptReason reason);
xingliuf61d39f2017-01-27 22:46:4649
xingliu6719c202017-03-18 03:45:2150 // Add a byte stream to the download sink.
51 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
52 int64_t offset,
53 int64_t length);
54
xingliu468824d2017-02-28 02:59:2555 DownloadItemImpl* download_item_;
xingliuf61d39f2017-01-27 22:46:4656
57 private:
xingliu468824d2017-02-28 02:59:2558 // If the download progress is paused by the user.
59 bool is_paused_;
60
xingliuf61d39f2017-01-27 22:46:4661 DISALLOW_COPY_AND_ASSIGN(DownloadJob);
62};
63
64} // namespace content
65
66#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_