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 |
+ : 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_ |