Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / native_desktop_media_list.h
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_NATIVE_DESKTOP_MEDIA_LIST_H_
6 #define CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_
7
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"
15
16 namespace webrtc {
17 class ScreenCapturer;
18 class WindowCapturer;
19 }
20
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;
32
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;
40
41  private:
42   class Worker;
43   friend class Worker;
44
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);
48
49     content::DesktopMediaID id;
50     base::string16 name;
51   };
52
53   // Order comparator for sources. Used to sort list of sources.
54   static bool CompareSources(const SourceDescription& a,
55                              const SourceDescription& b);
56
57   // Post a task for the |worker_| to update list of windows and get thumbnails.
58   void Refresh();
59
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();
67
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_;
71
72   // Time interval between mode updates.
73   base::TimeDelta update_period_;
74
75   // Size of thumbnails generated by the model.
76   gfx::Size thumbnail_size_;
77
78   // ID of the hosting dialog.
79   content::DesktopMediaID::Id view_dialog_id_;
80
81   // The observer passed to StartUpdating().
82   DesktopMediaListObserver* observer_;
83
84   // Task runner used for the |worker_|.
85   scoped_refptr<base::SequencedTaskRunner> capture_task_runner_;
86
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_;
91
92   // Current list of sources.
93   std::vector<Source> sources_;
94
95   base::WeakPtrFactory<NativeDesktopMediaList> weak_factory_;
96
97   DISALLOW_COPY_AND_ASSIGN(NativeDesktopMediaList);
98 };
99
100 #endif  // CHROME_BROWSER_MEDIA_NATIVE_DESKTOP_MEDIA_LIST_H_