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

Unified Diff: content/browser/renderer_host/media/web_contents_capture_util.h

Issue 11416350: Tab Audio Mirroring: WebContentsAudioInputStream is a new implementation which represents the lifet… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Destructors hate ASSERT() in unit tests. 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
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 0256a5cd570d9fa1bf672e82fbfbb117fd551213..a577e84ab186384cdf1bd211cf67a0c2bc6341c1 100644
--- a/content/browser/renderer_host/media/web_contents_capture_util.h
+++ b/content/browser/renderer_host/media/web_contents_capture_util.h
@@ -7,6 +7,15 @@
#include <string>
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "content/common/content_export.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
namespace content {
class WebContentsCaptureUtil {
@@ -28,6 +37,67 @@ class WebContentsCaptureUtil {
int* render_view_id);
};
+// Given a starting render_process_id and render_view_id, tracks RenderView
+// instance swapping during the lifetime of a WebContents instance.
+//
+// Threading issues: Start(), Stop() and the ChangeCallback are invoked on the
+// same thread. This can be any thread, and the decision is locked-in by
+// WebContentsTracker when Start() is called.
+class CONTENT_EXPORT WebContentsTracker
DaleCurtis 2013/01/15 22:02:18 Why put this here vs separate file vs private clas
miu 2013/01/16 03:22:18 This class is a utility meant to be used by only W
DaleCurtis 2013/01/17 01:15:52 Hmm, it depends on the usage pattern. In general,
miu 2013/01/17 05:33:55 Agreed. This stuff with the device_id parsing is
+ : public base::RefCountedThreadSafe<WebContentsTracker>,
+ public WebContentsObserver {
+ public:
+ WebContentsTracker();
+
+ // Callback for whenever the target is swapped. 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. The callback will be invoked on the same thread calling Start().
+ virtual 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.
+ virtual void Stop();
+
+ protected:
+ friend class base::RefCountedThreadSafe<WebContentsTracker>;
+ virtual ~WebContentsTracker();
+
+ private:
+ // Reads the render_process_id/render_view_id from the current WebContents
+ // instance and then invokes the callback.
+ void OnWebContentsChangeEvent();
+
+ // Called on the thread that Start()/Stop() are called on, check whether the
+ // callback is still valid and, if so, invoke it.
+ void MaybeDoCallback(int render_process_id, int render_view_id);
+
+ // 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);
+
+ // WebContentsObserver overrides to react to events of interest.
+ virtual void RenderViewReady() OVERRIDE;
+ virtual void AboutToNavigateRenderView(RenderViewHost* render_view_host)
+ OVERRIDE;
+ virtual void DidNavigateMainFrame(const LoadCommittedDetails& details,
+ const FrameNavigateParams& params) OVERRIDE;
+ virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE;
+
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ ChangeCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebContentsTracker);
+};
+
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698