Commit 5f59f88a authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate InstalledAppController to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I50f4ee672c7c94c37655107c4eeab8c8960bd6ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134094Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756592}
parent c2dd43c1
......@@ -12,6 +12,7 @@
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/manifest/manifest_manager.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
......@@ -54,11 +55,8 @@ const char InstalledAppController::kSupplementName[] = "InstalledAppController";
InstalledAppController::InstalledAppController(LocalFrame& frame)
: Supplement<LocalFrame>(frame),
ExecutionContextLifecycleObserver(frame.GetDocument()) {}
void InstalledAppController::ContextDestroyed() {
provider_.reset();
}
ExecutionContextClient(frame.DomWindow()),
provider_(frame.DomWindow()) {}
void InstalledAppController::OnGetManifestForRelatedApps(
std::unique_ptr<AppInstalledCallbacks> callbacks,
......@@ -74,7 +72,7 @@ void InstalledAppController::OnGetManifestForRelatedApps(
mojo_related_apps.push_back(std::move(application));
}
if (!provider_) {
if (!provider_.is_bound()) {
// See https://bit.ly/2S0zRAS for task types.
GetSupplementable()->GetBrowserInterfaceBroker().GetInterface(
provider_.BindNewPipeAndPassReceiver(
......@@ -82,7 +80,7 @@ void InstalledAppController::OnGetManifestForRelatedApps(
// TODO(mgiuca): Set a connection error handler. This requires a refactor to
// work like NavigatorShare.cpp (retain a persistent list of clients to
// reject all of their promises).
DCHECK(provider_);
DCHECK(provider_.is_bound());
}
provider_->FilterInstalledApps(
......@@ -107,8 +105,9 @@ void InstalledAppController::OnFilterInstalledApps(
}
void InstalledAppController::Trace(Visitor* visitor) {
visitor->Trace(provider_);
Supplement<LocalFrame>::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
ExecutionContextClient::Trace(visitor);
}
} // namespace blink
......@@ -9,7 +9,6 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom-blink.h"
#include "third_party/blink/public/mojom/installedapp/related_application.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink-forward.h"
......@@ -20,6 +19,7 @@
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
......@@ -31,7 +31,7 @@ using AppInstalledCallbacks =
class MODULES_EXPORT InstalledAppController final
: public GarbageCollected<InstalledAppController>,
public Supplement<LocalFrame>,
public ExecutionContextLifecycleObserver {
public ExecutionContextClient {
USING_GARBAGE_COLLECTED_MIXIN(InstalledAppController);
public:
......@@ -60,15 +60,12 @@ class MODULES_EXPORT InstalledAppController final
const KURL& url,
mojom::blink::ManifestPtr manifest);
// Inherited from ExecutionContextLifecycleObserver.
void ContextDestroyed() override;
// Callback from the InstalledAppProvider mojo service.
void OnFilterInstalledApps(std::unique_ptr<AppInstalledCallbacks>,
Vector<mojom::blink::RelatedApplicationPtr>);
// Handle to the InstalledApp mojo service.
mojo::Remote<mojom::blink::InstalledAppProvider> provider_;
HeapMojoRemote<mojom::blink::InstalledAppProvider> provider_;
DISALLOW_COPY_AND_ASSIGN(InstalledAppController);
};
......
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