Prevent chrome://net-internals/#export from flickering
[chromium-blink-merge.git] / chrome / browser / media / native_desktop_media_list.h
blob81bd32152813160ac1604f3555b1f56dbe28a57d
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.
5 #ifndef CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_
6 #define CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_
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 "chrome/browser/media/desktop_media_list.h"
13 #include "content/public/browser/desktop_media_id.h"
14 #include "ui/gfx/image/image_skia.h"
16 namespace webrtc {
17 class ScreenCapturer;
18 class WindowCapturer;
21 // Implementation of DesktopMediaList that shows native screens and
22 // native windows.
23 class NativeDesktopMediaList : public DesktopMediaList {
24 public:
25 // Caller may pass NULL for either of the arguments in case when only some
26 // types of sources the model should be populated with (e.g. it will only
27 // contain windows, if |screen_capturer| is NULL).
28 NativeDesktopMediaList(
29 scoped_ptr<webrtc::ScreenCapturer> screen_capturer,
30 scoped_ptr<webrtc::WindowCapturer> window_capturer);
31 ~NativeDesktopMediaList() override;
33 // DesktopMediaList interface.
34 void SetUpdatePeriod(base::TimeDelta period) override;
35 void SetThumbnailSize(const gfx::Size& thumbnail_size) override;
36 void StartUpdating(DesktopMediaListObserver* observer) override;
37 int GetSourceCount() const override;
38 const Source& GetSource(int index) const override;
39 void SetViewDialogWindowId(content::DesktopMediaID::Id dialog_id) override;
41 private:
42 class Worker;
43 friend class Worker;
45 // Struct used to represent sources list the model gets from the Worker.
46 struct SourceDescription {
47 SourceDescription(content::DesktopMediaID id, const base::string16& name);
49 content::DesktopMediaID id;
50 base::string16 name;
53 // Order comparator for sources. Used to sort list of sources.
54 static bool CompareSources(const SourceDescription& a,
55 const SourceDescription& b);
57 // Post a task for the |worker_| to update list of windows and get thumbnails.
58 void Refresh();
60 // Called by |worker_| to refresh the model. First it posts tasks for
61 // OnSourcesList() with the fresh list of sources, then follows with
62 // OnSourceThumbnail() for each changed thumbnail and then calls
63 // OnRefreshFinished() at the end.
64 void OnSourcesList(const std::vector<SourceDescription>& sources);
65 void OnSourceThumbnail(int index, const gfx::ImageSkia& thumbnail);
66 void OnRefreshFinished();
68 // Capturers specified in SetCapturers() and passed to the |worker_| later.
69 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_;
70 scoped_ptr<webrtc::WindowCapturer> window_capturer_;
72 // Time interval between mode updates.
73 base::TimeDelta update_period_;
75 // Size of thumbnails generated by the model.
76 gfx::Size thumbnail_size_;
78 // ID of the hosting dialog.
79 content::DesktopMediaID::Id view_dialog_id_;
81 // The observer passed to StartUpdating().
82 DesktopMediaListObserver* observer_;
84 // Task runner used for the |worker_|.
85 scoped_refptr<base::SequencedTaskRunner> capture_task_runner_;
87 // An object that does all the work of getting list of sources on a background
88 // thread (see |capture_task_runner_|). Destroyed on |capture_task_runner_|
89 // after the model is destroyed.
90 scoped_ptr<Worker> worker_;
92 // Current list of sources.
93 std::vector<Source> sources_;
95 base::WeakPtrFactory<NativeDesktopMediaList> weak_factory_;
97 DISALLOW_COPY_AND_ASSIGN(NativeDesktopMediaList);
100 #endif // CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_