blob: 5ba3f272e8f8348fb1906af980bfd095d28c9e28 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2021 The Chromium Authors
Evan Staded7058482021-03-25 14:47:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_BACKGROUND_FETCH_DOWNLOAD_CLIENT_H_
6#define COMPONENTS_BACKGROUND_FETCH_DOWNLOAD_CLIENT_H_
7
Avi Drissman12be0312023-01-11 09:16:098#include "base/functional/callback.h"
Keishi Hattori0e45c022021-11-27 09:25:529#include "base/memory/raw_ptr.h"
Evan Staded7058482021-03-25 14:47:5310#include "components/download/public/background_service/client.h"
11
12namespace content {
13class BrowserContext;
14} // namespace content
15
16namespace background_fetch {
17
18class BackgroundFetchDelegateBase;
19
20// A DownloadService client used by BackgroundFetch. Mostly this just forwards
21// calls to BackgroundFetchDelegateBase.
22class DownloadClient : public download::Client {
23 public:
24 // Create a client for |context|.
25 explicit DownloadClient(content::BrowserContext* context);
26 DownloadClient(const DownloadClient&) = delete;
27 DownloadClient& operator=(const DownloadClient&) = delete;
28 ~DownloadClient() override;
29
30 private:
31 BackgroundFetchDelegateBase* GetDelegate();
32
33 // download::Client:
34 void OnServiceInitialized(
35 bool state_lost,
36 const std::vector<download::DownloadMetaData>& downloads) override;
37 void OnServiceUnavailable() override;
38 void OnDownloadStarted(
39 const std::string& guid,
40 const std::vector<GURL>& url_chain,
41 const scoped_refptr<const net::HttpResponseHeaders>& headers) override;
42 void OnDownloadUpdated(const std::string& guid,
43 uint64_t bytes_uploaded,
44 uint64_t bytes_downloaded) override;
45 void OnDownloadFailed(const std::string& guid,
46 const download::CompletionInfo& info,
47 download::Client::FailureReason reason) override;
48 void OnDownloadSucceeded(const std::string& guid,
49 const download::CompletionInfo& info) override;
50 bool CanServiceRemoveDownloadedFile(const std::string& guid,
51 bool force_delete) override;
52 void GetUploadData(const std::string& guid,
53 download::GetUploadDataCallback callback) override;
54
Keishi Hattori0e45c022021-11-27 09:25:5255 raw_ptr<content::BrowserContext> browser_context_;
Evan Staded7058482021-03-25 14:47:5356};
57
58} // namespace background_fetch
59
60#endif // COMPONENTS_BACKGROUND_FETCH_DOWNLOAD_CLIENT_H_