File: device_bound_session_manager.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,788 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_NETWORK_DEVICE_BOUND_SESSION_MANAGER_H_
#define SERVICES_NETWORK_DEVICE_BOUND_SESSION_MANAGER_H_

#include <vector>

#include "base/callback_list.h"
#include "base/functional/callback_helpers.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/device_bound_sessions/session_display.h"
#include "net/device_bound_sessions/session_error.h"
#include "services/network/public/mojom/device_bound_sessions.mojom.h"

namespace net::device_bound_sessions {
class SessionService;
struct SessionKey;
}  // namespace net::device_bound_sessions

namespace network {

class CookieManager;

class COMPONENT_EXPORT(NETWORK_SERVICE) DeviceBoundSessionManager
    : public mojom::DeviceBoundSessionManager {
 public:
  static std::unique_ptr<DeviceBoundSessionManager> Create(
      net::device_bound_sessions::SessionService* service,
      CookieManager* cookie_manager);

  ~DeviceBoundSessionManager() override;

  void AddReceiver(
      mojo::PendingReceiver<mojom::DeviceBoundSessionManager> receiver);

  // network::mojom::DeviceBoundSessionManager
  void GetAllSessions(GetAllSessionsCallback callback) override;
  void DeleteSession(
      net::device_bound_sessions::DeletionReason reason,
      const net::device_bound_sessions::SessionKey& session_key) override;
  void DeleteAllSessions(net::device_bound_sessions::DeletionReason reason,
                         std::optional<base::Time> created_after_time,
                         std::optional<base::Time> created_before_time,
                         network::mojom::ClearDataFilterPtr filter,
                         base::OnceClosure completion_callback) override;
  void AddObserver(
      const GURL& url,
      mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver>
          observer) override;
  void AddEventObserver(
      mojo::PendingRemote<network::mojom::DeviceBoundSessionEventObserver>
          observer) override;
  void CreateBoundSessions(
      std::vector<net::device_bound_sessions::SessionParams> params,
      const std::vector<uint8_t>& wrapped_key,
      const std::vector<net::CanonicalCookie>& cookies_to_set,
      const net::CookieOptions& cookie_options,
      CreateBoundSessionsCallback callback) override;

 private:
  // State associated with a DeviceBoundSessionAccessObserver.
  struct AccessObserverRegistration {
    AccessObserverRegistration();
    ~AccessObserverRegistration();

    // Mojo interface
    mojo::Remote<network::mojom::DeviceBoundSessionAccessObserver> remote;

    // Subscription for inclusion in the SessionService's CallbackList.
    base::ScopedClosureRunner subscription;
  };

  // State associated with a DeviceBoundSessionEventObserver.
  struct EventObserverRegistration {
    EventObserverRegistration();
    ~EventObserverRegistration();

    // Mojo interface
    mojo::Remote<network::mojom::DeviceBoundSessionEventObserver> remote;

    // Subscription for inclusion in the SessionService's CallbackList.
    base::CallbackListSubscription subscription;

    base::WeakPtrFactory<EventObserverRegistration> weak_factory{this};
  };

  explicit DeviceBoundSessionManager(
      net::device_bound_sessions::SessionService* service,
      CookieManager* cookie_manager);

  // Remove an observer by its registration.
  void RemoveAccessObserver(AccessObserverRegistration* registration);
  void RemoveEventObserver(EventObserverRegistration* registration);

  void PopulateSessionDisplays(
      base::WeakPtr<EventObserverRegistration> registration,
      const std::vector<net::device_bound_sessions::SessionDisplay>&
          session_displays);

  void OnCreateBoundSessionsAdded(
      const std::vector<net::CanonicalCookie>& cookies_to_set,
      const net::CookieOptions& cookie_options,
      CreateBoundSessionsCallback callback,
      std::vector<net::device_bound_sessions::SessionError::ErrorType>
          session_errors);

  raw_ptr<net::device_bound_sessions::SessionService> service_;
  // `raw_ptr` is safe because both `this` and `cookie_manager_` are
  // owned by the `NetworkContext`.
  raw_ptr<CookieManager> cookie_manager_;
  mojo::ReceiverSet<network::mojom::DeviceBoundSessionManager> receivers_;
  std::vector<std::unique_ptr<AccessObserverRegistration>>
      access_observer_registrations_;
  std::vector<std::unique_ptr<EventObserverRegistration>>
      event_observer_registrations_;

  base::WeakPtrFactory<DeviceBoundSessionManager> weak_factory_{this};
};

}  // namespace network

#endif  // SERVICES_NETWORK_DEVICE_BOUND_SESSION_MANAGER_H_