File: snapshot_file_collector.cc

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 (165 lines) | stat: -rw-r--r-- 8,610 bytes parent folder | download | duplicates (6)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/downgrade/snapshot_file_collector.h"

#include <utility>

#include "build/build_config.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/common/chrome_constants.h"
#include "components/affiliations/core/browser/affiliation_constants.h"
#include "components/autofill/core/browser/strike_databases/strike_database.h"
#include "components/bookmarks/common/bookmark_constants.h"
#include "components/history/core/browser/history_constants.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/sessions/core/session_constants.h"
#include "components/webdata/common/webdata_constants.h"
#include "content/public/browser/browsing_data_remover.h"

#if BUILDFLAG(IS_WIN)
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/web_applications/chrome_pwa_launcher/last_browser_file_util.h"
#endif

namespace downgrade {

SnapshotItemDetails::SnapshotItemDetails(base::FilePath path,
                                         ItemType item_type,
                                         uint64_t data_types,
                                         SnapshotItemId id)
    : path(std::move(path)),
      is_directory(item_type == ItemType::kDirectory),
      data_types(data_types),
      id(id) {}

// Returns a list of items to snapshot that should be directly under the user
// data  directory.
std::vector<SnapshotItemDetails> CollectUserDataItems() {
  std::vector<SnapshotItemDetails> user_data_items{
      SnapshotItemDetails(base::FilePath(chrome::kLocalStateFilename),
                          SnapshotItemDetails::ItemType::kFile, 0,
                          SnapshotItemId::kLocalState),
      SnapshotItemDetails(base::FilePath(profiles::kHighResAvatarFolderName),
                          SnapshotItemDetails::ItemType::kDirectory, 0,
                          SnapshotItemId::kHighResAvatar)};
#if BUILDFLAG(IS_WIN)
  user_data_items.emplace_back(base::FilePath(web_app::kLastBrowserFilename),
                               SnapshotItemDetails::ItemType::kFile, 0,
                               SnapshotItemId::kLastBrowser);
#endif  // BUILDFLAG(IS_WIN)
  return user_data_items;
}

// Returns a list of items to snapshot that should be under a profile directory.
std::vector<SnapshotItemDetails> CollectProfileItems() {
  // Data mask to delete the pref files if any of the following types is
  // deleted. When cookies are deleted, the kZeroSuggestCachedResults and
  // kZeroSuggestCachedResultsWithURL prefs have to be reset. When history and
  // isolated origins are deleted, the kPrefLastLaunchTime and
  // kUserTriggeredIsolatedOrigins prefs have to be reset. When data type
  // content is deleted, blocklisted sites are deleted from the translation
  // prefs.
  uint64_t pref_data_type =
      content::BrowsingDataRemover::DATA_TYPE_COOKIES |
      chrome_browsing_data_remover::DATA_TYPE_ISOLATED_ORIGINS |
      chrome_browsing_data_remover::DATA_TYPE_HISTORY |
      chrome_browsing_data_remover::DATA_TYPE_CONTENT_SETTINGS;
  std::vector<SnapshotItemDetails> profile_items{
      // General Profile files
      SnapshotItemDetails(base::FilePath(chrome::kPreferencesFilename),
                          SnapshotItemDetails::ItemType::kFile, pref_data_type,
                          SnapshotItemId::kPreferences),
      SnapshotItemDetails(base::FilePath(chrome::kSecurePreferencesFilename),
                          SnapshotItemDetails::ItemType::kFile, pref_data_type,
                          SnapshotItemId::kSecurePreferences),
      // History files
      SnapshotItemDetails(base::FilePath(history::kHistoryFilename),
                          SnapshotItemDetails::ItemType::kFile,
                          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
                          SnapshotItemId::kHistory),
      SnapshotItemDetails(base::FilePath(history::kFaviconsFilename),
                          SnapshotItemDetails::ItemType::kFile,
                          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
                          SnapshotItemId::kFavicons),
      SnapshotItemDetails(base::FilePath(history::kTopSitesFilename),
                          SnapshotItemDetails::ItemType::kFile,
                          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
                          SnapshotItemId::kTopSites),
      // Bookmarks
      SnapshotItemDetails(
          base::FilePath(bookmarks::kLocalOrSyncableBookmarksFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_BOOKMARKS,
          SnapshotItemId::kLocalOrSyncableBookmarks),
      SnapshotItemDetails(base::FilePath(bookmarks::kAccountBookmarksFileName),
                          SnapshotItemDetails::ItemType::kFile,
                          chrome_browsing_data_remover::DATA_TYPE_BOOKMARKS,
                          SnapshotItemId::kAccountBookmarks),
      // Tab Restore and sessions
      // TODO(crbug.com/40704630): Remove legacy snapshots in M89
      SnapshotItemDetails(
          base::FilePath(sessions::kLegacyCurrentTabSessionFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
          SnapshotItemId::kLegacyCurrentTabSession),
      SnapshotItemDetails(
          base::FilePath(sessions::kLegacyCurrentSessionFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
          SnapshotItemId::kLegacyCurrentSession),
      SnapshotItemDetails(base::FilePath(sessions::kSessionsDirectory),
                          SnapshotItemDetails::ItemType::kDirectory,
                          chrome_browsing_data_remover::DATA_TYPE_HISTORY,
                          SnapshotItemId::kSessions),
      // Sign-in state
      SnapshotItemDetails(base::FilePath(profiles::kGAIAPictureFileName),
                          SnapshotItemDetails::ItemType::kFile, 0,
                          SnapshotItemId::kGAIAPicture),
      // Password / Autofill
      SnapshotItemDetails(
          base::FilePath(affiliations::kAffiliationDatabaseFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
              chrome_browsing_data_remover::DATA_TYPE_FORM_DATA,
          SnapshotItemId::kAffiliationDatabase),
      SnapshotItemDetails(
          base::FilePath(password_manager::kLoginDataForProfileFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
              chrome_browsing_data_remover::DATA_TYPE_FORM_DATA,
          SnapshotItemId::kLoginDataForProfile),
      SnapshotItemDetails(
          base::FilePath(password_manager::kLoginDataForAccountFileName),
          SnapshotItemDetails::ItemType::kFile,
          chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
              chrome_browsing_data_remover::DATA_TYPE_FORM_DATA,
          SnapshotItemId::kLoginDataForAccount),
      SnapshotItemDetails(base::FilePath(kWebDataFilename),
                          SnapshotItemDetails::ItemType::kFile,
                          chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
                              chrome_browsing_data_remover::DATA_TYPE_FORM_DATA,
                          SnapshotItemId::kWebData),
      SnapshotItemDetails(base::FilePath(autofill::kStrikeDatabaseFileName),
                          SnapshotItemDetails::ItemType::kDirectory,
                          chrome_browsing_data_remover::DATA_TYPE_PASSWORDS |
                              chrome_browsing_data_remover::DATA_TYPE_FORM_DATA,
                          SnapshotItemId::kStrikeDatabase),
      // Cookies
      SnapshotItemDetails(base::FilePath(chrome::kCookieFilename),
                          SnapshotItemDetails::ItemType::kFile,
                          content::BrowsingDataRemover::DATA_TYPE_COOKIES,
                          SnapshotItemId::kCookie)};

#if BUILDFLAG(IS_WIN)
  // Sign-in state
  profile_items.emplace_back(base::FilePath(profiles::kProfileIconFileName),
                             SnapshotItemDetails::ItemType::kFile, 0,
                             SnapshotItemId::kProfileIcon);
#endif  // BUILDFLAG(IS_WIN)
  return profile_items;
}

}  // namespace downgrade