File: downgrade_manager.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 (76 lines) | stat: -rw-r--r-- 3,296 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
// Copyright 2019 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_DOWNGRADE_DOWNGRADE_MANAGER_H_
#define CHROME_BROWSER_DOWNGRADE_DOWNGRADE_MANAGER_H_

namespace base {
class FilePath;
class Version;
}  // namespace base

namespace downgrade {

// An encapsulation of processing relating to the handling of browser launches
// where the User Data directory was last written by a higher version of the
// browser (a "downgrade"). It can detect if downgrade processing is needed,
// drop a breadcrumb for future launches indicating the current browser version,
// delete leftover state from a previous downgrade, and perform processing on
// state deposited on the device by the browser (e.g., the User Data directory)
// following a downgrade.
class DowngradeManager {
 public:
  DowngradeManager() = default;
  DowngradeManager(const DowngradeManager&) = delete;
  DowngradeManager& operator=(const DowngradeManager&) = delete;

  // Inspects the contents of |user_data_dir| to determine whether a downgrade
  // or an upgrade has happened since the last launch. Takes a Snapshot in case
  // of upgrade, and sets the appropriate |type_| in case of downgrade. Returns
  // |true| if the data from |user_data_dir| requires migration processing,
  // |false| if it is usable by the current version. Note: this must be called
  // within the protection of the process singleton.
  bool PrepareUserDataDirectoryForCurrentVersion(
      const base::FilePath& user_data_dir);

  // Writes the current version number into the "Last Version" file in
  // |user_data_dir|.
  void UpdateLastVersion(const base::FilePath& user_data_dir);

  // Schedules a search for the removal of any directories moved aside by
  // PrepareUserDataDirectoryForCurrentVersion or ProcessDowngrade. This
  // operation is idempotent, and may be safely called when no such directories
  // exist.
  void DeleteMovedUserDataSoon(const base::FilePath& user_data_dir);

  // Process a previously-detected downgrade of |user_data_dir|. This must be
  // called late in shutdown while the process singleton is still held.
  void ProcessDowngrade(const base::FilePath& user_data_dir);

  static void EnableSnapshotsForTesting(bool enable);

 private:
  enum class Type {
    kNone = 0,                // Same version or upgrade.
    kAdministrativeWipe = 1,  // Admin-driven downgrade with no snapshot.
    kUnsupported = 2,         // Unsupported downgrade with no data processing.
    kSnapshotRestore = 3,     // Downgrade with snapshot restoration.
    kMinorDowngrade = 4,      // Minor version downgrade; no data processing.
    kMaxValue = kMinorDowngrade
  };

  static Type GetDowngradeType(const base::FilePath& user_data_dir,
                               const base::Version& current_version,
                               const base::Version& last_version);

  static Type GetDowngradeTypeWithSnapshot(const base::FilePath& user_data_dir,
                                           const base::Version& current_version,
                                           const base::Version& last_version);

  Type type_ = Type::kNone;
};

}  // namespace downgrade

#endif  // CHROME_BROWSER_DOWNGRADE_DOWNGRADE_MANAGER_H_