file_system_quota_client.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2012 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 STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_QUOTA_CLIENT_H_
  5. #define STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_QUOTA_CLIENT_H_
  6. #include "base/component_export.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/sequence_checker.h"
  10. #include "base/thread_annotations.h"
  11. #include "components/services/storage/public/mojom/quota_client.mojom.h"
  12. #include "storage/browser/file_system/file_system_quota_util.h"
  13. #include "storage/browser/quota/quota_client_type.h"
  14. #include "storage/common/file_system/file_system_types.h"
  15. #include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
  16. namespace base {
  17. class SequencedTaskRunner;
  18. }
  19. namespace storage {
  20. class FileSystemContext;
  21. struct BucketLocator;
  22. // All of the public methods of this class are called by the quota manager
  23. // (except for the constructor/destructor).
  24. class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemQuotaClient
  25. : public mojom::QuotaClient {
  26. public:
  27. explicit FileSystemQuotaClient(FileSystemContext* file_system_context);
  28. ~FileSystemQuotaClient() override;
  29. FileSystemQuotaClient(const FileSystemQuotaClient&) = delete;
  30. FileSystemQuotaClient& operator=(const FileSystemQuotaClient&) = delete;
  31. // mojom::QuotaClient methods.
  32. void GetBucketUsage(const BucketLocator& bucket,
  33. GetBucketUsageCallback callback) override;
  34. void GetStorageKeysForType(blink::mojom::StorageType type,
  35. GetStorageKeysForTypeCallback callback) override;
  36. void DeleteBucketData(const BucketLocator& bucket,
  37. DeleteBucketDataCallback callback) override;
  38. void PerformStorageCleanup(blink::mojom::StorageType type,
  39. PerformStorageCleanupCallback callback) override;
  40. private:
  41. base::SequencedTaskRunner* file_task_runner() const;
  42. SEQUENCE_CHECKER(sequence_checker_);
  43. // Raw pointer usage is safe because `file_system_context_` owns this.
  44. //
  45. // The FileSystemQuotaClient implementation mints scoped_refptrs from this
  46. // raw pointer in order to ensure that the FileSystemContext remains alive
  47. // while tasks are posted to the FileSystemContext's file sequence.
  48. //
  49. // So, it would be tempting to use scoped_refptr<FileSystemContext> here.
  50. // However, using scoped_refptr here creates a cycle, because
  51. // `file_system_context_` owns this. We could break the cycle in
  52. // FileSystemContext::Shutdown(), but then we would have to ensure that
  53. // Shutdown() is called by all FileSystemContext users.
  54. const raw_ptr<FileSystemContext> file_system_context_
  55. GUARDED_BY_CONTEXT(sequence_checker_);
  56. };
  57. } // namespace storage
  58. #endif // STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_QUOTA_CLIENT_H_