• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
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 NET_DEVICE_BOUND_SESSIONS_SESSION_STORE_H_
6 #define NET_DEVICE_BOUND_SESSIONS_SESSION_STORE_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "net/device_bound_sessions/session.h"
12 
13 namespace net {
14 class SchemefulSite;
15 }
16 
17 namespace net::device_bound_sessions {
18 
19 // Interface SessionStore abstracts out the interaction with a
20 // persistent store for device bound session state.
21 class NET_EXPORT SessionStore {
22  public:
23   static std::unique_ptr<SessionStore> Create(
24       const base::FilePath& db_storage_path);
25 
26   virtual ~SessionStore() = default;
27 
28   SessionStore(const SessionStore&) = delete;
29   SessionStore& operator=(const SessionStore&) = delete;
30 
31   using SessionsMap = std::multimap<SchemefulSite, std::unique_ptr<Session>>;
32   using LoadSessionsCallback = base::OnceCallback<void(SessionsMap)>;
33   virtual void LoadSessions(LoadSessionsCallback callback) = 0;
34 
35   virtual void SaveSession(const SchemefulSite& site,
36                            const Session& session) = 0;
37 
38   virtual void DeleteSession(const SchemefulSite& site,
39                              const Session::Id& session_id) = 0;
40 
41   // Returns session objects created from currently cached store data.
42   virtual SessionsMap GetAllSessions() const = 0;
43 
44   // Asynchronously retrieves the unwrapped session binding key
45   // from its persistent form saved in the store.
46   using RestoreSessionBindingKeyCallback = base::OnceCallback<void(
47       unexportable_keys::ServiceErrorOr<unexportable_keys::UnexportableKeyId>)>;
48   virtual void RestoreSessionBindingKey(
49       const SchemefulSite& site,
50       const Session::Id& session_id,
51       RestoreSessionBindingKeyCallback callback) = 0;
52 
53  protected:
54   SessionStore() = default;
55 };
56 
57 }  // namespace net::device_bound_sessions
58 
59 #endif  // NET_DEVICE_BOUND_SESSIONS_SESSION_STORE_H_
60