| 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
|
| index c94f26ffc1bde0c014fc55855ec0d8b4f684b6ad..f571cff7fd0885bc5811ffd0287a5d7db1e2020a 100644
|
| --- a/chrome/browser/media/media_stream_capture_indicator.h
|
| +++ b/chrome/browser/media/media_stream_capture_indicator.h
|
| @@ -5,19 +5,23 @@
|
| #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
|
| #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_CAPTURE_INDICATOR_H_
|
|
|
| +#include <map>
|
| #include <string>
|
| +#include <utility>
|
| #include <vector>
|
|
|
| #include "base/memory/ref_counted.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| #include "content/public/common/media_stream_request.h"
|
| #include "ui/base/models/simple_menu_model.h"
|
| -#include "ui/gfx/image/image_skia.h"
|
|
|
| namespace content {
|
| class WebContents;
|
| } // namespace content
|
|
|
| +namespace gfx {
|
| +class ImageSkia;
|
| +} // namespace gfx
|
| +
|
| class StatusIcon;
|
| class StatusTray;
|
|
|
| @@ -47,61 +51,17 @@ class MediaStreamCaptureIndicator
|
| int render_view_id,
|
| const content::MediaStreamDevices& devices);
|
|
|
| - // Returns true if the render process is capturing media.
|
| - bool IsProcessCapturing(int render_process_id, int render_view_id) const;
|
| + // Returns true if the render view is capturing media.
|
| + bool IsRenderViewCapturing(int render_process_id, int render_view_id) const;
|
|
|
| - // Returns true if the render process is capturing tab media.
|
| - bool IsProcessCapturingTab(int render_process_id, int render_view_id) const;
|
| + // Returns true if the render view is being mirrored.
|
| + bool IsRenderViewMirroring(int render_process_id, int render_view_id) const;
|
|
|
| // ImageLoader callback.
|
| void OnImageLoaded(const string16& message, const gfx::Image& image);
|
|
|
| private:
|
| - // Struct to store the usage information of the capture devices for each tab.
|
| - // Note: It is not safe to dereference WebContents pointer. This is used to
|
| - // track the tab after navigations as render_view_id's can change.
|
| - // TODO(estade): this should be called CaptureDeviceContents; not all the
|
| - // render views it represents are tabs.
|
| - struct CaptureDeviceTab {
|
| - CaptureDeviceTab(content::WebContents* web_contents,
|
| - int render_process_id,
|
| - int render_view_id)
|
| - : web_contents(web_contents),
|
| - render_process_id(render_process_id),
|
| - render_view_id(render_view_id),
|
| - audio_ref_count(0),
|
| - video_ref_count(0),
|
| - tab_capture_ref_count(0) {}
|
| -
|
| - content::WebContents* web_contents;
|
| - int render_process_id;
|
| - int render_view_id;
|
| - int audio_ref_count;
|
| - int video_ref_count;
|
| - int tab_capture_ref_count;
|
| - };
|
| -
|
| - // A private predicate used in std::find_if to find a |CaptureDeviceTab|
|
| - // which matches the information specified at construction. A tab will match
|
| - // if either the web_contents pointer is the same or the render_process_id and
|
| - // render_view_id's are the same. In the first case, a tab with a UI indicator
|
| - // may have changed page so the id's are different. In the second case, the
|
| - // web_contents may have already been destroyed before the indicator was
|
| - // hidden.
|
| - class TabEquals {
|
| - public:
|
| - TabEquals(content::WebContents* web_contents,
|
| - int render_process_id,
|
| - int render_view_id);
|
| -
|
| - bool operator() (
|
| - const MediaStreamCaptureIndicator::CaptureDeviceTab& tab);
|
| -
|
| - private:
|
| - content::WebContents* web_contents_;
|
| - int render_process_id_;
|
| - int render_view_id_;
|
| - };
|
| + class CaptureDeviceUsage;
|
|
|
| friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>;
|
| virtual ~MediaStreamCaptureIndicator();
|
| @@ -115,33 +75,41 @@ class MediaStreamCaptureIndicator
|
| 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();
|
| +
|
| + // Creates and shows the status tray icon if it has not been created and is
|
| + // supported on the current platform.
|
| + void MaybeCreateStatusTrayIcon();
|
|
|
| // Makes sure we have done one-time initialization of the images.
|
| void EnsureStatusTrayIconResources();
|
|
|
| - // Adds the new tab to the device usage list.
|
| - void AddCaptureDeviceTab(int render_process_id,
|
| - int render_view_id,
|
| - const content::MediaStreamDevices& devices);
|
| + // Finds a WebContents instance by its RenderView's current or
|
| + // previously-known IDs. This is necessary since clients that called
|
| + // CaptureDevicesOpened() may later call CaptureDevicesClosed() with stale
|
| + // IDs.
|
| + content::WebContents* LookUpByKnownAlias(int render_process_id,
|
| + int render_view_id) const;
|
| +
|
| + // Adds devices to usage map and triggers necessary UI updates.
|
| + void AddCaptureDevices(int render_process_id,
|
| + int render_view_id,
|
| + const content::MediaStreamDevices& devices);
|
|
|
| - // Removes the tab from the device usage list.
|
| - void RemoveCaptureDeviceTab(int render_process_id,
|
| - int render_view_id,
|
| - const content::MediaStreamDevices& devices);
|
| + // Removes devices from the usage map and triggers necessary UI updates.
|
| + void RemoveCaptureDevices(int render_process_id,
|
| + int render_view_id,
|
| + const content::MediaStreamDevices& devices);
|
|
|
| // Triggers a balloon in the corner telling capture devices are being used.
|
| - // This function is called by AddCaptureDeviceTab().
|
| - void ShowBalloon(int render_process_id, int render_view_id,
|
| - bool audio, bool video);
|
| + // This function is called by AddCaptureDevices().
|
| + void ShowBalloon(content::WebContents* web_contents, bool audio, bool video);
|
|
|
| - // Hides the status tray from the desktop. This function is called by
|
| - // RemoveCaptureDeviceTab() when the device usage list becomes empty.
|
| - void Hide();
|
| + // Removes the status tray icon from the desktop. This function is called by
|
| + // RemoveCaptureDevices() when the device usage map becomes empty.
|
| + void MaybeDestroyStatusTrayIcon();
|
|
|
| // Updates the status tray menu with the new device list. This call will be
|
| - // triggered by both AddCaptureDeviceTab() and RemoveCaptureDeviceTab().
|
| + // triggered by both AddCaptureDevices() and RemoveCaptureDevices().
|
| void UpdateStatusTrayIconContextMenu();
|
|
|
| // Updates the status tray tooltip and image according to which kind of
|
| @@ -158,9 +126,21 @@ class MediaStreamCaptureIndicator
|
| gfx::ImageSkia* camera_image_;
|
| gfx::ImageSkia* balloon_image_;
|
|
|
| - // A list that contains the usage information of the opened capture devices.
|
| - typedef std::vector<CaptureDeviceTab> CaptureDeviceTabs;
|
| - CaptureDeviceTabs tabs_;
|
| + // A map that contains the usage counts of the opened capture devices for each
|
| + // WebContents instance.
|
| + typedef std::map<content::WebContents*, CaptureDeviceUsage*> UsageMap;
|
| + UsageMap usage_map_;
|
| +
|
| + // A map of known render_process_id/render_view_id pairs that have been
|
| + // associated with a WebContents instance.
|
| + typedef std::pair<int, int> RenderViewIDs;
|
| + typedef std::map<RenderViewIDs, content::WebContents*> AliasMap;
|
| + AliasMap aliases_;
|
| +
|
| + // A map from command_ids to their associated WebContents instance. This is
|
| + // rebuilt each time the status tray icon context menu is updated.
|
| + typedef std::vector<content::WebContents*> CommandMap;
|
| + CommandMap command_map_;
|
|
|
| bool should_show_balloon_;
|
| };
|
|
|