Chromium Code Reviews| 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 the 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 std::string& url, | |
| 40 const content::MediaStreamDevices& devices); | |
| 41 | |
| 42 // Called on IO thread when the MediaStream closes the opened devices. | |
| 43 void CaptureDevicesClosed(int render_process_id, | |
| 44 int render_view_id, | |
| 45 const std::string& url, | |
| 46 const content::MediaStreamDevices& devices); | |
| 47 | |
| 48 private: | |
| 49 // Struct to store the usage information of the capture devices. | |
| 50 struct CaptureDeviceUser { | |
|
tommi (sloooow) - chröme
2012/04/30 10:57:07
Should this struct also include usage count?
no longer working on chromium
2012/04/30 13:12:54
The problem of using the usage count is that we ne
| |
| 51 CaptureDeviceUser(int render_process_id, | |
| 52 int render_view_id, | |
| 53 const std::string& url, | |
| 54 content::MediaStreamDeviceType type) | |
| 55 : render_process_id(render_process_id), | |
| 56 render_view_id(render_view_id), | |
| 57 url(url), | |
| 58 type(type) {} | |
| 59 | |
| 60 int render_process_id; | |
| 61 int render_view_id; | |
| 62 std::string url; | |
|
tommi (sloooow) - chröme
2012/04/30 10:57:07
do we really care about the URL (render_view_id sh
no longer working on chromium
2012/04/30 13:12:54
the URL is used as a friendly message telling the
| |
| 63 content::MediaStreamDeviceType type; | |
| 64 }; | |
| 65 | |
| 66 // A private predicate used in std::find_if to find a |CaptureDeviceUser| | |
| 67 // which matches the information specified at construction. | |
| 68 class UserEquals { | |
| 69 public: | |
| 70 UserEquals(int render_process_id, int render_view_id, | |
| 71 const std::string& url, content::MediaStreamDeviceType type); | |
|
tommi (sloooow) - chröme
2012/04/30 10:57:07
is it enough to compare only the render_view_id?
no longer working on chromium
2012/04/30 13:12:54
They are not only for comparison, we need both ren
| |
| 72 UserEquals(int render_process_id, int render_view_id, | |
| 73 const std::string& url); | |
| 74 | |
| 75 bool operator() ( | |
| 76 const MediaStreamCaptureIndicator::CaptureDeviceUser& user); | |
| 77 | |
| 78 private: | |
| 79 int render_process_id_; | |
| 80 int render_view_id_; | |
| 81 std::string url_; | |
| 82 content::MediaStreamDeviceType type_; | |
| 83 }; | |
| 84 | |
| 85 friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>; | |
| 86 virtual ~MediaStreamCaptureIndicator(); | |
| 87 | |
| 88 // Called by the public functions, executed on UI thread. | |
| 89 void DoDevicesOpenedOnUIThread(int render_process_id, | |
| 90 int render_view_id, | |
| 91 const std::string& url, | |
| 92 const content::MediaStreamDevices& devices); | |
| 93 void DoDevicesClosedOnUIThread(int render_process_id, | |
| 94 int render_view_id, | |
| 95 const std::string& url, | |
| 96 const content::MediaStreamDevices& devices); | |
| 97 | |
| 98 // Following functions/variables are executed/accessed only on UI thread. | |
| 99 // Creates the status tray if it has not been created. | |
| 100 void CreateStatusTray(); | |
| 101 | |
| 102 // Makes sure we have done one-time initialization of the |icon_image_|. | |
| 103 void EnsureStatusTrayIcon(); | |
| 104 | |
| 105 // Triggers a balloon in the corner telling users devices are being used. | |
| 106 void ShowBalloon(const std::string& url); | |
| 107 | |
| 108 // Hides the status tray from the desktop. | |
| 109 void Hide(); | |
| 110 | |
| 111 // Adds the new user to the device usage list. | |
| 112 void AddCaptureDeviceUser(int render_process_id, | |
| 113 int render_view_id, | |
| 114 const std::string& url, | |
| 115 const content::MediaStreamDevices& devices); | |
| 116 | |
| 117 // Removes the user from the device usage list. | |
| 118 void RemoveCaptureDeviceUser(int render_process_id, | |
| 119 int render_view_id, | |
| 120 const std::string& url, | |
| 121 const content::MediaStreamDevices& devices); | |
| 122 | |
| 123 // Updates the status tray menu with the new device list. This call will be | |
| 124 // triggered by both AddCaptureDeviceUser() and RemoveCaptureDeviceUser(). | |
| 125 void UpdateStatusTrayIconContextMenu(); | |
| 126 | |
| 127 // Reference to our status icon - owned by the StatusTray. If null, | |
| 128 // the platform doesn't support status icons. | |
| 129 StatusIcon* status_icon_; | |
| 130 | |
| 131 // Icon to be displayed on the status tray. | |
| 132 SkBitmap icon_image_; | |
| 133 | |
| 134 // A list that contains the usage information of the opened capture devices. | |
| 135 typedef std::list<CaptureDeviceUser> CaptureDeviceUserList; | |
|
tommi (sloooow) - chröme
2012/04/30 10:57:07
What about having the 'users' list a map between r
no longer working on chromium
2012/04/30 13:12:54
According to my understanding, it is a valid case
| |
| 136 CaptureDeviceUserList users_; | |
| 137 }; | |
| 138 | |
| 139 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ | |
| OLD | NEW |