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_NATIVE_DESKTOP_MEDIA_LIST_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_NATIVE_DESKTOP_MEDIA_LIST_H_
7 
8 #include <memory>
9 
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread.h"
12 #include "chrome/browser/media/webrtc/desktop_media_list_base.h"
13 #include "content/public/browser/desktop_media_id.h"
14 #include "ui/gfx/image/image.h"
15 
16 namespace webrtc {
17 class DesktopCapturer;
18 }
19 
20 // Implementation of DesktopMediaList that shows native screens and
21 // native windows.
22 class NativeDesktopMediaList : public DesktopMediaListBase {
23  public:
24   // |capturer| must exist.
25   NativeDesktopMediaList(content::DesktopMediaID::Type type,
26                          std::unique_ptr<webrtc::DesktopCapturer> capturer);
27   ~NativeDesktopMediaList() override;
28 
29  private:
30   typedef std::map<content::DesktopMediaID, uint32_t> ImageHashesMap;
31 
32   class Worker;
33   friend class Worker;
34 
35   // Refresh() posts a task for the |worker_| to update list of windows, get
36   // thumbnails and schedules next refresh.
37   void Refresh(bool update_thumnails) override;
38 
39   void RefreshForAuraWindows(std::vector<SourceDescription> sources,
40                              bool update_thumnails);
41   void UpdateNativeThumbnailsFinished();
42 
43 #if defined(USE_AURA)
44   void CaptureAuraWindowThumbnail(const content::DesktopMediaID& id);
45   void OnAuraThumbnailCaptured(const content::DesktopMediaID& id,
46                                gfx::Image image);
47 #endif
48 
49   base::Thread thread_;
50   std::unique_ptr<Worker> worker_;
51 
52 #if defined(USE_AURA)
53   // previous_aura_thumbnail_hashes_ holds thumbanil hash values of aura windows
54   // in the previous refresh. While new_aura_thumbnail_hashes_ has hash values
55   // of the ongoing refresh. Those two maps are used to detect new thumbnails
56   // and changed thumbnails from the previous refresh.
57   ImageHashesMap previous_aura_thumbnail_hashes_;
58   ImageHashesMap new_aura_thumbnail_hashes_;
59 
60   int pending_aura_capture_requests_ = 0;
61   bool pending_native_thumbnail_capture_ = false;
62 #endif
63   base::WeakPtrFactory<NativeDesktopMediaList> weak_factory_{this};
64 
65   DISALLOW_COPY_AND_ASSIGN(NativeDesktopMediaList);
66 };
67 
68 #endif  // CHROME_BROWSER_MEDIA_WEBRTC_NATIVE_DESKTOP_MEDIA_LIST_H_
69