Commit 9d96bce3 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

User data snapshot: Use global constants for filenames

Bug: 958893
Change-Id: I5423d68fe7459ea2f1f90f4f4da8d3750304d3aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067813
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarParastoo Geranmayeh <parastoog@google.com>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744326}
parent 9ed42d0f
...@@ -6,6 +6,21 @@ ...@@ -6,6 +6,21 @@
#include <utility> #include <utility>
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/common/chrome_constants.h"
#include "components/autofill/core/browser/payments/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"
#if defined(OS_WIN)
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/web_applications/components/web_app_file_handler_registration_win.h"
#endif
namespace downgrade { namespace downgrade {
SnapshotItemDetails::SnapshotItemDetails(base::FilePath path, SnapshotItemDetails::SnapshotItemDetails(base::FilePath path,
...@@ -15,68 +30,70 @@ SnapshotItemDetails::SnapshotItemDetails(base::FilePath path, ...@@ -15,68 +30,70 @@ SnapshotItemDetails::SnapshotItemDetails(base::FilePath path,
// Returns a list of items to snapshot that should be directly under the user // Returns a list of items to snapshot that should be directly under the user
// data directory. // data directory.
std::vector<SnapshotItemDetails> CollectUserDataItems(uint16_t version) { std::vector<SnapshotItemDetails> CollectUserDataItems(uint16_t version) {
// TODO (ydago): move the logic of the component files to the component std::vector<SnapshotItemDetails> user_data_items{
// themselves. SnapshotItemDetails(base::FilePath(chrome::kLocalStateFilename),
return std::vector<SnapshotItemDetails>{
// General files to snapshot
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Last Browser")),
SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Local State")),
SnapshotItemDetails::ItemType::kDirectory), SnapshotItemDetails::ItemType::kDirectory),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Avatars")), SnapshotItemDetails(base::FilePath(profiles::kHighResAvatarFolderName),
SnapshotItemDetails::ItemType::kDirectory)}; SnapshotItemDetails::ItemType::kDirectory)};
#if defined(OS_WIN)
user_data_items.emplace_back(
SnapshotItemDetails(base::FilePath(web_app::kLastBrowserFile),
SnapshotItemDetails::ItemType::kFile));
#endif // defined(OS_WIN)
return user_data_items;
} }
// Returns a list of items to snapshot that should be under a profile directory. // Returns a list of items to snapshot that should be under a profile directory.
std::vector<SnapshotItemDetails> CollectProfileItems(uint16_t version) { std::vector<SnapshotItemDetails> CollectProfileItems(uint16_t version) {
// TODO (ydago): move the logic of the component files to the component std::vector<SnapshotItemDetails> profile_items{
// themselves.
return std::vector<SnapshotItemDetails>{
// General Profile files // General Profile files
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Preferences")), SnapshotItemDetails(base::FilePath(chrome::kPreferencesFilename),
SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(chrome::kSecurePreferencesFilename),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(
base::FilePath(FILE_PATH_LITERAL("Secure Preferences")),
SnapshotItemDetails::ItemType::kFile),
// History files // History files
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("History")), SnapshotItemDetails(base::FilePath(history::kHistoryFilename),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Favicons")), SnapshotItemDetails(base::FilePath(history::kFaviconsFilename),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("TopSites")), SnapshotItemDetails(base::FilePath(history::kTopSitesFilename),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
// Bookmarks // Bookmarks
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Bookmarks")), SnapshotItemDetails(base::FilePath(bookmarks::kBookmarksFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
// Tab Restore and sessions // Tab Restore and sessions
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Current Tabs")), SnapshotItemDetails(base::FilePath(sessions::kCurrentTabSessionFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Current Session")), SnapshotItemDetails(base::FilePath(sessions::kCurrentSessionFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
// Sign-in state // Sign-in state
SnapshotItemDetails(base::FilePath(profiles::kGAIAPictureFileName),
SnapshotItemDetails::ItemType::kFile),
// Password / Autofill
SnapshotItemDetails( SnapshotItemDetails(
base::FilePath(FILE_PATH_LITERAL("Google Profile.ico")), base::FilePath(password_manager::kAffiliationDatabaseFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails( SnapshotItemDetails(
base::FilePath(FILE_PATH_LITERAL("Google Profile Picture.png")), base::FilePath(password_manager::kLoginDataForProfileFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
// Password / Autofill
SnapshotItemDetails( SnapshotItemDetails(
base::FilePath(FILE_PATH_LITERAL("Affiliation Database")), base::FilePath(password_manager::kLoginDataForAccountFileName),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Login Data")), SnapshotItemDetails(base::FilePath(kWebDataFilename),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails( SnapshotItemDetails(base::FilePath(autofill::kStrikeDatabaseFileName),
base::FilePath(FILE_PATH_LITERAL("Login Data For Account")),
SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Web Data")),
SnapshotItemDetails::ItemType::kFile), SnapshotItemDetails::ItemType::kFile),
SnapshotItemDetails(
base::FilePath(FILE_PATH_LITERAL("AutofillStrikeDatabase")),
SnapshotItemDetails::ItemType::kFile),
// Cookies // Cookies
SnapshotItemDetails(base::FilePath(FILE_PATH_LITERAL("Cookies")), SnapshotItemDetails(base::FilePath(chrome::kCookieFilename),
SnapshotItemDetails::ItemType::kFile)}; SnapshotItemDetails::ItemType::kFile)};
#if defined(OS_WIN)
// Sign-in state
profile_items.emplace_back(
SnapshotItemDetails(base::FilePath(profiles::kProfileIconFileName),
SnapshotItemDetails::ItemType::kFile));
#endif // defined(OS_WIN)
return profile_items;
} }
} // namespace downgrade } // namespace downgrade
...@@ -307,8 +307,10 @@ constexpr SkColor kAvatarBubbleGaiaBackgroundColor = ...@@ -307,8 +307,10 @@ constexpr SkColor kAvatarBubbleGaiaBackgroundColor =
constexpr SkColor kUserManagerBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); constexpr SkColor kUserManagerBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee);
constexpr char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; constexpr char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_";
constexpr char kGAIAPictureFileName[] = "Google Profile Picture.png"; constexpr base::FilePath::CharType kGAIAPictureFileName[] =
constexpr char kHighResAvatarFolderName[] = "Avatars"; FILE_PATH_LITERAL("Google Profile Picture.png");
constexpr base::FilePath::CharType kHighResAvatarFolderName[] =
FILE_PATH_LITERAL("Avatars");
// The size of the function-static kDefaultAvatarIconResources array below. // The size of the function-static kDefaultAvatarIconResources array below.
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -594,8 +596,7 @@ base::FilePath GetPathOfHighResAvatarAtIndex(size_t index) { ...@@ -594,8 +596,7 @@ base::FilePath GetPathOfHighResAvatarAtIndex(size_t index) {
const char* file_name = GetDefaultAvatarIconFileNameAtIndex(index); const char* file_name = GetDefaultAvatarIconFileNameAtIndex(index);
base::FilePath user_data_dir; base::FilePath user_data_dir;
CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
return user_data_dir.AppendASCII( return user_data_dir.Append(kHighResAvatarFolderName).AppendASCII(file_name);
kHighResAvatarFolderName).AppendASCII(file_name);
} }
std::string GetDefaultAvatarIconUrl(size_t index) { std::string GetDefaultAvatarIconUrl(size_t index) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include "base/files/file_path.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
...@@ -39,8 +40,8 @@ const int kProfileAvatarBadgeSizeWin = kShortcutIconSizeWin / 2; ...@@ -39,8 +40,8 @@ const int kProfileAvatarBadgeSizeWin = kShortcutIconSizeWin / 2;
#endif // OS_WIN #endif // OS_WIN
// Avatar access. // Avatar access.
extern const char kGAIAPictureFileName[]; extern const base::FilePath::CharType kGAIAPictureFileName[];
extern const char kHighResAvatarFolderName[]; extern const base::FilePath::CharType kHighResAvatarFolderName[];
// Avatar formatting. // Avatar formatting.
extern const int kAvatarIconSize; extern const int kAvatarIconSize;
......
...@@ -416,7 +416,9 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex( ...@@ -416,7 +416,9 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(
} else { } else {
// Save the new bitmap to disk. // Save the new bitmap to disk.
new_file_name = new_file_name =
old_file_name.empty() ? profiles::kGAIAPictureFileName : old_file_name; old_file_name.empty()
? base::FilePath(profiles::kGAIAPictureFileName).MaybeAsASCII()
: old_file_name;
base::FilePath image_path = path.AppendASCII(new_file_name); base::FilePath image_path = path.AppendASCII(new_file_name);
SaveAvatarImageAtPath( SaveAvatarImageAtPath(
GetPathOfProfileAtIndex(index), image, key, image_path, GetPathOfProfileAtIndex(index), image, key, image_path,
......
...@@ -57,9 +57,6 @@ using content::BrowserThread; ...@@ -57,9 +57,6 @@ using content::BrowserThread;
namespace { namespace {
// Name of the badged icon file generated for a given profile.
const char kProfileIconFileName[] = "Google Profile.ico";
// Characters that are not allowed in Windows filenames. Taken from // Characters that are not allowed in Windows filenames. Taken from
// http://msdn.microsoft.com/en-us/library/aa365247.aspx // http://msdn.microsoft.com/en-us/library/aa365247.aspx
const base::char16 kReservedCharacters[] = const base::char16 kReservedCharacters[] =
...@@ -617,10 +614,14 @@ base::string16 SanitizeShortcutProfileNameString( ...@@ -617,10 +614,14 @@ base::string16 SanitizeShortcutProfileNameString(
} // namespace } // namespace
namespace profiles { namespace profiles {
const base::FilePath::StringPieceType kProfileIconFileName =
FILE_PATH_LITERAL("Google Profile.ico");
namespace internal { namespace internal {
base::FilePath GetProfileIconPath(const base::FilePath& profile_path) { base::FilePath GetProfileIconPath(const base::FilePath& profile_path) {
return profile_path.AppendASCII(kProfileIconFileName); return profile_path.Append(kProfileIconFileName);
} }
base::string16 GetShortcutFilenameForProfile( base::string16 GetShortcutFilenameForProfile(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <set> #include <set>
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager_observer.h" #include "chrome/browser/profiles/profile_manager_observer.h"
...@@ -15,6 +16,10 @@ ...@@ -15,6 +16,10 @@
// Internal free-standing functions that are exported here for testing. // Internal free-standing functions that are exported here for testing.
namespace profiles { namespace profiles {
// Name of the badged icon file generated for a given profile.
extern const base::FilePath::StringPieceType kProfileIconFileName;
namespace internal { namespace internal {
// Returns the full path to the profile icon file. // Returns the full path to the profile icon file.
......
...@@ -24,13 +24,16 @@ namespace { ...@@ -24,13 +24,16 @@ namespace {
const int kMaxInitAttempts = 3; const int kMaxInitAttempts = 3;
} // namespace } // namespace
const base::FilePath::StringPieceType kStrikeDatabaseFileName =
FILE_PATH_LITERAL("AutofillStrikeDatabase");
StrikeDatabase::StrikeDatabase( StrikeDatabase::StrikeDatabase(
leveldb_proto::ProtoDatabaseProvider* db_provider, leveldb_proto::ProtoDatabaseProvider* db_provider,
base::FilePath profile_path) { base::FilePath profile_path) {
auto strike_database_path = const auto strike_database_path =
profile_path.Append(FILE_PATH_LITERAL("AutofillStrikeDatabase")); profile_path.Append(kStrikeDatabaseFileName);
auto database_task_runner = base::CreateSequencedTaskRunner( const auto database_task_runner = base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}); base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN});
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/leveldb_proto/public/proto_database.h" #include "components/leveldb_proto/public/proto_database.h"
...@@ -18,6 +19,8 @@ ...@@ -18,6 +19,8 @@
namespace autofill { namespace autofill {
extern const base::FilePath::StringPieceType kStrikeDatabaseFileName;
namespace { namespace {
const char kKeyDeliminator[] = "__"; const char kKeyDeliminator[] = "__";
} // namespace } // namespace
......
...@@ -6,6 +6,16 @@ ...@@ -6,6 +6,16 @@
namespace sessions { namespace sessions {
const base::FilePath::StringPieceType kCurrentTabSessionFileName =
FILE_PATH_LITERAL("Current Tabs");
const base::FilePath::StringPieceType kLastTabSessionFileName =
FILE_PATH_LITERAL("Last Tabs");
const base::FilePath::StringPieceType kCurrentSessionFileName =
FILE_PATH_LITERAL("Current Session");
const base::FilePath::StringPieceType kLastSessionFileName =
FILE_PATH_LITERAL("Last Session");
const int gMaxPersistNavigationCount = 6; const int gMaxPersistNavigationCount = 6;
} // namespace sessions } // namespace sessions
...@@ -5,10 +5,23 @@ ...@@ -5,10 +5,23 @@
#ifndef COMPONENTS_SESSIONS_CORE_SESSION_CONSTANTS_H_ #ifndef COMPONENTS_SESSIONS_CORE_SESSION_CONSTANTS_H_
#define COMPONENTS_SESSIONS_CORE_SESSION_CONSTANTS_H_ #define COMPONENTS_SESSIONS_CORE_SESSION_CONSTANTS_H_
#include "base/files/file_path.h"
#include "components/sessions/core/sessions_export.h" #include "components/sessions/core/sessions_export.h"
namespace sessions { namespace sessions {
// File names (current and previous) for a type of TAB.
extern const base::FilePath::StringPieceType SESSIONS_EXPORT
kCurrentTabSessionFileName;
extern const base::FilePath::StringPieceType SESSIONS_EXPORT
kLastTabSessionFileName;
// File names (current and previous) for a type of SESSION.
extern const base::FilePath::StringPieceType SESSIONS_EXPORT
kCurrentSessionFileName;
extern const base::FilePath::StringPieceType SESSIONS_EXPORT
kLastSessionFileName;
// The maximum number of navigation entries in each direction to persist. // The maximum number of navigation entries in each direction to persist.
extern const int SESSIONS_EXPORT gMaxPersistNavigationCount; extern const int SESSIONS_EXPORT gMaxPersistNavigationCount;
......
...@@ -7,26 +7,19 @@ ...@@ -7,26 +7,19 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "components/sessions/core/session_constants.h"
namespace sessions { namespace sessions {
namespace { namespace {
// File names (current and previous) for a type of TAB.
static const char* kCurrentTabSessionFileName = "Current Tabs";
static const char* kLastTabSessionFileName = "Last Tabs";
// File names (current and previous) for a type of SESSION.
static const char* kCurrentSessionFileName = "Current Session";
static const char* kLastSessionFileName = "Last Session";
base::FilePath GetCurrentFilePath( base::FilePath GetCurrentFilePath(
SnapshottingCommandStorageManager::SessionType type, SnapshottingCommandStorageManager::SessionType type,
const base::FilePath& base_path) { const base::FilePath& base_path) {
base::FilePath path = base_path; base::FilePath path = base_path;
if (type == SnapshottingCommandStorageManager::TAB_RESTORE) if (type == SnapshottingCommandStorageManager::TAB_RESTORE)
path = path.AppendASCII(kCurrentTabSessionFileName); path = path.Append(kCurrentTabSessionFileName);
else else
path = path.AppendASCII(kCurrentSessionFileName); path = path.Append(kCurrentSessionFileName);
return path; return path;
} }
...@@ -35,9 +28,9 @@ base::FilePath GetLastFilePath( ...@@ -35,9 +28,9 @@ base::FilePath GetLastFilePath(
const base::FilePath& base_path) { const base::FilePath& base_path) {
base::FilePath path = base_path; base::FilePath path = base_path;
if (type == SnapshottingCommandStorageManager::TAB_RESTORE) if (type == SnapshottingCommandStorageManager::TAB_RESTORE)
path = path.AppendASCII(kLastTabSessionFileName); path = path.Append(kLastTabSessionFileName);
else else
path = path.AppendASCII(kLastSessionFileName); path = path.Append(kLastSessionFileName);
return path; return path;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment