profile_disk_operations.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_
  5. #define WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/files/file_path.h"
  9. namespace weblayer {
  10. struct ProfileInfo {
  11. ProfileInfo(bool is_incognito,
  12. const std::string& name,
  13. const base::FilePath& data_path,
  14. const base::FilePath& cache_path);
  15. ProfileInfo();
  16. ProfileInfo(const ProfileInfo&);
  17. ProfileInfo& operator=(const ProfileInfo&);
  18. ~ProfileInfo();
  19. bool is_incognito = false;
  20. // The profile name supplied by client code. For non-incognito profiles name
  21. // can only contain alphanumeric and underscore to be valid.
  22. std::string name;
  23. // Path where persistent profile data is stored. This will be empty if
  24. // icognito.
  25. base::FilePath data_path;
  26. // Path where cache profile data is stored. Depending on the OS, this may
  27. // be the same as |data_path|; the OS may delete data in this directory.
  28. base::FilePath cache_path;
  29. };
  30. // |name| must be a valid profile name. Ensures that both data and cache path
  31. // directories are created. The paths returned may be different from the name
  32. // to avoid reusing directories that are marked as deleted.
  33. ProfileInfo CreateProfileInfo(const std::string& name, bool is_incognito);
  34. base::FilePath ComputeBrowserPersisterDataBaseDir(const ProfileInfo& info);
  35. void MarkProfileAsDeleted(const ProfileInfo& info);
  36. void TryNukeProfileFromDisk(const ProfileInfo& info);
  37. // Return names of profiles on disk. Invalid profile names are ignored.
  38. // Profiles marked as deleted are ignored.
  39. std::vector<std::string> ListProfileNames();
  40. // This should be called before any |MarkProfileAsDeleted| for a single process
  41. // to avoid races.
  42. void NukeProfilesMarkedForDeletion();
  43. // Functions exposed for testing.
  44. namespace internal {
  45. bool IsValidNameForNonIncognitoProfile(const std::string& name);
  46. std::string CheckDirNameAndExtractName(const std::string& dir_name);
  47. bool IsProfileMarkedForDeletion(const std::string& dir_name);
  48. } // namespace internal
  49. } // namespace weblayer
  50. #endif // WEBLAYER_BROWSER_PROFILE_DISK_OPERATIONS_H_