File: archive_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (93 lines) | stat: -rw-r--r-- 3,736 bytes parent folder | download | duplicates (8)
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
// Copyright 2016 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_OFFLINE_PAGES_CORE_ARCHIVE_MANAGER_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_ARCHIVE_MANAGER_H_

#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"

namespace base {
class SequencedTaskRunner;
}  // namespace base

namespace offline_pages {

// Class that manages all archive files for offline pages. They are stored in
// different archive directories based on their lifetime types (persistent or
// temporary).
// All tasks are performed using |task_runner_|.
class ArchiveManager {
 public:
  // Used by metrics collection and clearing storage of temporary pages.
  // - |internal_free_disk_space| is the free space of the volume which
  //   contains temporary and private archive directories.
  // - |external_free_disk_space| is the free space of the volume which contains
  //   public archives directory, in most cases it should be Download directory
  //   in /sdcard/.
  // - |{temporary/private}_archives_size| is the size of the directory. Since
  //   these are inside app directory and are fully controlled, it's unnecessary
  //   to calculate the size by iterating and counting.
  // - |public_archives_size| will enumerate all mhtml files in the public
  //   directory and records the total file size. This will include mhtml files
  //   shared into the public directory through other approaches.
  struct StorageStats {
    int64_t internal_archives_size() const {
      return temporary_archives_size + private_archives_size;
    }
    int64_t internal_free_disk_space;
    int64_t external_free_disk_space;
    int64_t temporary_archives_size;
    int64_t private_archives_size;
    int64_t public_archives_size;
  };

  typedef base::OnceCallback<void(
      const ArchiveManager::StorageStats& storage_stats)>
      StorageStatsCallback;

  ArchiveManager(const base::FilePath& temporary_archives_dir,
                 const base::FilePath& private_archives_dir_,
                 const base::FilePath& public_archives_dir,
                 const scoped_refptr<base::SequencedTaskRunner>& task_runner);

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

  virtual ~ArchiveManager();

  // Creates archives directory if one does not exist yet;
  virtual void EnsureArchivesDirCreated(base::OnceCallback<void()> callback);

  // Gets stats about archive storage, i.e. sizes of all archive directories
  // and free disk spaces.
  virtual void GetStorageStats(StorageStatsCallback callback) const;

  // Gets the archive directories.
  const base::FilePath& GetTemporaryArchivesDir() const;
  const base::FilePath& GetPrivateArchivesDir() const;
  virtual const base::FilePath& GetPublicArchivesDir();

 protected:
  // Used for testing.
  ArchiveManager();

 private:
  // Path under which all of the temporary archives should be stored.
  base::FilePath temporary_archives_dir_;
  // Path under which all of the persistent archives should be saved initially.
  base::FilePath private_archives_dir_;
  // Publically accessible path where archives should be moved once ready.
  base::FilePath public_archives_dir_;
  // Task runner for running file operations.
  // Since the task_runner is a SequencedTaskRunner, it's guaranteed that the
  // second task will start after the first one. This is an important assumption
  // for |ArchiveManager::EnsureArchivesDirCreated|.
  scoped_refptr<base::SequencedTaskRunner> task_runner_;
};

}  // namespace offline_pages

#endif  // COMPONENTS_OFFLINE_PAGES_CORE_ARCHIVE_MANAGER_H_