Commit 386aad04 authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Chromium LUCI CQ

Remove unused WebContentsTracker

Change-Id: If231540e44354a1dcf1c4d8e8e4deb13516b3059
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589913Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836714}
parent eb16d547
......@@ -1060,8 +1060,6 @@ source_set("browser") {
"media/capture/desktop_streams_registry_impl.h",
"media/capture/web_contents_audio_muter.cc",
"media/capture/web_contents_audio_muter.h",
"media/capture/web_contents_tracker.cc",
"media/capture/web_contents_tracker.h",
"media/cdm_registry_impl.cc",
"media/cdm_registry_impl.h",
"media/desktop_media_window_registry.cc",
......
// Copyright (c) 2013 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.
#include "content/browser/media/capture/web_contents_tracker.h"
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
namespace content {
WebContentsTracker::WebContentsTracker() : last_target_view_(nullptr) {}
WebContentsTracker::~WebContentsTracker() {
// Likely unintentional BUG if Stop() was not called before this point.
DCHECK(!web_contents());
}
void WebContentsTracker::Start(int render_process_id,
int main_render_frame_id,
ChangeCallback callback) {
DCHECK(!task_runner_ || task_runner_->BelongsToCurrentThread());
task_runner_ = base::ThreadTaskRunnerHandle::Get();
DCHECK(task_runner_);
callback_ = std::move(callback);
if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
StartObservingWebContents(render_process_id, main_render_frame_id);
} else {
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&WebContentsTracker::StartObservingWebContents, this,
render_process_id, main_render_frame_id));
}
}
void WebContentsTracker::Stop() {
DCHECK(task_runner_->BelongsToCurrentThread());
callback_.Reset();
resize_callback_.Reset();
if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
WebContentsObserver::Observe(nullptr);
} else {
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&WebContentsTracker::Observe, this,
static_cast<WebContents*>(nullptr)));
}
}
RenderWidgetHostView* WebContentsTracker::GetTargetView() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebContents* const wc = web_contents();
if (!wc)
return nullptr;
if (auto* view = wc->GetRenderWidgetHostView()) {
// Make sure the RWHV is still associated with a RWH before considering the
// view "alive." This is because a null RWH indicates the RWHV has had its
// Destroy() method called.
if (view->GetRenderWidgetHost())
return view;
}
return nullptr;
}
void WebContentsTracker::SetResizeChangeCallback(
base::RepeatingClosure callback) {
DCHECK(!task_runner_ || task_runner_->BelongsToCurrentThread());
resize_callback_ = std::move(callback);
}
void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderWidgetHostView* const rwhv = GetTargetView();
if (rwhv == last_target_view_ && !force_callback_run) {
DVLOG(1) << "No target view change (RenderWidgetHostView@" << rwhv << ')';
return;
}
DVLOG(1) << "Will report target change from RenderWidgetHostView@"
<< last_target_view_ << " to RenderWidgetHostView@" << rwhv;
last_target_view_ = rwhv;
if (task_runner_->BelongsToCurrentThread()) {
MaybeDoCallback(is_still_tracking());
return;
}
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&WebContentsTracker::MaybeDoCallback, this,
is_still_tracking()));
}
void WebContentsTracker::MaybeDoCallback(bool was_still_tracking) {
DCHECK(task_runner_->BelongsToCurrentThread());
// Notify of a size change just before notifying of a new target. This allows
// the downstream implementation to capture the first frame from the new
// target at the correct resolution. http://crbug.com/704277
if (was_still_tracking)
MaybeDoResizeCallback();
if (!callback_.is_null())
callback_.Run(was_still_tracking);
}
void WebContentsTracker::MaybeDoResizeCallback() {
DCHECK(task_runner_->BelongsToCurrentThread());
if (!resize_callback_.is_null())
resize_callback_.Run();
}
void WebContentsTracker::StartObservingWebContents(int render_process_id,
int main_render_frame_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Observe(WebContents::FromRenderFrameHost(RenderFrameHost::FromID(
render_process_id, main_render_frame_id)));
DVLOG_IF(1, !web_contents())
<< "Could not find WebContents associated with main RenderFrameHost "
<< "referenced by render_process_id=" << render_process_id
<< ", routing_id=" << main_render_frame_id;
OnPossibleTargetChange(true);
}
void WebContentsTracker::RenderFrameCreated(
RenderFrameHost* render_frame_host) {
DVLOG(1) << "RenderFrameCreated(rfh=" << render_frame_host << ')';
OnPossibleTargetChange(false);
}
void WebContentsTracker::RenderFrameDeleted(
RenderFrameHost* render_frame_host) {
DVLOG(1) << "RenderFrameDeleted(rfh=" << render_frame_host << ')';
OnPossibleTargetChange(false);
}
void WebContentsTracker::RenderFrameHostChanged(RenderFrameHost* old_host,
RenderFrameHost* new_host) {
DVLOG(1) << "RenderFrameHostChanged(old=" << old_host << ", new=" << new_host
<< ')';
OnPossibleTargetChange(false);
}
void WebContentsTracker::MainFrameWasResized(bool width_changed) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (task_runner_->BelongsToCurrentThread()) {
MaybeDoResizeCallback();
return;
}
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WebContentsTracker::MaybeDoResizeCallback, this));
}
void WebContentsTracker::WebContentsDestroyed() {
DVLOG(1) << "WebContentsDestroyed()";
Observe(nullptr);
OnPossibleTargetChange(true);
}
} // namespace content
// Copyright (c) 2013 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.
//
// Given a starting render_process_id and main_render_frame_id, the
// WebContentsTracker tracks changes to the active RenderFrameHost tree during
// the lifetime of a WebContents instance. This is used to maintain capture of
// the WebContents's video and audio across page transitions such as user
// navigations, crashes, iframes, etc..
//
// Threading issues: Start(), Stop() and the ChangeCallback must be invoked on
// the same thread. This can be any thread, and the decision is locked-in once
// WebContentsTracker::Start() is called.
#ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_
#define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/public/browser/web_contents_observer.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace content {
class RenderWidgetHostView;
class CONTENT_EXPORT WebContentsTracker
: public base::RefCountedThreadSafe<WebContentsTracker>,
public WebContentsObserver {
public:
WebContentsTracker();
// Callback to indicate a new RenderWidgetHostView should be targeted for
// capture. This is also invoked with false to indicate tracking will not
// continue (i.e., the WebContents instance was not found or has been
// destroyed).
using ChangeCallback = base::RepeatingCallback<void(bool was_still_tracking)>;
// Start tracking. The last-known |render_process_id| and
// |main_render_frame_id| are provided, and |callback| will be run once to
// indicate whether tracking successfully started (this may occur during the
// invocation of Start(), or in the future). The callback will be invoked on
// the same thread calling Start().
virtual void Start(int render_process_id,
int main_render_frame_id,
ChangeCallback callback);
// Stop tracking. Once this method returns, the callback is guaranteed not to
// be invoked again.
virtual void Stop();
// Returns true if this tracker is still able to continue tracking changes.
// This must only be called on the UI BrowserThread.
bool is_still_tracking() const { return !!web_contents(); }
// Current target view. May return nullptr during certain transient periods.
// This must only be called on the UI BrowserThread.
RenderWidgetHostView* GetTargetView() const;
// Set a callback that is run whenever the main frame of the WebContents is
// resized. This method must be called on the same thread that calls
// Start()/Stop(), and |callback| will be run on that same thread. Calling
// the Stop() method guarantees the callback will never be invoked again.
void SetResizeChangeCallback(base::RepeatingClosure callback);
protected:
friend class base::RefCountedThreadSafe<WebContentsTracker>;
~WebContentsTracker() override;
private:
// Determine the target RenderWidgetHostView and, if different from that last
// reported, runs the ChangeCallback on the appropriate thread. If
// |force_callback_run| is true, the ChangeCallback is run even if the
// RenderWidgetHostView has not changed.
void OnPossibleTargetChange(bool force_callback_run);
// Called on the thread that Start()/Stop() are called on. Checks whether the
// callback is still valid and, if so, runs it.
void MaybeDoCallback(bool was_still_tracking);
// Called on the thread that Start()/Stop() are called on. Checks whether the
// callback is still valid and, if so, runs it to indicate the main frame has
// changed in size.
void MaybeDoResizeCallback();
// Look-up the current WebContents instance associated with the given
// |render_process_id| and |main_render_frame_id| and begin observing it.
void StartObservingWebContents(int render_process_id,
int main_render_frame_id);
// WebContentsObserver overrides: These events indicate that the view of the
// main frame may have changed.
void RenderFrameCreated(RenderFrameHost* render_frame_host) final;
void RenderFrameDeleted(RenderFrameHost* render_frame_host) final;
void RenderFrameHostChanged(RenderFrameHost* old_host,
RenderFrameHost* new_host) final;
// WebContentsObserver override to notify the client that the source size has
// changed.
void MainFrameWasResized(bool width_changed) final;
// WebContentsObserver override to notify the client that the capture target
// has been permanently lost.
void WebContentsDestroyed() final;
// Pointer to the RenderWidgetHostView provided in the last run of
// |callback_|. This is used to eliminate duplicate callback runs.
RenderWidgetHostView* last_target_view_;
// TaskRunner corresponding to the thread that called Start().
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// Callback to run when the target RenderWidgetHostView has changed.
ChangeCallback callback_;
// Callback to run when the target RenderWidgetHostView has resized.
base::RepeatingClosure resize_callback_;
DISALLOW_COPY_AND_ASSIGN(WebContentsTracker);
};
} // namespace content
#endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment