Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 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 | |
| 5 | #ifndef COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_ |
| 6 | #define COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "base/files/file_path.h" |
| 11 | #include "base/macros.h" |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 12 | #include "components/services/storage/origin_context_impl.h" |
| 13 | #include "components/services/storage/public/mojom/partition.mojom.h" |
| 14 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 15 | #include "mojo/public/cpp/bindings/receiver_set.h" |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 16 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 17 | #include "url/origin.h" |
| 18 | |
| 19 | namespace storage { |
| 20 | |
Ken Rockot | af15f1d32 | 2020-02-14 23:08:11 | [diff] [blame] | 21 | class LocalStorageImpl; |
Kenichi Ishibashi | df2e01d0f | 2021-02-08 07:07:03 | [diff] [blame] | 22 | class ServiceWorkerStorageControlImpl; |
Ken Rockot | af15f1d32 | 2020-02-14 23:08:11 | [diff] [blame] | 23 | class SessionStorageImpl; |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 24 | class StorageServiceImpl; |
| 25 | |
| 26 | // A PartitionImpl instance exclusively owns an isolated storage partition |
| 27 | // corresponding to either a persistent filesystem directory or an in-memory |
| 28 | // database. |
| 29 | class PartitionImpl : public mojom::Partition { |
| 30 | public: |
| 31 | // |service| owns and outlives this object. |
| 32 | explicit PartitionImpl(StorageServiceImpl* service, |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 33 | const absl::optional<base::FilePath>& path); |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 34 | ~PartitionImpl() override; |
| 35 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 36 | const absl::optional<base::FilePath>& path() const { return path_; } |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 37 | |
| 38 | const mojo::ReceiverSet<mojom::Partition>& receivers() const { |
| 39 | return receivers_; |
| 40 | } |
| 41 | |
| 42 | const auto& origin_contexts() const { return origin_contexts_; } |
| 43 | |
| 44 | // Binds a new client endpoint to this partition. |
| 45 | void BindReceiver(mojo::PendingReceiver<mojom::Partition> receiver); |
| 46 | |
| 47 | // mojom::Partition: |
| 48 | void BindOriginContext( |
| 49 | const url::Origin& origin, |
| 50 | mojo::PendingReceiver<mojom::OriginContext> receiver) override; |
Ken Rockot | af15f1d32 | 2020-02-14 23:08:11 | [diff] [blame] | 51 | void BindSessionStorageControl( |
| 52 | mojo::PendingReceiver<mojom::SessionStorageControl> receiver) override; |
| 53 | void BindLocalStorageControl( |
| 54 | mojo::PendingReceiver<mojom::LocalStorageControl> receiver) override; |
Kenichi Ishibashi | df2e01d0f | 2021-02-08 07:07:03 | [diff] [blame] | 55 | void BindServiceWorkerStorageControl( |
| 56 | mojo::PendingReceiver<mojom::ServiceWorkerStorageControl> receiver) |
| 57 | override; |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | friend class OriginContextImpl; |
| 61 | |
| 62 | void OnDisconnect(); |
| 63 | void RemoveOriginContext(const url::Origin& origin); |
| 64 | |
| 65 | StorageServiceImpl* const service_; |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 66 | const absl::optional<base::FilePath> path_; |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 67 | mojo::ReceiverSet<mojom::Partition> receivers_; |
| 68 | std::map<url::Origin, std::unique_ptr<OriginContextImpl>> origin_contexts_; |
| 69 | |
Ken rockot | 6e4416c3 | 2020-11-23 20:10:08 | [diff] [blame] | 70 | std::unique_ptr<SessionStorageImpl> session_storage_; |
| 71 | std::unique_ptr<LocalStorageImpl> local_storage_; |
Kenichi Ishibashi | df2e01d0f | 2021-02-08 07:07:03 | [diff] [blame] | 72 | std::unique_ptr<ServiceWorkerStorageControlImpl> service_worker_storage_; |
Ken Rockot | af15f1d32 | 2020-02-14 23:08:11 | [diff] [blame] | 73 | |
Ken Rockot | 1962d93 | 2019-08-21 01:47:28 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(PartitionImpl); |
| 75 | }; |
| 76 | |
| 77 | } // namespace storage |
| 78 | |
| 79 | #endif // COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_ |