Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / media / media_stream_capture_indicator.h
blob85dc0eb2ad0029988a8d302a650ced505563bbc1
1 // Copyright (c) 2012 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_MEDIA_STREAM_CAPTURE_INDICATOR_H_
6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
8 #include <map>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h"
15 #include "chrome/browser/status_icons/status_icon_menu_model.h"
16 #include "content/public/common/media_stream_request.h"
18 namespace content {
19 class WebContents;
20 } // namespace content
22 namespace gfx {
23 class ImageSkia;
24 } // namespace gfx
26 class StatusIcon;
27 class StatusTray;
29 // This indicator is owned by MediaCaptureDevicesDispatcher
30 // (MediaCaptureDevicesDispatcher is a singleton).
31 class MediaStreamCaptureIndicator
32 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>,
33 public StatusIconMenuModel::Delegate {
34 public:
35 MediaStreamCaptureIndicator();
37 // Registers a new media stream for |web_contents| and returns UI object
38 // that's used by the content layer to notify about state of the stream.
39 scoped_ptr<content::MediaStreamUI> RegisterMediaStream(
40 content::WebContents* web_contents,
41 const content::MediaStreamDevices& devices);
43 // Overrides from StatusIconMenuModel::Delegate implementation.
44 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
46 // Returns true if the |web_contents| is capturing user media (e.g., webcam or
47 // microphone input).
48 bool IsCapturingUserMedia(content::WebContents* web_contents) const;
50 // Returns true if the |web_contents| is capturing video (e.g., webcam).
51 bool IsCapturingVideo(content::WebContents* web_contents) const;
53 // Returns true if the |web_contents| is capturing audio (e.g., microphone).
54 bool IsCapturingAudio(content::WebContents* web_contents) const;
56 // Returns true if the |web_contents| itself is being mirrored (e.g., a source
57 // of media for remote broadcast).
58 bool IsBeingMirrored(content::WebContents* web_contents) const;
60 private:
61 class UIDelegate;
62 class WebContentsDeviceUsage;
63 friend class WebContentsDeviceUsage;
65 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>;
66 virtual ~MediaStreamCaptureIndicator();
68 // Following functions/variables are executed/accessed only on UI thread.
70 // Called by WebContentsDeviceUsage when it's about to destroy itself, i.e.
71 // when WebContents is being destroyed.
72 void UnregisterWebContents(content::WebContents* web_contents);
74 // Updates the status tray menu. Called by WebContentsDeviceUsage.
75 void UpdateNotificationUserInterface();
77 // Helpers to create and destroy status tray icon. Called from
78 // UpdateNotificationUserInterface().
79 void EnsureStatusTrayIconResources();
80 void MaybeCreateStatusTrayIcon(bool audio, bool video);
81 void MaybeDestroyStatusTrayIcon();
83 // Gets the status icon image and the string to use as the tooltip.
84 void GetStatusTrayIconInfo(bool audio,
85 bool video,
86 gfx::ImageSkia* image,
87 base::string16* tool_tip);
89 // Reference to our status icon - owned by the StatusTray. If null,
90 // the platform doesn't support status icons.
91 StatusIcon* status_icon_;
93 // These images are owned by ResourceBundle and need not be destroyed.
94 gfx::ImageSkia* mic_image_;
95 gfx::ImageSkia* camera_image_;
97 // A map that contains the usage counts of the opened capture devices for each
98 // WebContents instance.
99 typedef std::map<content::WebContents*, WebContentsDeviceUsage*> UsageMap;
100 UsageMap usage_map_;
102 // A vector which maps command IDs to their associated WebContents
103 // instance. This is rebuilt each time the status tray icon context menu is
104 // updated.
105 typedef std::vector<content::WebContents*> CommandTargets;
106 CommandTargets command_targets_;
109 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_