1 // 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 CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_MANAGER_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_MANAGER_H_
7 
8 #include "base/macros.h"
9 #include "base/observer_list.h"
10 
11 namespace base {
12 template <typename T>
13 class NoDestructor;
14 }
15 
16 // A singleton that acts as a rendezvous for dialog observers to register and
17 // the dialog managers/delegates to post their activities.
18 // TODO(crbug/953495): Merge this into DesktopMediaPickerFactoryImpl.
19 class DesktopMediaPickerManager {
20  public:
21   class DialogObserver : public base::CheckedObserver {
22    public:
23     // Called when a media dialog is opened/shown.
24     virtual void OnDialogOpened() = 0;
25 
26     // Called when a media dialog is closed/hidden.
27     virtual void OnDialogClosed() = 0;
28   };
29 
30   static DesktopMediaPickerManager* Get();
31 
32   // For the observers
33   void AddObserver(DialogObserver* observer);
34   void RemoveObserver(DialogObserver* observer);
35 
36   // For the notifiers
37   void OnShowDialog();
38   void OnHideDialog();
39 
40  private:
41   friend base::NoDestructor<DesktopMediaPickerManager>;
42 
43   DesktopMediaPickerManager();
44   ~DesktopMediaPickerManager();  // Never called.
45 
46   base::ObserverList<DesktopMediaPickerManager::DialogObserver> observers_;
47 
48   DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerManager);
49 };
50 
51 #endif  // CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_MANAGER_H_
52