File: multi_capture_data_service.h

package info (click to toggle)
chromium 140.0.7339.127-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,192,880 kB
  • sloc: cpp: 35,093,808; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,151 bytes parent folder | download | duplicates (3)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_MEDIA_WEBRTC_MULTI_CAPTURE_MULTI_CAPTURE_DATA_SERVICE_H_
#define CHROME_BROWSER_MEDIA_WEBRTC_MULTI_CAPTURE_MULTI_CAPTURE_DATA_SERVICE_H_

#include <map>
#include <memory>
#include <set>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/scoped_observation.h"
#include "base/values.h"
#include "chrome/browser/web_applications/web_app_install_manager.h"
#include "chrome/browser/web_applications/web_app_install_manager_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/webapps/common/web_app_id.h"

class PrefService;

namespace gfx {
class ImageSkia;
}  // namespace gfx

namespace web_app {
class IwaKeyDistributionInfoProvider;
class WebAppProvider;
}  // namespace web_app

namespace multi_capture {

// This keyed service serves as mechanism to prevent dynamic propagation for the
// data that constrains access to the `getAllScreensMedia` API. This is
// intentional to prevent that additional apps can use the API after the user
// was informed on login.
class MultiCaptureDataService : public KeyedService,
                                public web_app::WebAppInstallManagerObserver {
 public:
  class Observer : public base::CheckedObserver {
   public:
    virtual void MultiCaptureDataChanged() = 0;
    virtual void MultiCaptureDataServiceDestroyed() = 0;

   protected:
    ~Observer() override = default;
  };

  ~MultiCaptureDataService() override;

  static std::unique_ptr<MultiCaptureDataService> Create(
      web_app::WebAppProvider* provider,
      PrefService* prefs);

  const std::map<webapps::AppId, std::string>& GetCaptureAppsWithNotification()
      const;
  const std::map<webapps::AppId, std::string>&
  GetCaptureAppsWithoutNotification() const;
  gfx::ImageSkia GetAppIcon(const webapps::AppId& app_id) const;

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  // web_app::WebAppInstallManagerObserver:
  void OnWebAppInstalled(const webapps::AppId& app_id) override;
  void OnWebAppUninstalled(
      const webapps::AppId& app_id,
      webapps::WebappUninstallSource uninstall_source) override;
  void OnWebAppInstallManagerDestroyed() override;

 private:
  FRIEND_TEST_ALL_PREFIXES(
      MultiCaptureUsageIndicatorBrowserTest,
      YouMayBeCapturedNotificationShowsIfAppInstalledAndAllowlisted);
  FRIEND_TEST_ALL_PREFIXES(
      MultiCaptureUsageIndicatorBrowserTest,
      YouAreCapturedNotificationShowsIfAppInstalledAndAllowlisted);
  FRIEND_TEST_ALL_PREFIXES(MultiCaptureUsageIndicatorDynamicAppBrowserTest,
                           AllowlistedAppAddedAndDeleted);

  MultiCaptureDataService(web_app::WebAppProvider* provider,
                          PrefService* prefs);

  void Init();
  void LoadData();
  void OnIconReceived(const webapps::AppId& app_id, gfx::ImageSkia icon);
  bool MaybeAddAppToCaptureAppLists(const webapps::AppId& app_id);

  const raw_ref<web_app::IwaKeyDistributionInfoProvider> info_provider_;
  const raw_ptr<web_app::WebAppProvider> provider_;
  const raw_ptr<PrefService> prefs_;

  bool is_initialized_ = false;

  base::Value::List multi_screen_capture_allowlist_on_login_;
  std::set<std::string> app_without_notification_bundle_ids_;

  std::map<webapps::AppId, std::string> capture_apps_with_notification_;
  std::map<webapps::AppId, std::string> capture_apps_without_notification_;
  std::map<webapps::AppId, gfx::ImageSkia> app_icons_;

  base::ScopedObservation<web_app::WebAppInstallManager,
                          web_app::WebAppInstallManagerObserver>
      install_manager_observation_{this};

  base::ObserverList<Observer> observers_;

  base::WeakPtrFactory<MultiCaptureDataService> weak_ptr_factory_{this};
};

}  // namespace multi_capture

#endif  // CHROME_BROWSER_MEDIA_WEBRTC_MULTI_CAPTURE_MULTI_CAPTURE_DATA_SERVICE_H_