OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| 6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <list> |
| 10 #include <string> |
| 11 |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "content/public/common/media_stream_request.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/base/models/simple_menu_model.h" |
| 16 |
| 17 class StatusIcon; |
| 18 class StatusTray; |
| 19 |
| 20 // This indicator is owned by MediaInternals and deleted when MediaInternals |
| 21 // is deleted. |
| 22 class MediaStreamCaptureIndicator |
| 23 : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, |
| 24 public ui::SimpleMenuModel::Delegate { |
| 25 public: |
| 26 MediaStreamCaptureIndicator(); |
| 27 |
| 28 // Overrides from SimpleMenuModel::Delegate implementation. |
| 29 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 30 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 31 virtual bool GetAcceleratorForCommandId( |
| 32 int command_id, |
| 33 ui::Accelerator* accelerator) OVERRIDE; |
| 34 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 35 |
| 36 // Called on IO thread when MediaStream opens new capture devices. |
| 37 void CaptureDevicesOpened(int render_process_id, |
| 38 int render_view_id, |
| 39 const content::MediaStreamDevices& devices); |
| 40 |
| 41 // Called on IO thread when MediaStream closes the opened devices. |
| 42 void CaptureDevicesClosed(int render_process_id, |
| 43 int render_view_id, |
| 44 const content::MediaStreamDevices& devices); |
| 45 |
| 46 private: |
| 47 // Struct to store the usage information of the capture devices for each tab. |
| 48 struct CaptureDeviceTab { |
| 49 CaptureDeviceTab(int render_process_id, |
| 50 int render_view_id, |
| 51 content::MediaStreamDeviceType type) |
| 52 : render_process_id(render_process_id), |
| 53 render_view_id(render_view_id), |
| 54 type(type) {} |
| 55 |
| 56 int render_process_id; |
| 57 int render_view_id; |
| 58 content::MediaStreamDeviceType type; |
| 59 }; |
| 60 |
| 61 // A private predicate used in std::find_if to find a |CaptureDeviceTab| |
| 62 // which matches the information specified at construction. |
| 63 class TabEquals { |
| 64 public: |
| 65 TabEquals(int render_process_id, int render_view_id, |
| 66 content::MediaStreamDeviceType type); |
| 67 TabEquals(int render_process_id, int render_view_id); |
| 68 |
| 69 bool operator() ( |
| 70 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab); |
| 71 |
| 72 private: |
| 73 int render_process_id_; |
| 74 int render_view_id_; |
| 75 content::MediaStreamDeviceType type_; |
| 76 }; |
| 77 |
| 78 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>; |
| 79 virtual ~MediaStreamCaptureIndicator(); |
| 80 |
| 81 // Called by the public functions, executed on UI thread. |
| 82 void DoDevicesOpenedOnUIThread(int render_process_id, |
| 83 int render_view_id, |
| 84 const content::MediaStreamDevices& devices); |
| 85 void DoDevicesClosedOnUIThread(int render_process_id, |
| 86 int render_view_id, |
| 87 const content::MediaStreamDevices& devices); |
| 88 |
| 89 // Following functions/variables are executed/accessed only on UI thread. |
| 90 // Creates the status tray if it has not been created. |
| 91 void CreateStatusTray(); |
| 92 |
| 93 // Makes sure we have done one-time initialization of the |icon_image_|. |
| 94 void EnsureStatusTrayIcon(); |
| 95 |
| 96 // Triggers a balloon in the corner telling capture devices are being used. |
| 97 void ShowBalloon(int render_process_id, int render_view_id, |
| 98 const content::MediaStreamDevices& devices) const; |
| 99 |
| 100 // Hides the status tray from the desktop. |
| 101 void Hide(); |
| 102 |
| 103 // Adds the new tab to the device usage list. |
| 104 void AddCaptureDeviceTab(int render_process_id, |
| 105 int render_view_id, |
| 106 const content::MediaStreamDevices& devices); |
| 107 |
| 108 // Removes the tab from the device usage list. |
| 109 void RemoveCaptureDeviceTab(int render_process_id, |
| 110 int render_view_id, |
| 111 const content::MediaStreamDevices& devices); |
| 112 |
| 113 // Gets the title of the tab. |
| 114 string16 GetTitle(int render_process_id, int render_view_id) const; |
| 115 |
| 116 // Updates the status tray menu with the new device list. This call will be |
| 117 // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab(). |
| 118 void UpdateStatusTrayIconContextMenu(); |
| 119 |
| 120 // Reference to our status icon - owned by the StatusTray. If null, |
| 121 // the platform doesn't support status icons. |
| 122 StatusIcon* status_icon_; |
| 123 |
| 124 // Icon to be displayed on the status tray. |
| 125 SkBitmap icon_image_; |
| 126 |
| 127 // A list that contains the usage information of the opened capture devices. |
| 128 typedef std::list<CaptureDeviceTab> CaptureDeviceTabList; |
| 129 CaptureDeviceTabList tabs_; |
| 130 }; |
| 131 |
| 132 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
OLD | NEW |