OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ |
6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ | 6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "content/public/common/desktop_media_id.h" | 12 #include "content/public/common/desktop_media_id.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 class ScreenCapturer; | 16 class ScreenCapturer; |
17 class WindowCapturer; | 17 class WindowCapturer; |
18 } | 18 } |
19 | 19 |
20 // DesktopMediaPickerModel provides the list of desktop media source (screens, | 20 // Interface for DesktopMediaPickerModel, which provides the list of desktop |
21 // windows, tabs), and their thumbnails, to the desktop media picker dialog. It | 21 // media source (screens, windows, tabs), and their thumbnails, to the desktop |
22 // transparently updates the list in the background, and notifies the desktop | 22 // media picker dialog. It transparently updates the list in the background, and |
23 // media picker when something changes. | 23 // notifies the desktop media picker when something changes. |
24 class DesktopMediaPickerModel { | 24 class DesktopMediaPickerModelInterface { |
Sergey Ulanov
2013/09/04 20:39:00
We don't normally use "Interface" suffix in chromi
dcaiafa
2013/09/04 22:41:38
Done.
| |
25 public: | 25 public: |
26 virtual ~DesktopMediaPickerModelInterface() {} | |
27 | |
26 // Interface implemented by the picker dialog to receive notifications when | 28 // Interface implemented by the picker dialog to receive notifications when |
27 // the model's contents change. | 29 // the model's contents change. |
28 class Observer { | 30 class Observer { |
29 public: | 31 public: |
30 virtual ~Observer() {} | 32 virtual ~Observer() {} |
31 | 33 |
32 virtual void OnSourceAdded(int index) = 0; | 34 virtual void OnSourceAdded(int index) = 0; |
33 virtual void OnSourceRemoved(int index) = 0; | 35 virtual void OnSourceRemoved(int index) = 0; |
34 virtual void OnSourceNameChanged(int index) = 0; | 36 virtual void OnSourceNameChanged(int index) = 0; |
35 virtual void OnSourceThumbnailChanged(int index) = 0; | 37 virtual void OnSourceThumbnailChanged(int index) = 0; |
36 }; | 38 }; |
37 | 39 |
38 // Struct used to represent each entry in the model. | 40 // Struct used to represent each entry in the model. |
39 struct Source { | 41 struct Source { |
40 Source(content::DesktopMediaID id, const string16& name); | 42 Source(content::DesktopMediaID id, const string16& name); |
41 | 43 |
42 // Id of the source. | 44 // Id of the source. |
43 content::DesktopMediaID id; | 45 content::DesktopMediaID id; |
44 | 46 |
45 // Name of the source that should be shown to the user. | 47 // Name of the source that should be shown to the user. |
46 string16 name; | 48 string16 name; |
47 | 49 |
48 // The thumbnail for the source. | 50 // The thumbnail for the source. |
49 gfx::ImageSkia thumbnail; | 51 gfx::ImageSkia thumbnail; |
50 }; | 52 }; |
51 | 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 // Starts updating the model. The model is initially empty, so OnSourceAdded() | |
65 // notifications will be generated for each existing source as it is | |
66 // enumerated. After the initial enumeration the model will be refreshed based | |
67 // on the update period, and notifications generated only for changes in the | |
68 // model. | |
69 virtual void StartUpdating(Observer* observer) = 0; | |
70 | |
71 virtual int source_count() const = 0; | |
72 virtual const Source& source(int index) const = 0; | |
73 | |
74 private: | |
75 DISALLOW_ASSIGN(DesktopMediaPickerModelInterface); | |
76 }; | |
77 | |
78 class DesktopMediaPickerModel : public DesktopMediaPickerModelInterface { | |
79 public: | |
52 // Caller may pass NULL for either of the arguments in case when only some | 80 // Caller may pass NULL for either of the arguments in case when only some |
53 // types of sources the model should be populated with (e.g. it will only | 81 // types of sources the model should be populated with (e.g. it will only |
54 // contain windows, if |screen_capturer| is NULL). | 82 // contain windows, if |screen_capturer| is NULL). |
55 DesktopMediaPickerModel(scoped_ptr<webrtc::ScreenCapturer> screen_capturer, | 83 DesktopMediaPickerModel(scoped_ptr<webrtc::ScreenCapturer> screen_capturer, |
56 scoped_ptr<webrtc::WindowCapturer> window_capturer); | 84 scoped_ptr<webrtc::WindowCapturer> window_capturer); |
57 virtual ~DesktopMediaPickerModel(); | 85 virtual ~DesktopMediaPickerModel(); |
58 | 86 |
59 // Sets time interval between updates. By default list of sources and their | 87 // DesktopMediaPickerModelInterface: |
60 // thumbnail are updated once per second. If called after StartUpdating() then | 88 virtual void SetUpdatePeriod(base::TimeDelta period) OVERRIDE; |
61 // it will take effect only after the next update. | 89 virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) OVERRIDE; |
62 void SetUpdatePeriod(base::TimeDelta period); | 90 virtual void StartUpdating(Observer* observer) OVERRIDE; |
63 | 91 virtual int source_count() const OVERRIDE; |
64 // Sets size to which the thumbnails should be scaled. If called after | 92 virtual const Source& source(int index) const OVERRIDE; |
65 // StartUpdating() then some thumbnails may be still scaled to the old size | |
66 // until they are updated. | |
67 void SetThumbnailSize(const gfx::Size& thumbnail_size); | |
68 | |
69 // Starts updating the model. The model is initially empty, so OnSourceAdded() | |
70 // notifications will be generated for each existing source as it is | |
71 // enumerated. After the initial enumeration the model will be refreshed based | |
72 // on the update period, and notifications generated only for changes in the | |
73 // model. | |
74 void StartUpdating(Observer* observer); | |
75 | |
76 int source_count() const { return sources_.size(); } | |
77 const Source& source(int index) const { return sources_.at(index); } | |
78 | 93 |
79 private: | 94 private: |
80 class Worker; | 95 class Worker; |
81 friend class Worker; | 96 friend class Worker; |
82 | 97 |
83 // Struct used to represent sources list the model gets from the Worker. | 98 // Struct used to represent sources list the model gets from the Worker. |
84 struct SourceDescription { | 99 struct SourceDescription { |
85 SourceDescription(content::DesktopMediaID id, const string16& name); | 100 SourceDescription(content::DesktopMediaID id, const string16& name); |
86 | 101 |
87 content::DesktopMediaID id; | 102 content::DesktopMediaID id; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 141 |
127 // Current list of sources. | 142 // Current list of sources. |
128 std::vector<Source> sources_; | 143 std::vector<Source> sources_; |
129 | 144 |
130 base::WeakPtrFactory<DesktopMediaPickerModel> weak_factory_; | 145 base::WeakPtrFactory<DesktopMediaPickerModel> weak_factory_; |
131 | 146 |
132 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModel); | 147 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModel); |
133 }; | 148 }; |
134 | 149 |
135 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ | 150 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_PICKER_MODEL_H_ |
OLD | NEW |