OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_LIST_BASE_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_BASE_H_ |
6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_BASE_H_ | 6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_BASE_H_ |
7 | 7 |
8 #include "chrome/browser/media/desktop_media_list.h" | 8 #include "chrome/browser/media/desktop_media_list.h" |
9 #include "content/public/browser/desktop_media_id.h" | 9 #include "content/public/browser/desktop_media_id.h" |
10 #include "ui/gfx/image/image.h" | |
11 | |
12 using content::DesktopMediaID; | |
Sergey Ulanov
2016/03/10 00:46:07
using is not allowed in headers. Please use fully
GeorgeZ
2016/03/10 21:18:46
Done.
| |
10 | 13 |
11 // Thumbnail size is 100*100 pixels | 14 // Thumbnail size is 100*100 pixels |
12 static const int kDefaultThumbnailSize = 100; | 15 static const int kDefaultThumbnailSize = 100; |
13 | 16 |
14 // Base class for DesktopMediaList implementations. Implements logic shared | 17 // Base class for DesktopMediaList implementations. Implements logic shared |
15 // between implementations. Specifically it's responsible for keeping current | 18 // between implementations. Specifically it's responsible for keeping current |
16 // list of sources and calling the observer when the list changes. | 19 // list of sources and calling the observer when the list changes. |
17 class DesktopMediaListBase : public DesktopMediaList { | 20 class DesktopMediaListBase : public DesktopMediaList { |
18 public: | 21 public: |
19 explicit DesktopMediaListBase(base::TimeDelta update_period); | 22 explicit DesktopMediaListBase(base::TimeDelta update_period); |
20 ~DesktopMediaListBase() override; | 23 ~DesktopMediaListBase() override; |
21 | 24 |
22 // DesktopMediaList interface. | 25 // DesktopMediaList interface. |
23 void SetUpdatePeriod(base::TimeDelta period) override; | 26 void SetUpdatePeriod(base::TimeDelta period) override; |
24 void SetThumbnailSize(const gfx::Size& thumbnail_size) override; | 27 void SetThumbnailSize(const gfx::Size& thumbnail_size) override; |
25 void SetViewDialogWindowId(content::DesktopMediaID dialog_id) override; | 28 void SetViewDialogWindowId(DesktopMediaID dialog_id) override; |
26 void StartUpdating(DesktopMediaListObserver* observer) override; | 29 void StartUpdating(DesktopMediaListObserver* observer) override; |
27 int GetSourceCount() const override; | 30 int GetSourceCount() const override; |
28 const Source& GetSource(int index) const override; | 31 const Source& GetSource(int index) const override; |
29 | 32 |
33 static uint32_t GetImageHash(const gfx::Image& image); | |
34 | |
30 protected: | 35 protected: |
31 struct SourceDescription { | 36 struct SourceDescription { |
32 SourceDescription(content::DesktopMediaID id, const base::string16& name); | 37 SourceDescription(DesktopMediaID id, const base::string16& name); |
33 | 38 |
34 content::DesktopMediaID id; | 39 DesktopMediaID id; |
35 base::string16 name; | 40 base::string16 name; |
36 }; | 41 }; |
37 | 42 |
38 virtual void Refresh() = 0; | 43 virtual void Refresh() = 0; |
39 | 44 |
40 // Update source media list to observer. | 45 // Update source media list to observer. |
41 void UpdateSourcesList(const std::vector<SourceDescription>& new_sources); | 46 void UpdateSourcesList(const std::vector<SourceDescription>& new_sources); |
42 | 47 |
43 // Update a thumbnail to observer. | 48 // Update a thumbnail to observer. |
44 void UpdateSourceThumbnail(content::DesktopMediaID id, | 49 void UpdateSourceThumbnail(DesktopMediaID id, const gfx::ImageSkia& image); |
45 const gfx::ImageSkia& image); | |
46 | 50 |
47 // Post a task for next list update. | 51 // Post a task for next list update. |
48 void ScheduleNextRefresh(); | 52 void ScheduleNextRefresh(); |
49 | 53 |
50 // Size of thumbnails generated by the model. | 54 // Size of thumbnails generated by the model. |
51 gfx::Size thumbnail_size_ = | 55 gfx::Size thumbnail_size_ = |
52 gfx::Size(kDefaultThumbnailSize, kDefaultThumbnailSize); | 56 gfx::Size(kDefaultThumbnailSize, kDefaultThumbnailSize); |
53 | 57 |
54 // ID of the hosting dialog. | 58 // ID of the hosting dialog. |
55 content::DesktopMediaID view_dialog_id_ = | 59 DesktopMediaID view_dialog_id_ = |
56 content::DesktopMediaID(content::DesktopMediaID::TYPE_NONE, -1); | 60 DesktopMediaID(DesktopMediaID::TYPE_NONE, -1); |
57 | 61 |
58 private: | 62 private: |
59 // Time interval between mode updates. | 63 // Time interval between mode updates. |
60 base::TimeDelta update_period_; | 64 base::TimeDelta update_period_; |
61 | 65 |
62 // Current list of sources. | 66 // Current list of sources. |
63 std::vector<Source> sources_; | 67 std::vector<Source> sources_; |
64 | 68 |
65 // The observer passed to StartUpdating(). | 69 // The observer passed to StartUpdating(). |
66 DesktopMediaListObserver* observer_ = nullptr; | 70 DesktopMediaListObserver* observer_ = nullptr; |
67 | 71 |
68 base::WeakPtrFactory<DesktopMediaListBase> weak_factory_; | 72 base::WeakPtrFactory<DesktopMediaListBase> weak_factory_; |
69 | 73 |
70 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListBase); | 74 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListBase); |
71 }; | 75 }; |
72 | 76 |
73 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_BASE_H_ | 77 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_BASE_H_ |
OLD | NEW |