sandbox_quota_observer.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_SANDBOX_QUOTA_OBSERVER_H_
  5. #define STORAGE_BROWSER_FILE_SYSTEM_SANDBOX_QUOTA_OBSERVER_H_
  6. #include <stdint.h>
  7. #include <map>
  8. #include "base/compiler_specific.h"
  9. #include "base/files/file_error_or.h"
  10. #include "base/files/file_path.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/memory/scoped_refptr.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "base/timer/timer.h"
  16. #include "storage/browser/file_system/file_observers.h"
  17. #include "storage/browser/file_system/file_system_url.h"
  18. namespace base {
  19. class SequencedTaskRunner;
  20. }
  21. namespace url {
  22. class Origin;
  23. }
  24. namespace storage {
  25. class FileSystemUsageCache;
  26. class FileSystemURL;
  27. class ObfuscatedFileUtil;
  28. class QuotaManagerProxy;
  29. class SandboxQuotaObserver : public FileUpdateObserver,
  30. public FileAccessObserver {
  31. public:
  32. SandboxQuotaObserver(
  33. scoped_refptr<QuotaManagerProxy> quota_manager_proxy,
  34. scoped_refptr<base::SequencedTaskRunner> update_notify_runner,
  35. ObfuscatedFileUtil* sandbox_file_util,
  36. FileSystemUsageCache* file_system_usage_cache_);
  37. SandboxQuotaObserver(const SandboxQuotaObserver&) = delete;
  38. SandboxQuotaObserver& operator=(const SandboxQuotaObserver&) = delete;
  39. ~SandboxQuotaObserver() override;
  40. // FileUpdateObserver overrides.
  41. void OnStartUpdate(const FileSystemURL& url) override;
  42. void OnUpdate(const FileSystemURL& url, int64_t delta) override;
  43. void OnEndUpdate(const FileSystemURL& url) override;
  44. // FileAccessObserver overrides.
  45. void OnAccess(const FileSystemURL& url) override;
  46. void SetUsageCacheEnabled(const url::Origin& origin,
  47. FileSystemType type,
  48. bool enabled);
  49. private:
  50. void ApplyPendingUsageUpdate();
  51. void UpdateUsageCacheFile(const base::FilePath& usage_file_path,
  52. int64_t delta);
  53. base::FileErrorOr<base::FilePath> GetUsageCachePath(const FileSystemURL& url);
  54. const scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
  55. const scoped_refptr<base::SequencedTaskRunner> update_notify_runner_;
  56. // Not owned; sandbox_file_util_ should have identical lifetime with this.
  57. const raw_ptr<ObfuscatedFileUtil> sandbox_file_util_;
  58. // Not owned; file_system_usage_cache_ should have longer lifetime than this.
  59. const raw_ptr<FileSystemUsageCache> file_system_usage_cache_;
  60. std::map<base::FilePath, int64_t> pending_update_notification_;
  61. base::OneShotTimer delayed_cache_update_helper_;
  62. };
  63. } // namespace storage
  64. #endif // STORAGE_BROWSER_FILE_SYSTEM_SANDBOX_QUOTA_OBSERVER_H_