File: snapshot_file_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 (108 lines) | stat: -rw-r--r-- 3,713 bytes parent folder | download | duplicates (7)
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
100
101
102
103
104
105
106
107
108
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_MEDIA_GALLERIES_CHROMEOS_SNAPSHOT_FILE_DETAILS_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_CHROMEOS_SNAPSHOT_FILE_DETAILS_H_

#include <stdint.h>

#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"

// Used to represent snapshot file request params.
struct SnapshotRequestInfo {
  SnapshotRequestInfo(uint32_t file_id,
                      const base::FilePath& snapshot_file_path,
                      MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback
                          success_callback,
                      MTPDeviceAsyncDelegate::ErrorCallback error_callback);
  SnapshotRequestInfo(SnapshotRequestInfo&& other);
  SnapshotRequestInfo(const SnapshotRequestInfo& other) = delete;
  SnapshotRequestInfo& operator=(const SnapshotRequestInfo& other) = delete;
  ~SnapshotRequestInfo();

  // MTP device file id.
  const uint32_t file_id;

  // Local platform path of the snapshot file.
  const base::FilePath snapshot_file_path;

  // A callback to be called when CreateSnapshotFile() succeeds.
  MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback success_callback;

  // A callback to be called when CreateSnapshotFile() fails.
  MTPDeviceAsyncDelegate::ErrorCallback error_callback;
};

// SnapshotFileDetails tracks the current state of the snapshot file (e.g how
// many bytes written to the snapshot file, source file details, snapshot file
// metadata information, etc).
class SnapshotFileDetails {
 public:
  SnapshotFileDetails(SnapshotRequestInfo request_info,
                      const base::File::Info& file_info);

  SnapshotFileDetails(const SnapshotFileDetails&) = delete;
  SnapshotFileDetails& operator=(const SnapshotFileDetails&) = delete;

  ~SnapshotFileDetails();

  uint32_t file_id() const { return request_info_.file_id; }

  base::FilePath snapshot_file_path() const {
    return request_info_.snapshot_file_path;
  }

  uint32_t bytes_written() const { return bytes_written_; }

  const base::File::Info& file_info() const {
    return file_info_;
  }

  MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback success_callback() {
    return std::move(request_info_.success_callback);
  }

  MTPDeviceAsyncDelegate::ErrorCallback error_callback() {
    return std::move(request_info_.error_callback);
  }

  bool error_occurred() const {
    return error_occurred_;
  }

  void set_error_occurred(bool error);

  // Adds |bytes_written| to |bytes_written_|.
  // |bytes_written| specifies the total number of bytes transferred during the
  // last write operation.
  // If |bytes_written| is valid, returns true and adds |bytes_written| to
  // |bytes_written_|.
  // If |bytes_written| is invalid, returns false and does not add
  // |bytes_written| to |bytes_written_|.
  bool AddBytesWritten(uint32_t bytes_written);

  // Returns true if the snapshot file is created successfully (no more write
  // operation is required to complete the snapshot file).
  bool IsSnapshotFileWriteComplete() const;

  uint32_t BytesToRead() const;

 private:
  // Snapshot file request params.
  SnapshotRequestInfo request_info_;

  // Metadata of the snapshot file (such as name, size, type, etc).
  const base::File::Info file_info_;

  // Number of bytes written into the snapshot file.
  uint32_t bytes_written_;

  // Whether an error occurred during file transfer.
  bool error_occurred_;
};

#endif  // CHROME_BROWSER_MEDIA_GALLERIES_CHROMEOS_SNAPSHOT_FILE_DETAILS_H_