Index: content/browser/renderer_host/media/web_contents_capture_util.h |
diff --git a/content/browser/renderer_host/media/web_contents_capture_util.h b/content/browser/renderer_host/media/web_contents_capture_util.h |
index 626f152e1887225ff417e63dfbc197e08367fa7e..5029c9bd6a87ba1652ca349ccb08563607ddf61f 100644 |
--- a/content/browser/renderer_host/media/web_contents_capture_util.h |
+++ b/content/browser/renderer_host/media/web_contents_capture_util.h |
@@ -7,10 +7,70 @@ |
#include <string> |
+#include "base/callback.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/synchronization/lock.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
namespace content { |
class WebContentsCaptureUtil { |
public: |
+ // Tracks RenderView changes during the lifetime of a WebContents instance. |
+ // |
+ // Thread-safety: Since the RenderViewTracker is intended to be used by both |
+ // WebContentsAudioInputStream and WebContentsVideoCaptureDevice, it operates |
+ // under the assumption that any thread could call the Start/Stop methods. |
+ // Likewise, while the ChangeCallback is invoked from the UI BrowserThread, it |
+ // is up to downstream code to trampoline to some other thread if necessary. |
+ class RenderViewTracker |
+ : public base::RefCountedThreadSafe<RenderViewTracker>, |
+ public WebContentsObserver { |
+ public: |
+ RenderViewTracker(); |
+ |
+ // Callback for whenever a new RenderView is swapped in. The callback is |
+ // also invoked with both arguments set to MSG_ROUTING_NONE to indicate |
+ // tracking will not continue (i.e., the WebContents instance was not found |
+ // or has been destroyed). |
+ typedef base::Callback<void(int render_process_id, int render_view_id)> |
+ ChangeCallback; |
+ |
+ // Start tracking. The last-known |render_process_id| and |render_view_id| |
+ // are provided, and the given callback is invoked asynchronously one or |
+ // more times. |
+ void Start(int render_process_id, int render_view_id, |
+ const ChangeCallback& callback); |
+ |
+ // Stop tracking. Once this method returns, the callback is guaranteed not |
+ // to be invoked again. |
+ void Stop(); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<RenderViewTracker>; |
+ |
+ virtual ~RenderViewTracker(); |
+ |
+ // Reads the render_process_id/render_view_id from the current WebContents |
+ // instance and then invokes the callback. |
+ void OnWebContentsChangeEvent(); |
+ |
+ // Look-up the current WebContents instance associated with the given |
+ // |render_process_id| and |render_view_id| and begin observing it. |
+ void LookUpAndObserveWebContents(int render_process_id, |
+ int render_view_id); |
+ |
+ // How WebContents notifies us of a new RenderView target. |
+ virtual void RenderViewReady() OVERRIDE; |
+ |
+ // Called when a WebContents has been destroyed. This invokes the callback |
+ // with MSG_ROUTING_NONE values to indicate tracking will not continue. |
+ virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; |
+ |
+ base::Lock lock_; // Guards changes to callback_. |
+ ChangeCallback callback_; |
+ }; |
+ |
// Function to extract the target renderer id's from a tab media stream |
// request's device id. |
static bool ExtractTabCaptureTarget(const std::string& device_id, |