summaryrefslogtreecommitdiff
path: root/chromium/weblayer/browser/profile_disk_operations.h
blob: 38a9fbd2a818fd66c3b3f3e63e9df26b36159999 (plain)
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_
#define WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_

#include <string>
#include <vector>

#include "base/files/file_path.h"

namespace weblayer {

struct ProfileInfo {
  // The profile name supplied by client code. Name can only contain
  // alphanumeric and underscore to be valid. The empty name is valid and
  // indicates the incognito profile.
  std::string name;
  // Path where persistent profile data is stored. This will be empty for the
  // incognito profile with empty name.
  base::FilePath data_path;
  // Path where cache profile data is stored. Depending on the OS, this may
  // be the same as |data_path|; the OS may delete data in this directory.
  base::FilePath cache_path;
};

// |name| must be a valid profile name. Ensures that both data and cache path
// directories are created. The paths returned may be different from the name
// to avoid reusing directories that are marked as deleted.
ProfileInfo CreateProfileInfo(const std::string& name);

base::FilePath ComputeBrowserPersisterDataBaseDir(const ProfileInfo& info);
void MarkProfileAsDeleted(const ProfileInfo& info);
void TryNukeProfileFromDisk(const ProfileInfo& info);

// Return names of profiles on disk. Invalid profile names are ignored.
// Profiles marked as deleted are ignored.
std::vector<std::string> ListProfileNames();

// This should be called before any |MarkProfileAsDeleted| for a single process
// to avoid races.
void NukeProfilesMarkedForDeletion();

// Functions exposed for testing.
namespace internal {

bool IsProfileNameValid(const std::string& name);
std::string CheckDirNameAndExtractName(const std::string& dir_name);
bool IsProfileMarkedForDeletion(const std::string& dir_name);

}  // namespace internal

}  // namespace weblayer

#endif  // WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_