1 // Copyright 2013 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_LIST_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_
7 
8 #include <vector>
9 
10 #include "base/strings/string16.h"
11 #include "base/time/time.h"
12 #include "content/public/browser/desktop_media_id.h"
13 #include "ui/gfx/image/image_skia.h"
14 
15 class DesktopMediaListObserver;
16 
17 // DesktopMediaList provides the list of desktop media source (screens, windows,
18 // tabs), and their thumbnails, to the desktop media picker dialog. It
19 // transparently updates the list in the background, and notifies the desktop
20 // media picker when something changes.
21 //
22 // TODO(crbug.com/987001): Consider renaming this class.
23 class DesktopMediaList {
24  public:
25   // Struct used to represent each entry in the list.
26   struct Source {
27     // Id of the source.
28     content::DesktopMediaID id;
29 
30     // Name of the source that should be shown to the user.
31     base::string16 name;
32 
33     // The thumbnail for the source.
34     gfx::ImageSkia thumbnail;
35   };
36 
37   using UpdateCallback = base::OnceClosure;
38 
~DesktopMediaList()39   virtual ~DesktopMediaList() {}
40 
41   // Sets time interval between updates. By default list of sources and their
42   // thumbnail are updated once per second. If called after StartUpdating() then
43   // it will take effect only after the next update.
44   virtual void SetUpdatePeriod(base::TimeDelta period) = 0;
45 
46   // Sets size to which the thumbnails should be scaled. If called after
47   // StartUpdating() then some thumbnails may be still scaled to the old size
48   // until they are updated.
49   virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) = 0;
50 
51   // Sets ID of the hosting desktop picker dialog. The window with this ID will
52   // be filtered out from the list of sources.
53   virtual void SetViewDialogWindowId(content::DesktopMediaID dialog_id) = 0;
54 
55   // Starts updating the model. The model is initially empty, so OnSourceAdded()
56   // notifications will be generated for each existing source as it is
57   // enumerated. After the initial enumeration the model will be refreshed based
58   // on the update period, and notifications generated only for changes in the
59   // model.
60   virtual void StartUpdating(DesktopMediaListObserver* observer) = 0;
61 
62   // Updates the model and calls |callback| when all currently existing sources
63   // have been found, passing |this| as the argument.  In most respects, this is
64   // a simplified version of StartUpdating().  This method should only be called
65   // once per DesktopMediaList instance.  It should not be called after
66   // StartUpdating(), and StartUpdating() should not be called until |callback|
67   // has been called.
68   virtual void Update(UpdateCallback callback) = 0;
69 
70   virtual int GetSourceCount() const = 0;
71   virtual const Source& GetSource(int index) const = 0;
72 
73   virtual content::DesktopMediaID::Type GetMediaListType() const = 0;
74 };
75 
76 #endif  // CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_
77