[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / media / native_desktop_media_list.h
blob8d7a1cb68fd6a47dce22683e7745d56b7866d9d6
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 virtual ~NativeDesktopMediaList();
33 // DesktopMediaList interface.
34 virtual void SetUpdatePeriod(base::TimeDelta period) OVERRIDE;
35 virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) OVERRIDE;
36 virtual void StartUpdating(DesktopMediaListObserver* observer) OVERRIDE;
37 virtual int GetSourceCount() const OVERRIDE;
38 virtual const Source& GetSource(int index) const OVERRIDE;
39 virtual void SetViewDialogWindowId(
40 content::DesktopMediaID::Id dialog_id) OVERRIDE;
42 private:
43 class Worker;
44 friend class Worker;
46 // Struct used to represent sources list the model gets from the Worker.
47 struct SourceDescription {
48 SourceDescription(content::DesktopMediaID id, const base::string16& name);
50 content::DesktopMediaID id;
51 base::string16 name;
54 // Order comparator for sources. Used to sort list of sources.
55 static bool CompareSources(const SourceDescription& a,
56 const SourceDescription& b);
58 // Post a task for the |worker_| to update list of windows and get thumbnails.
59 void Refresh();
61 // Called by |worker_| to refresh the model. First it posts tasks for
62 // OnSourcesList() with the fresh list of sources, then follows with
63 // OnSourceThumbnail() for each changed thumbnail and then calls
64 // OnRefreshFinished() at the end.
65 void OnSourcesList(const std::vector<SourceDescription>& sources);
66 void OnSourceThumbnail(int index, const gfx::ImageSkia& thumbnail);
67 void OnRefreshFinished();
69 // Capturers specified in SetCapturers() and passed to the |worker_| later.
70 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_;
71 scoped_ptr<webrtc::WindowCapturer> window_capturer_;
73 // Time interval between mode updates.
74 base::TimeDelta update_period_;
76 // Size of thumbnails generated by the model.
77 gfx::Size thumbnail_size_;
79 // ID of the hosting dialog.
80 content::DesktopMediaID::Id view_dialog_id_;
82 // The observer passed to StartUpdating().
83 DesktopMediaListObserver* observer_;
85 // Task runner used for the |worker_|.
86 scoped_refptr<base::SequencedTaskRunner> capture_task_runner_;
88 // An object that does all the work of getting list of sources on a background
89 // thread (see |capture_task_runner_|). Destroyed on |capture_task_runner_|
90 // after the model is destroyed.
91 scoped_ptr<Worker> worker_;
93 // Current list of sources.
94 std::vector<Source> sources_;
96 base::WeakPtrFactory<NativeDesktopMediaList> weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(NativeDesktopMediaList);
101 #endif // CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_