Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: chrome/browser/media/media_stream_capture_indicator.h

Issue 12035046: Fix bug causing tab favicon media indicator to not turn off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ 6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
10 #include <utility>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/common/media_stream_request.h" 14 #include "content/public/common/media_stream_request.h"
14 #include "ui/base/models/simple_menu_model.h" 15 #include "ui/base/models/simple_menu_model.h"
15 #include "ui/gfx/image/image_skia.h"
16 16
17 namespace content { 17 namespace content {
18 class WebContents; 18 class WebContents;
19 } // namespace content 19 } // namespace content
20 20
21 namespace gfx {
22 class ImageSkia;
23 } // namespace gfx
24
21 class StatusIcon; 25 class StatusIcon;
22 class StatusTray; 26 class StatusTray;
23 27
24 // This indicator is owned by MediaInternals and deleted when MediaInternals 28 // This indicator is owned by MediaInternals and deleted when MediaInternals
25 // is deleted. 29 // is deleted.
26 class MediaStreamCaptureIndicator 30 class MediaStreamCaptureIndicator
27 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, 31 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>,
28 public ui::SimpleMenuModel::Delegate { 32 public ui::SimpleMenuModel::Delegate {
29 public: 33 public:
30 MediaStreamCaptureIndicator(); 34 MediaStreamCaptureIndicator();
31 35
32 // Overrides from SimpleMenuModel::Delegate implementation. 36 // Overrides from SimpleMenuModel::Delegate implementation.
33 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 37 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
34 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 38 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
35 virtual bool GetAcceleratorForCommandId( 39 virtual bool GetAcceleratorForCommandId(
36 int command_id, 40 int command_id,
37 ui::Accelerator* accelerator) OVERRIDE; 41 ui::Accelerator* accelerator) OVERRIDE;
38 virtual void ExecuteCommand(int command_id) OVERRIDE; 42 virtual void ExecuteCommand(int command_id) OVERRIDE;
39 43
40 // Called on IO thread when MediaStream opens new capture devices. 44 // Called on IO thread when MediaStream opens new capture devices.
41 void CaptureDevicesOpened(int render_process_id, 45 void CaptureDevicesOpened(int render_process_id,
42 int render_view_id, 46 int render_view_id,
43 const content::MediaStreamDevices& devices); 47 const content::MediaStreamDevices& devices);
44 48
45 // Called on IO thread when MediaStream closes the opened devices. 49 // Called on IO thread when MediaStream closes the opened devices.
46 void CaptureDevicesClosed(int render_process_id, 50 void CaptureDevicesClosed(int render_process_id,
47 int render_view_id, 51 int render_view_id,
48 const content::MediaStreamDevices& devices); 52 const content::MediaStreamDevices& devices);
49 53
50 // Returns true if the render process is capturing media. 54 // Returns true if the render view is capturing media.
51 bool IsProcessCapturing(int render_process_id, int render_view_id) const; 55 bool IsRenderViewCapturing(int render_process_id, int render_view_id) const;
52 56
53 // Returns true if the render process is capturing tab media. 57 // Returns true if the render view is being mirrored.
54 bool IsProcessCapturingTab(int render_process_id, int render_view_id) const; 58 bool IsRenderViewMirroring(int render_process_id, int render_view_id) const;
55 59
56 // ImageLoader callback. 60 // ImageLoader callback.
57 void OnImageLoaded(const string16& message, const gfx::Image& image); 61 void OnImageLoaded(const string16& message, const gfx::Image& image);
58 62
59 private: 63 private:
60 // Struct to store the usage information of the capture devices for each tab. 64 class CaptureDeviceUsage;
61 // Note: It is not safe to dereference WebContents pointer. This is used to
62 // track the tab after navigations as render_view_id's can change.
63 // TODO(estade): this should be called CaptureDeviceContents; not all the
64 // render views it represents are tabs.
65 struct CaptureDeviceTab {
66 CaptureDeviceTab(content::WebContents* web_contents,
67 int render_process_id,
68 int render_view_id)
69 : web_contents(web_contents),
70 render_process_id(render_process_id),
71 render_view_id(render_view_id),
72 audio_ref_count(0),
73 video_ref_count(0),
74 tab_capture_ref_count(0) {}
75
76 content::WebContents* web_contents;
77 int render_process_id;
78 int render_view_id;
79 int audio_ref_count;
80 int video_ref_count;
81 int tab_capture_ref_count;
82 };
83
84 // A private predicate used in std::find_if to find a |CaptureDeviceTab|
85 // which matches the information specified at construction. A tab will match
86 // if either the web_contents pointer is the same or the render_process_id and
87 // render_view_id's are the same. In the first case, a tab with a UI indicator
88 // may have changed page so the id's are different. In the second case, the
89 // web_contents may have already been destroyed before the indicator was
90 // hidden.
91 class TabEquals {
92 public:
93 TabEquals(content::WebContents* web_contents,
94 int render_process_id,
95 int render_view_id);
96
97 bool operator() (
98 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab);
99
100 private:
101 content::WebContents* web_contents_;
102 int render_process_id_;
103 int render_view_id_;
104 };
105 65
106 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>; 66 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>;
107 virtual ~MediaStreamCaptureIndicator(); 67 virtual ~MediaStreamCaptureIndicator();
108 68
109 // Called by the public functions, executed on UI thread. 69 // Called by the public functions, executed on UI thread.
110 void DoDevicesOpenedOnUIThread(int render_process_id, 70 void DoDevicesOpenedOnUIThread(int render_process_id,
111 int render_view_id, 71 int render_view_id,
112 const content::MediaStreamDevices& devices); 72 const content::MediaStreamDevices& devices);
113 void DoDevicesClosedOnUIThread(int render_process_id, 73 void DoDevicesClosedOnUIThread(int render_process_id,
114 int render_view_id, 74 int render_view_id,
115 const content::MediaStreamDevices& devices); 75 const content::MediaStreamDevices& devices);
116 76
117 // Following functions/variables are executed/accessed only on UI thread. 77 // Following functions/variables are executed/accessed only on UI thread.
118 // Creates the status tray if it has not been created. 78
119 void CreateStatusTray(); 79 // Creates and shows the status tray icon if it has not been created and is
80 // supported on the current platform.
81 void MaybeCreateStatusTrayIcon();
120 82
121 // Makes sure we have done one-time initialization of the images. 83 // Makes sure we have done one-time initialization of the images.
122 void EnsureStatusTrayIconResources(); 84 void EnsureStatusTrayIconResources();
123 85
124 // Adds the new tab to the device usage list. 86 // Finds a WebContents instance by its RenderView's current or
125 void AddCaptureDeviceTab(int render_process_id, 87 // previously-known IDs. This is necessary since clients that called
126 int render_view_id, 88 // CaptureDevicesOpened() may later call CaptureDevicesClosed() with stale
127 const content::MediaStreamDevices& devices); 89 // IDs.
90 content::WebContents* LookUpByKnownAlias(int render_process_id,
91 int render_view_id) const;
128 92
129 // Removes the tab from the device usage list. 93 // Adds devices to usage map and triggers necessary UI updates.
130 void RemoveCaptureDeviceTab(int render_process_id, 94 void AddCaptureDevices(int render_process_id,
131 int render_view_id, 95 int render_view_id,
132 const content::MediaStreamDevices& devices); 96 const content::MediaStreamDevices& devices);
97
98 // Removes devices from the usage map and triggers necessary UI updates.
99 void RemoveCaptureDevices(int render_process_id,
100 int render_view_id,
101 const content::MediaStreamDevices& devices);
133 102
134 // Triggers a balloon in the corner telling capture devices are being used. 103 // Triggers a balloon in the corner telling capture devices are being used.
135 // This function is called by AddCaptureDeviceTab(). 104 // This function is called by AddCaptureDevices().
136 void ShowBalloon(int render_process_id, int render_view_id, 105 void ShowBalloon(content::WebContents* web_contents, bool audio, bool video);
137 bool audio, bool video);
138 106
139 // Hides the status tray from the desktop. This function is called by 107 // Removes the status tray icon from the desktop. This function is called by
140 // RemoveCaptureDeviceTab() when the device usage list becomes empty. 108 // RemoveCaptureDevices() when the device usage map becomes empty.
141 void Hide(); 109 void MaybeDestroyStatusTrayIcon();
142 110
143 // Updates the status tray menu with the new device list. This call will be 111 // Updates the status tray menu with the new device list. This call will be
144 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). 112 // triggered by both AddCaptureDevices() and RemoveCaptureDevices().
145 void UpdateStatusTrayIconContextMenu(); 113 void UpdateStatusTrayIconContextMenu();
146 114
147 // Updates the status tray tooltip and image according to which kind of 115 // Updates the status tray tooltip and image according to which kind of
148 // devices are being used. This function is called by 116 // devices are being used. This function is called by
149 // UpdateStatusTrayIconContextMenu(). 117 // UpdateStatusTrayIconContextMenu().
150 void UpdateStatusTrayIconDisplay(bool audio, bool video); 118 void UpdateStatusTrayIconDisplay(bool audio, bool video);
151 119
152 // Reference to our status icon - owned by the StatusTray. If null, 120 // Reference to our status icon - owned by the StatusTray. If null,
153 // the platform doesn't support status icons. 121 // the platform doesn't support status icons.
154 StatusIcon* status_icon_; 122 StatusIcon* status_icon_;
155 123
156 // These images are owned by ResourceBundle and need not be destroyed. 124 // These images are owned by ResourceBundle and need not be destroyed.
157 gfx::ImageSkia* mic_image_; 125 gfx::ImageSkia* mic_image_;
158 gfx::ImageSkia* camera_image_; 126 gfx::ImageSkia* camera_image_;
159 gfx::ImageSkia* balloon_image_; 127 gfx::ImageSkia* balloon_image_;
160 128
161 // A list that contains the usage information of the opened capture devices. 129 // A map that contains the usage counts of the opened capture devices for each
162 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; 130 // WebContents instance.
163 CaptureDeviceTabs tabs_; 131 typedef std::map<content::WebContents*, CaptureDeviceUsage*> UsageMap;
132 UsageMap usage_map_;
133
134 // A map of known render_process_id/render_view_id pairs that have been
135 // associated with a WebContents instance.
136 typedef std::pair<int, int> RenderViewIDs;
137 typedef std::map<RenderViewIDs, content::WebContents*> AliasMap;
138 AliasMap aliases_;
139
140 // A map from command_ids to their associated WebContents instance. This is
141 // rebuilt each time the status tray icon context menu is updated.
142 typedef std::vector<content::WebContents*> CommandMap;
143 CommandMap command_map_;
164 144
165 bool should_show_balloon_; 145 bool should_show_balloon_;
166 }; 146 };
167 147
168 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ 148 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698