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