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

Side by Side 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: Minor tweaks and added some useful comments. Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h"
13 #include "content/public/browser/web_contents_observer.h"
14
10 namespace content { 15 namespace content {
11 16
12 class WebContentsCaptureUtil { 17 class WebContentsCaptureUtil {
13 public: 18 public:
19 // Tracks RenderView changes during the lifetime of a WebContents instance.
20 //
21 // Thread-safety: Since the RenderViewTracker is intended to be used by both
22 // WebContentsAudioInputStream and WebContentsVideoCaptureDevice, it operates
23 // under the assumption that any thread could call the Start/Stop methods.
24 // Likewise, while the ChangeCallback is invoked from the UI BrowserThread, it
25 // is up to downstream code to trampoline to some other thread if necessary.
26 class RenderViewTracker
27 : public base::RefCountedThreadSafe<RenderViewTracker>,
28 public WebContentsObserver {
29 public:
30 RenderViewTracker();
31
32 // Callback for whenever a new RenderView is swapped in. The callback is
33 // also invoked with both arguments set to MSG_ROUTING_NONE to indicate
34 // tracking will not continue (i.e., the WebContents instance was not found
35 // or has been destroyed).
36 typedef base::Callback<void(int render_process_id, int render_view_id)>
37 ChangeCallback;
38
39 // Start tracking. The last-known |render_process_id| and |render_view_id|
40 // are provided, and the given callback is invoked asynchronously one or
41 // more times.
42 void Start(int render_process_id, int render_view_id,
43 const ChangeCallback& callback);
44
45 // Stop tracking. Once this method returns, the callback is guaranteed not
46 // to be invoked again.
47 void Stop();
48
49 private:
50 friend class base::RefCountedThreadSafe<RenderViewTracker>;
51
52 virtual ~RenderViewTracker();
53
54 // Reads the render_process_id/render_view_id from the current WebContents
55 // instance and then invokes the callback.
56 void OnWebContentsChangeEvent();
57
58 // Look-up the current WebContents instance associated with the given
59 // |render_process_id| and |render_view_id| and begin observing it.
60 void LookUpAndObserveWebContents(int render_process_id,
61 int render_view_id);
62
63 // How WebContents notifies us of a new RenderView target.
64 virtual void RenderViewReady() OVERRIDE;
65
66 // Called when a WebContents has been destroyed. This invokes the callback
67 // with MSG_ROUTING_NONE values to indicate tracking will not continue.
68 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE;
69
70 base::Lock lock_; // Guards changes to callback_.
71 ChangeCallback callback_;
72 };
73
14 // Function to extract the target renderer id's from a tab media stream 74 // Function to extract the target renderer id's from a tab media stream
15 // request's device id. 75 // request's device id.
16 static bool ExtractTabCaptureTarget(const std::string& device_id, 76 static bool ExtractTabCaptureTarget(const std::string& device_id,
17 int* render_process_id, 77 int* render_process_id,
18 int* render_view_id); 78 int* render_view_id);
19 }; 79 };
20 80
21 } // namespace content 81 } // namespace content
22 82
23 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ 83 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698