Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/media/desktop_media_picker_model.h

Issue 89683003: Rename DesktopMediaPickerModel[Impl]->[Native]DesktopMediaList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_DESKTOP_MEDIA_PICKER_MODEL_H_
6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/sequenced_task_runner.h"
12 #include "content/public/common/desktop_media_id.h"
13 #include "ui/gfx/image/image_skia.h"
14
15 namespace webrtc {
16 class ScreenCapturer;
17 class WindowCapturer;
18 }
19
20 // DesktopMediaPickerModel provides the list of desktop media source (screens,
21 // windows, tabs), and their thumbnails, to the desktop media picker dialog. It
22 // transparently updates the list in the background, and notifies the desktop
23 // media picker when something changes.
24 class DesktopMediaPickerModel {
25 public:
26 // Interface implemented by the picker dialog to receive notifications when
27 // the model's contents change.
28 class Observer {
29 public:
30 virtual ~Observer() {}
31
32 virtual void OnSourceAdded(int index) = 0;
33 virtual void OnSourceRemoved(int index) = 0;
34 virtual void OnSourceNameChanged(int index) = 0;
35 virtual void OnSourceThumbnailChanged(int index) = 0;
36 };
37
38 // Struct used to represent each entry in the model.
39 struct Source {
40 Source(content::DesktopMediaID id, const string16& name);
41
42 // Id of the source.
43 content::DesktopMediaID id;
44
45 // Name of the source that should be shown to the user.
46 string16 name;
47
48 // The thumbnail for the source.
49 gfx::ImageSkia thumbnail;
50 };
51
52 virtual ~DesktopMediaPickerModel() {}
53
54 // Sets time interval between updates. By default list of sources and their
55 // thumbnail are updated once per second. If called after StartUpdating() then
56 // it will take effect only after the next update.
57 virtual void SetUpdatePeriod(base::TimeDelta period) = 0;
58
59 // Sets size to which the thumbnails should be scaled. If called after
60 // StartUpdating() then some thumbnails may be still scaled to the old size
61 // until they are updated.
62 virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) = 0;
63
64 // Sets ID of the hosting desktop picker dialog. The window with this ID will
65 // be filtered out from the list of sources.
66 virtual void SetViewDialogWindowId(content::DesktopMediaID::Id dialog_id) = 0;
67
68 // Starts updating the model. The model is initially empty, so OnSourceAdded()
69 // notifications will be generated for each existing source as it is
70 // enumerated. After the initial enumeration the model will be refreshed based
71 // on the update period, and notifications generated only for changes in the
72 // model.
73 virtual void StartUpdating(Observer* observer) = 0;
74
75 virtual int source_count() const = 0;
76 virtual const Source& source(int index) const = 0;
77 };
78
79 class DesktopMediaPickerModelImpl : public DesktopMediaPickerModel {
80 public:
81 // Caller may pass NULL for either of the arguments in case when only some
82 // types of sources the model should be populated with (e.g. it will only
83 // contain windows, if |screen_capturer| is NULL).
84 DesktopMediaPickerModelImpl(
85 scoped_ptr<webrtc::ScreenCapturer> screen_capturer,
86 scoped_ptr<webrtc::WindowCapturer> window_capturer);
87 virtual ~DesktopMediaPickerModelImpl();
88
89 // DesktopMediaPickerModel interface.
90 virtual void SetUpdatePeriod(base::TimeDelta period) OVERRIDE;
91 virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) OVERRIDE;
92 virtual void StartUpdating(Observer* observer) OVERRIDE;
93 virtual int source_count() const OVERRIDE;
94 virtual const Source& source(int index) const OVERRIDE;
95 virtual void SetViewDialogWindowId(
96 content::DesktopMediaID::Id dialog_id) OVERRIDE;
97
98 private:
99 class Worker;
100 friend class Worker;
101
102 // Struct used to represent sources list the model gets from the Worker.
103 struct SourceDescription {
104 SourceDescription(content::DesktopMediaID id, const string16& name);
105
106 content::DesktopMediaID id;
107 string16 name;
108 };
109
110 // Order comparator for sources. Used to sort list of sources.
111 static bool CompareSources(const SourceDescription& a,
112 const SourceDescription& b);
113
114 // Post a task for the |worker_| to update list of windows and get thumbnails.
115 void Refresh();
116
117 // Called by |worker_| to refresh the model. First it posts tasks for
118 // OnSourcesList() with the fresh list of sources, then follows with
119 // OnSourceThumbnail() for each changed thumbnail and then calls
120 // OnRefreshFinished() at the end.
121 void OnSourcesList(const std::vector<SourceDescription>& sources);
122 void OnSourceThumbnail(int index, const gfx::ImageSkia& thumbnail);
123 void OnRefreshFinished();
124
125 // Capturers specified in SetCapturers() and passed to the |worker_| later.
126 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_;
127 scoped_ptr<webrtc::WindowCapturer> window_capturer_;
128
129 // Time interval between mode updates.
130 base::TimeDelta update_period_;
131
132 // Size of thumbnails generated by the model.
133 gfx::Size thumbnail_size_;
134
135 // ID of the hosting dialog.
136 content::DesktopMediaID::Id view_dialog_id_;
137
138 // The observer passed to StartUpdating().
139 Observer* observer_;
140
141 // Task runner used for the |worker_|.
142 scoped_refptr<base::SequencedTaskRunner> capture_task_runner_;
143
144 // An object that does all the work of getting list of sources on a background
145 // thread (see |capture_task_runner_|). Destroyed on |capture_task_runner_|
146 // after the model is destroyed.
147 scoped_ptr<Worker> worker_;
148
149 // Current list of sources.
150 std::vector<Source> sources_;
151
152 base::WeakPtrFactory<DesktopMediaPickerModelImpl> weak_factory_;
153
154 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModelImpl);
155 };
156
157 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/desktop_media_picker.h ('k') | chrome/browser/media/desktop_media_picker_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698