Skip to content

Commit

Permalink
[Code Health] Remove uses of base::SupportsWeakPtr
Browse files Browse the repository at this point in the history
This CL removes uses of this deprecated base class by adding a
base::WeakPtrFactory data member.

In some cases, the base class was no longer being used, so it's
simply removed.

In some cases, it was being used as the base class for a supposed
interface class. In those cases, a pure virtual member function
was added so that implementation classes can have a WeakPtrFactory
data member and dispense appropriate WeakPtr instances.

This CL was uploaded by git cl split.

R=takumif@chromium.org

Bug: 647430
Change-Id: I7b11c725f9fda29a06c398f16fb831820dd4de5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4984451
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Auto-Submit: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216724}
  • Loading branch information
David Bertoni authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent d7af739 commit 2afa527
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 17 additions & 14 deletions chrome/browser/media/router/mojo/media_router_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,19 @@ void MediaRouterDesktop::CreateRoute(const MediaSource::Id& source_id,
const mojom::MediaRouteProviderId provider_id = sink->provider_id();

const std::string presentation_id = MediaRouterBase::CreatePresentationId();
auto mr_callback =
base::BindOnce(&MediaRouterDesktop::RouteResponseReceived, AsWeakPtr(),
presentation_id, provider_id, std::move(callback), false);
auto mr_callback = base::BindOnce(&MediaRouterDesktop::RouteResponseReceived,
weak_factory_.GetWeakPtr(), presentation_id,
provider_id, std::move(callback), false);

if (source.IsDesktopMirroringSource()) {
desktop_picker_.Show(
MakeDesktopPickerParams(web_contents),
{DesktopMediaList::Type::kScreen},
base::BindRepeating([](content::WebContents* wc) { return true; }),
base::BindOnce(&MediaRouterDesktop::CreateRouteWithSelectedDesktop,
AsWeakPtr(), provider_id, sink_id, presentation_id,
origin, web_contents, timeout, std::move(mr_callback)));
weak_factory_.GetWeakPtr(), provider_id, sink_id,
presentation_id, origin, web_contents, timeout,
std::move(mr_callback)));
} else {
const int frame_tree_node_id =
web_contents ? web_contents->GetPrimaryMainFrame()->GetFrameTreeNodeId()
Expand Down Expand Up @@ -240,9 +241,9 @@ void MediaRouterDesktop::JoinRoute(const MediaSource::Id& source_id,
const int frame_tree_node_id =
web_contents ? web_contents->GetPrimaryMainFrame()->GetFrameTreeNodeId()
: kDefaultFrameTreeNodeId;
auto mr_callback =
base::BindOnce(&MediaRouterDesktop::RouteResponseReceived, AsWeakPtr(),
presentation_id, *provider_id, std::move(callback), true);
auto mr_callback = base::BindOnce(&MediaRouterDesktop::RouteResponseReceived,
weak_factory_.GetWeakPtr(), presentation_id,
*provider_id, std::move(callback), true);
media_route_providers_[*provider_id]->JoinRoute(
source_id, presentation_id, origin, frame_tree_node_id, timeout,
std::move(mr_callback));
Expand All @@ -257,8 +258,9 @@ void MediaRouterDesktop::TerminateRoute(const MediaRoute::Id& route_id) {
mojom::RouteRequestResultCode::ROUTE_NOT_FOUND);
return;
}
auto callback = base::BindOnce(&MediaRouterDesktop::OnTerminateRouteResult,
AsWeakPtr(), route_id, *provider_id);
auto callback =
base::BindOnce(&MediaRouterDesktop::OnTerminateRouteResult,
weak_factory_.GetWeakPtr(), route_id, *provider_id);
media_route_providers_[*provider_id]->TerminateRoute(route_id,
std::move(callback));
}
Expand Down Expand Up @@ -357,7 +359,7 @@ void MediaRouterDesktop::GetMediaController(
return;
}
auto callback = base::BindOnce(&MediaRouterDesktop::OnMediaControllerCreated,
AsWeakPtr(), route_id);
weak_factory_.GetWeakPtr(), route_id);
media_route_providers_[*provider_id]->CreateMediaRouteController(
route_id, std::move(controller), std::move(observer),
std::move(callback));
Expand Down Expand Up @@ -464,8 +466,9 @@ void MediaRouterDesktop::RegisterMediaRoutesObserver(
// MediaRoutesObserver is calling this method from its constructor, and that
// must complete before invoking its virtual OnRoutesUpdated() method.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&MediaRouterDesktop::NotifyOfExistingRoutes,
AsWeakPtr(), observer->AsWeakPtr()));
FROM_HERE,
base::BindOnce(&MediaRouterDesktop::NotifyOfExistingRoutes,
weak_factory_.GetWeakPtr(), observer->AsWeakPtr()));
}
}

Expand Down Expand Up @@ -514,7 +517,7 @@ void MediaRouterDesktop::RegisterMediaRouteProvider(
std::move(media_route_provider_remote));
bound_remote.set_disconnect_handler(
base::BindOnce(&MediaRouterDesktop::OnProviderConnectionError,
AsWeakPtr(), provider_id));
weak_factory_.GetWeakPtr(), provider_id));
media_route_providers_[provider_id] = std::move(bound_remote);
}

Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/media/router/mojo/media_router_desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class DualMediaSinkService;
class WiredDisplayMediaRouteProvider;

// MediaRouter implementation that uses the desktop MediaRouteProviders.
class MediaRouterDesktop : public MediaRouterBase,
public mojom::MediaRouter,
public base::SupportsWeakPtr<MediaRouterDesktop> {
class MediaRouterDesktop : public MediaRouterBase, public mojom::MediaRouter {
public:
explicit MediaRouterDesktop(content::BrowserContext* context);
MediaRouterDesktop(const MediaRouterDesktop&) = delete;
Expand Down

0 comments on commit 2afa527

Please sign in to comment.