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

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

Issue 11413078: Tab Audio Capture: Browser-side connect/disconnect functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed WCAIS threading issue (methods called on audio thread). Addressed hclam's review comments. Created 8 years, 1 month 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
new file mode 100644
index 0000000000000000000000000000000000000000..bf26ec666e1c7a5e20bc0e491862b5c4712cc895
--- /dev/null
+++ b/content/browser/renderer_host/media/web_contents_capture_util.h
@@ -0,0 +1,79 @@
+// 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_
+#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_
+
+#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 WebContents;
+
+class WebContentsCaptureUtil {
+ public:
+ // Tracks RenderView changes during the lifetime of a WebContents.
+ 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,
+ int* render_process_id,
+ int* render_view_id);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698