Chromium Code Reviews| Index: chrome/browser/media/media_stream_capture_indicator.h |
| diff --git a/chrome/browser/media/media_stream_capture_indicator.h b/chrome/browser/media/media_stream_capture_indicator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9465e5817fbef10c44e719b3cdf105bf0a4c0aa1 |
| --- /dev/null |
| +++ b/chrome/browser/media/media_stream_capture_indicator.h |
| @@ -0,0 +1,139 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| +#define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |
| +#pragma once |
| + |
| +#include <list> |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "content/public/common/media_stream_request.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/base/models/simple_menu_model.h" |
| + |
| +class StatusIcon; |
| +class StatusTray; |
| + |
| +// This indicator is owned by MediaInternals and deleted when the MediaInternals |
| +// is deleted. |
| +class MediaStreamCaptureIndicator |
| + : public base::RefCountedThreadSafe<MediaStreamCaptureIndicator>, |
| + public ui::SimpleMenuModel::Delegate { |
| + public: |
| + MediaStreamCaptureIndicator(); |
| + |
| + // Overrides from SimpleMenuModel::Delegate implementation. |
| + virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| + virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| + virtual bool GetAcceleratorForCommandId( |
| + int command_id, |
| + ui::Accelerator* accelerator) OVERRIDE; |
| + virtual void ExecuteCommand(int command_id) OVERRIDE; |
| + |
| + // Called on IO thread when MediaStream opens new capture devices. |
| + void CaptureDevicesOpened(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + |
| + // Called on IO thread when the MediaStream closes the opened devices. |
| + void CaptureDevicesClosed(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + |
| + private: |
| + // Struct to store the usage information of the capture devices. |
| + 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
|
| + CaptureDeviceUser(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + content::MediaStreamDeviceType type) |
| + : render_process_id(render_process_id), |
| + render_view_id(render_view_id), |
| + url(url), |
| + type(type) {} |
| + |
| + int render_process_id; |
| + int render_view_id; |
| + 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
|
| + content::MediaStreamDeviceType type; |
| + }; |
| + |
| + // A private predicate used in std::find_if to find a |CaptureDeviceUser| |
| + // which matches the information specified at construction. |
| + class UserEquals { |
| + public: |
| + UserEquals(int render_process_id, int render_view_id, |
| + 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
|
| + UserEquals(int render_process_id, int render_view_id, |
| + const std::string& url); |
| + |
| + bool operator() ( |
| + const MediaStreamCaptureIndicator::CaptureDeviceUser& user); |
| + |
| + private: |
| + int render_process_id_; |
| + int render_view_id_; |
| + std::string url_; |
| + content::MediaStreamDeviceType type_; |
| + }; |
| + |
| + friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>; |
| + virtual ~MediaStreamCaptureIndicator(); |
| + |
| + // Called by the public functions, executed on UI thread. |
| + void DoDevicesOpenedOnUIThread(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + void DoDevicesClosedOnUIThread(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + |
| + // Following functions/variables are executed/accessed only on UI thread. |
| + // Creates the status tray if it has not been created. |
| + void CreateStatusTray(); |
| + |
| + // Makes sure we have done one-time initialization of the |icon_image_|. |
| + void EnsureStatusTrayIcon(); |
| + |
| + // Triggers a balloon in the corner telling users devices are being used. |
| + void ShowBalloon(const std::string& url); |
| + |
| + // Hides the status tray from the desktop. |
| + void Hide(); |
| + |
| + // Adds the new user to the device usage list. |
| + void AddCaptureDeviceUser(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + |
| + // Removes the user from the device usage list. |
| + void RemoveCaptureDeviceUser(int render_process_id, |
| + int render_view_id, |
| + const std::string& url, |
| + const content::MediaStreamDevices& devices); |
| + |
| + // Updates the status tray menu with the new device list. This call will be |
| + // triggered by both AddCaptureDeviceUser() and RemoveCaptureDeviceUser(). |
| + void UpdateStatusTrayIconContextMenu(); |
| + |
| + // Reference to our status icon - owned by the StatusTray. If null, |
| + // the platform doesn't support status icons. |
| + StatusIcon* status_icon_; |
| + |
| + // Icon to be displayed on the status tray. |
| + SkBitmap icon_image_; |
| + |
| + // A list that contains the usage information of the opened capture devices. |
| + 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
|
| + CaptureDeviceUserList users_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_ |