xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/linux/wayland/restore_token_manager.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2022 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_RESTORE_TOKEN_MANAGER_H_
12 #define MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_RESTORE_TOKEN_MANAGER_H_
13 
14 #include <mutex>
15 #include <string>
16 #include <unordered_map>
17 
18 #include "modules/desktop_capture/desktop_capturer.h"
19 
20 namespace webrtc {
21 
22 class RestoreTokenManager {
23  public:
24   RestoreTokenManager(const RestoreTokenManager& manager) = delete;
25   RestoreTokenManager& operator=(const RestoreTokenManager& manager) = delete;
26 
27   static RestoreTokenManager& GetInstance();
28 
29   void AddToken(DesktopCapturer::SourceId id, const std::string& token);
30   std::string TakeToken(DesktopCapturer::SourceId id);
31 
32   // Returns a source ID which does not have any token associated with it yet.
33   DesktopCapturer::SourceId GetUnusedId();
34 
35  private:
36   RestoreTokenManager() = default;
37   ~RestoreTokenManager() = default;
38 
39   DesktopCapturer::SourceId last_source_id_ = 0;
40 
41   std::unordered_map<DesktopCapturer::SourceId, std::string> restore_tokens_;
42 };
43 
44 }  // namespace webrtc
45 
46 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_RESTORE_TOKEN_MANAGER_H_
47