OLD | NEW |
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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/extensions/image_loading_tracker.h" | |
14 #include "content/public/common/media_stream_request.h" | 13 #include "content/public/common/media_stream_request.h" |
15 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
16 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
17 | 16 |
18 class StatusIcon; | 17 class StatusIcon; |
19 class StatusTray; | 18 class StatusTray; |
20 | 19 |
21 // This indicator is owned by MediaInternals and deleted when MediaInternals | 20 // This indicator is owned by MediaInternals and deleted when MediaInternals |
22 // is deleted. | 21 // is deleted. |
23 class MediaStreamCaptureIndicator | 22 class MediaStreamCaptureIndicator |
24 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, | 23 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, |
25 public ui::SimpleMenuModel::Delegate, | 24 public ui::SimpleMenuModel::Delegate { |
26 public ImageLoadingTracker::Observer { | |
27 public: | 25 public: |
28 MediaStreamCaptureIndicator(); | 26 MediaStreamCaptureIndicator(); |
29 | 27 |
30 // Overrides from SimpleMenuModel::Delegate implementation. | 28 // Overrides from SimpleMenuModel::Delegate implementation. |
31 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 29 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
32 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 30 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
33 virtual bool GetAcceleratorForCommandId( | 31 virtual bool GetAcceleratorForCommandId( |
34 int command_id, | 32 int command_id, |
35 ui::Accelerator* accelerator) OVERRIDE; | 33 ui::Accelerator* accelerator) OVERRIDE; |
36 virtual void ExecuteCommand(int command_id) OVERRIDE; | 34 virtual void ExecuteCommand(int command_id) OVERRIDE; |
37 | 35 |
38 // Called on IO thread when MediaStream opens new capture devices. | 36 // Called on IO thread when MediaStream opens new capture devices. |
39 void CaptureDevicesOpened(int render_process_id, | 37 void CaptureDevicesOpened(int render_process_id, |
40 int render_view_id, | 38 int render_view_id, |
41 const content::MediaStreamDevices& devices); | 39 const content::MediaStreamDevices& devices); |
42 | 40 |
43 // Called on IO thread when MediaStream closes the opened devices. | 41 // Called on IO thread when MediaStream closes the opened devices. |
44 void CaptureDevicesClosed(int render_process_id, | 42 void CaptureDevicesClosed(int render_process_id, |
45 int render_view_id, | 43 int render_view_id, |
46 const content::MediaStreamDevices& devices); | 44 const content::MediaStreamDevices& devices); |
47 | 45 |
48 // ImageLoadingTracker::Observer implementation. | 46 // extension_image_utils callback. |
49 virtual void OnImageLoaded(const gfx::Image& image, | 47 void OnImageLoaded(const string16& message, const gfx::Image& image); |
50 const std::string& extension_id, | |
51 int index) OVERRIDE; | |
52 | |
53 private: | 48 private: |
54 // Struct to store the usage information of the capture devices for each tab. | 49 // Struct to store the usage information of the capture devices for each tab. |
55 // TODO(estade): this should be called CaptureDeviceContents; not all the | 50 // TODO(estade): this should be called CaptureDeviceContents; not all the |
56 // render views it represents are tabs. | 51 // render views it represents are tabs. |
57 struct CaptureDeviceTab { | 52 struct CaptureDeviceTab { |
58 CaptureDeviceTab(int render_process_id, | 53 CaptureDeviceTab(int render_process_id, |
59 int render_view_id) | 54 int render_view_id) |
60 : render_process_id(render_process_id), | 55 : render_process_id(render_process_id), |
61 render_view_id(render_view_id), | 56 render_view_id(render_view_id), |
62 audio_ref_count(0), | 57 audio_ref_count(0), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 116 |
122 // Updates the status tray menu with the new device list. This call will be | 117 // Updates the status tray menu with the new device list. This call will be |
123 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). | 118 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). |
124 void UpdateStatusTrayIconContextMenu(); | 119 void UpdateStatusTrayIconContextMenu(); |
125 | 120 |
126 // Updates the status tray tooltip and image according to which kind of | 121 // Updates the status tray tooltip and image according to which kind of |
127 // devices are being used. This function is called by | 122 // devices are being used. This function is called by |
128 // UpdateStatusTrayIconContextMenu(). | 123 // UpdateStatusTrayIconContextMenu(). |
129 void UpdateStatusTrayIconDisplay(bool audio, bool video); | 124 void UpdateStatusTrayIconDisplay(bool audio, bool video); |
130 | 125 |
131 // Initializes image loading state. | |
132 void EnsureImageLoadingTracker(); | |
133 | |
134 // Reference to our status icon - owned by the StatusTray. If null, | 126 // Reference to our status icon - owned by the StatusTray. If null, |
135 // the platform doesn't support status icons. | 127 // the platform doesn't support status icons. |
136 StatusIcon* status_icon_; | 128 StatusIcon* status_icon_; |
137 | 129 |
138 // These images are owned by ResourceBundle and need not be destroyed. | 130 // These images are owned by ResourceBundle and need not be destroyed. |
139 gfx::ImageSkia* mic_image_; | 131 gfx::ImageSkia* mic_image_; |
140 gfx::ImageSkia* camera_image_; | 132 gfx::ImageSkia* camera_image_; |
141 gfx::ImageSkia* balloon_image_; | 133 gfx::ImageSkia* balloon_image_; |
142 | 134 |
143 // A list that contains the usage information of the opened capture devices. | 135 // A list that contains the usage information of the opened capture devices. |
144 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; | 136 typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs; |
145 CaptureDeviceTabs tabs_; | 137 CaptureDeviceTabs tabs_; |
146 | 138 |
147 // Tracks the load of extension icons. | 139 // Tracks the load of extension icons. |
148 scoped_ptr<ImageLoadingTracker> tracker_; | 140 base::WeakPtrFactory<MediaStreamCaptureIndicator> icon_tracker_; |
149 // The messages to display when extension images are loaded. The index | |
150 // corresponds to the index of the associated LoadImage request. | |
151 std::map<int, string16> pending_messages_; | |
152 // Tracks the number of requests to |tracker_|. | |
153 int request_index_; | |
154 }; | 141 }; |
155 | 142 |
156 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | 143 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
OLD | NEW |