File: job_details.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_BACKGROUND_FETCH_JOB_DETAILS_H_
#define COMPONENTS_BACKGROUND_FETCH_JOB_DETAILS_H_

#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/background_fetch_delegate.h"

namespace content {
struct BackgroundFetchDescription;
}

namespace background_fetch {

struct JobDetails {
  enum class State {
    kPendingWillStartPaused,
    kPendingWillStartDownloading,
    kStartedButPaused,
    kStartedAndDownloading,
    // The job was aborted.
    kCancelled,
    // All requests were processed (either succeeded or failed).
    kDownloadsComplete,
    // The appropriate completion event (success, fail, abort) has been
    // dispatched.
    kJobComplete,
  };

  JobDetails();
  JobDetails(const JobDetails& other) = delete;
  JobDetails& operator=(const JobDetails& other) = delete;
  ~JobDetails();

  void MarkJobAsStarted();
  void UpdateJobOnDownloadComplete(const std::string& download_guid);

  // Gets the total number of bytes that need to be processed, or -1 if unknown.
  uint64_t GetTotalBytes() const;

  // Returns how many bytes have been processed by the Download Service so
  // far.
  uint64_t GetProcessedBytes() const;

  // Returns the number of downloaded bytes, including for the in progress
  // requests.
  uint64_t GetDownloadedBytes() const;

  // Whether the job has finished successfully (not aborted).
  bool IsComplete() const;

  void UpdateInProgressBytes(const std::string& download_guid,
                             uint64_t bytes_uploaded,
                             uint64_t bytes_downloaded);

  // Whether we should report progress of the job in terms of size of
  // downloads or in terms of the number of files being downloaded.
  bool ShouldReportProgressBySize() const;

  // Returns the number of bytes processed by in-progress requests.
  uint64_t GetInProgressBytes() const;

  struct RequestData {
    enum class Status {
      kAbsent,
      kIncluded,
    };

    explicit RequestData(bool has_upload_data);
    ~RequestData();

    Status status;

    uint64_t body_size_bytes = 0u;
    uint64_t in_progress_uploaded_bytes = 0u;
    uint64_t in_progress_downloaded_bytes = 0u;
  };

  // The client to report the Background Fetch updates to.
  base::WeakPtr<content::BackgroundFetchDelegate::Client> client;

  // Set of DownloadService GUIDs that are currently processed. They are
  // added by DownloadUrl and are removed when the fetch completes, fails,
  // or is cancelled.
  std::map<std::string, RequestData> current_fetch_guids;

  State job_state;
  std::unique_ptr<content::BackgroundFetchDescription> fetch_description;
  bool cancelled_from_ui = false;

  base::OnceClosure on_resume;
};

}  // namespace background_fetch

#endif  // COMPONENTS_BACKGROUND_FETCH_JOB_DETAILS_H_