blob: d69f9253222f0e6b7e46be4a7aa2541ae7bb3b83 [file] [log] [blame]
Ken Rockot1962d932019-08-21 01:47:281// 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 Rockot1962d932019-08-21 01:47:2812#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 Bikineev1156b5f2021-05-15 22:35:3616#include "third_party/abseil-cpp/absl/types/optional.h"
Ken Rockot1962d932019-08-21 01:47:2817#include "url/origin.h"
18
19namespace storage {
20
Ken Rockotaf15f1d322020-02-14 23:08:1121class LocalStorageImpl;
Kenichi Ishibashidf2e01d0f2021-02-08 07:07:0322class ServiceWorkerStorageControlImpl;
Ken Rockotaf15f1d322020-02-14 23:08:1123class SessionStorageImpl;
Ken Rockot1962d932019-08-21 01:47:2824class 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.
29class PartitionImpl : public mojom::Partition {
30 public:
31 // |service| owns and outlives this object.
32 explicit PartitionImpl(StorageServiceImpl* service,
Anton Bikineev1156b5f2021-05-15 22:35:3633 const absl::optional<base::FilePath>& path);
Ken Rockot1962d932019-08-21 01:47:2834 ~PartitionImpl() override;
35
Anton Bikineev1156b5f2021-05-15 22:35:3636 const absl::optional<base::FilePath>& path() const { return path_; }
Ken Rockot1962d932019-08-21 01:47:2837
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 Rockotaf15f1d322020-02-14 23:08:1151 void BindSessionStorageControl(
52 mojo::PendingReceiver<mojom::SessionStorageControl> receiver) override;
53 void BindLocalStorageControl(
54 mojo::PendingReceiver<mojom::LocalStorageControl> receiver) override;
Kenichi Ishibashidf2e01d0f2021-02-08 07:07:0355 void BindServiceWorkerStorageControl(
56 mojo::PendingReceiver<mojom::ServiceWorkerStorageControl> receiver)
57 override;
Ken Rockot1962d932019-08-21 01:47:2858
59 private:
60 friend class OriginContextImpl;
61
62 void OnDisconnect();
63 void RemoveOriginContext(const url::Origin& origin);
64
65 StorageServiceImpl* const service_;
Anton Bikineev1156b5f2021-05-15 22:35:3666 const absl::optional<base::FilePath> path_;
Ken Rockot1962d932019-08-21 01:47:2867 mojo::ReceiverSet<mojom::Partition> receivers_;
68 std::map<url::Origin, std::unique_ptr<OriginContextImpl>> origin_contexts_;
69
Ken rockot6e4416c32020-11-23 20:10:0870 std::unique_ptr<SessionStorageImpl> session_storage_;
71 std::unique_ptr<LocalStorageImpl> local_storage_;
Kenichi Ishibashidf2e01d0f2021-02-08 07:07:0372 std::unique_ptr<ServiceWorkerStorageControlImpl> service_worker_storage_;
Ken Rockotaf15f1d322020-02-14 23:08:1173
Ken Rockot1962d932019-08-21 01:47:2874 DISALLOW_COPY_AND_ASSIGN(PartitionImpl);
75};
76
77} // namespace storage
78
79#endif // COMPONENTS_SERVICES_STORAGE_PARTITION_IMPL_H_