Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5543)

Unified Diff: chrome/browser/media/media_stream_capture_indicator.h

Issue 12035046: Fix bug causing tab favicon media indicator to not turn off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix issue with browser shutdown race condition. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/media/media_stream_capture_indicator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a36faf7f8b2ccdabae2ff90e8c10ccc3ba5d10eb 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,19 @@ 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 user media (e.g., webcam
+ // or microphone input).
+ bool IsCapturingUserMedia(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 itself is being mirrored (e.g., a source of
+ // media for remote broadcast).
+ bool IsBeingMirrored(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 WebContentsDeviceUsage;
friend class base::RefCountedThreadSafe<MediaStreamCaptureIndicator>;
virtual ~MediaStreamCaptureIndicator();
@@ -115,33 +77,43 @@ 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);
-
- // Removes the tab from the device usage list.
- void RemoveCaptureDeviceTab(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. Do not attempt to dereference the pointer without first consulting
+ // WebContentsDeviceUsage::IsWebContentsDestroyed().
+ 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 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,
+ int balloon_body_message_id);
- // 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 +130,22 @@ 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*, WebContentsDeviceUsage*> UsageMap;
justinlin 2013/01/29 21:32:07 would it be possible to make this a map of objects
miu 2013/01/29 21:41:41 I would have liked to do this, but WebContentsDevi
+ UsageMap usage_map_;
+
+ // A map of previously-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 vector which maps 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*> CommandTargets;
+ CommandTargets command_targets_;
bool should_show_balloon_;
};
« no previous file with comments | « no previous file | chrome/browser/media/media_stream_capture_indicator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698