partition_impl.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2019 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 COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_
  5. #define COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_
  6. #include <memory>
  7. #include "base/files/file_path.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "components/services/storage/origin_context_impl.h"
  10. #include "components/services/storage/public/mojom/partition.mojom.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/receiver_set.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. #include "url/origin.h"
  15. namespace storage {
  16. class LocalStorageImpl;
  17. class ServiceWorkerStorageControlImpl;
  18. class SessionStorageImpl;
  19. class StorageServiceImpl;
  20. // A PartitionImpl instance exclusively owns an isolated storage partition
  21. // corresponding to either a persistent filesystem directory or an in-memory
  22. // database.
  23. class PartitionImpl : public mojom::Partition {
  24. public:
  25. // |service| owns and outlives this object.
  26. explicit PartitionImpl(StorageServiceImpl* service,
  27. const absl::optional<base::FilePath>& path);
  28. PartitionImpl(const PartitionImpl&) = delete;
  29. PartitionImpl& operator=(const PartitionImpl&) = delete;
  30. ~PartitionImpl() override;
  31. const absl::optional<base::FilePath>& path() const { return path_; }
  32. const mojo::ReceiverSet<mojom::Partition>& receivers() const {
  33. return receivers_;
  34. }
  35. const auto& origin_contexts() const { return origin_contexts_; }
  36. // Binds a new client endpoint to this partition.
  37. void BindReceiver(mojo::PendingReceiver<mojom::Partition> receiver);
  38. // mojom::Partition:
  39. void BindOriginContext(
  40. const url::Origin& origin,
  41. mojo::PendingReceiver<mojom::OriginContext> receiver) override;
  42. void BindSessionStorageControl(
  43. mojo::PendingReceiver<mojom::SessionStorageControl> receiver) override;
  44. void BindLocalStorageControl(
  45. mojo::PendingReceiver<mojom::LocalStorageControl> receiver) override;
  46. void BindServiceWorkerStorageControl(
  47. mojo::PendingReceiver<mojom::ServiceWorkerStorageControl> receiver)
  48. override;
  49. private:
  50. friend class OriginContextImpl;
  51. void OnDisconnect();
  52. void RemoveOriginContext(const url::Origin& origin);
  53. const raw_ptr<StorageServiceImpl> service_;
  54. const absl::optional<base::FilePath> path_;
  55. mojo::ReceiverSet<mojom::Partition> receivers_;
  56. std::map<url::Origin, std::unique_ptr<OriginContextImpl>> origin_contexts_;
  57. std::unique_ptr<SessionStorageImpl> session_storage_;
  58. std::unique_ptr<LocalStorageImpl> local_storage_;
  59. std::unique_ptr<ServiceWorkerStorageControlImpl> service_worker_storage_;
  60. };
  61. } // namespace storage
  62. #endif // COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_