[PM] Remove GetWeakPtrOnUIThread

Now that Performance Manager runs on the main thread, this is the same
as GetWeakPtr().

Bug: 40755583
Change-Id: I02a12759000fabb7a3fff903f52cb29a2a9ef8e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6216679
Auto-Submit: Joe Mason <joenotcharles@google.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415643}
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index 874be849..fba0142 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -85,13 +85,6 @@
 #include "base/sequence_checker.h"
 #include "base/synchronization/atomic_flag.h"
 
-namespace performance_manager {
-class FrameNodeImpl;
-class PageNodeImpl;
-class ProcessNodeImpl;
-class WorkerNodeImpl;
-}  // namespace performance_manager
-
 namespace base {
 
 namespace sequence_manager::internal {
@@ -348,10 +341,6 @@
   BindWeakPtrFactoryPassKey() = default;
 
   friend class BindWeakPtrFactoryForTesting;
-  friend class performance_manager::FrameNodeImpl;
-  friend class performance_manager::PageNodeImpl;
-  friend class performance_manager::ProcessNodeImpl;
-  friend class performance_manager::WorkerNodeImpl;
   friend class sequence_manager::internal::TaskQueueImpl;
 };
 
diff --git a/components/performance_manager/execution_context/execution_context_impl.h b/components/performance_manager/execution_context/execution_context_impl.h
index 8e4310f..da20c50 100644
--- a/components/performance_manager/execution_context/execution_context_impl.h
+++ b/components/performance_manager/execution_context/execution_context_impl.h
@@ -13,7 +13,9 @@
 namespace performance_manager {
 
 class FrameNode;
+class FrameNodeImpl;
 class WorkerNode;
+class WorkerNodeImpl;
 
 namespace execution_context {
 
diff --git a/components/performance_manager/graph/frame_node_impl.cc b/components/performance_manager/graph/frame_node_impl.cc
index 74695cd6..3335608 100644
--- a/components/performance_manager/graph/frame_node_impl.cc
+++ b/components/performance_manager/graph/frame_node_impl.cc
@@ -69,13 +69,7 @@
           process_node->GetRenderProcessHostId().value(),
           render_frame_id)),
       is_current_(is_current) {
-  // Nodes are created on the UI thread, then accessed on the PM sequence.
-  // `weak_this_` can be returned from GetWeakPtrOnUIThread() and dereferenced
-  // on the PM sequence.
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  DETACH_FROM_SEQUENCE(sequence_checker_);
-  weak_this_ = weak_factory_.GetWeakPtr();
-
   DCHECK(process_node);
   DCHECK(page_node);
   // A <fencedframe>, MPArch <webview> has no parent node.
@@ -637,11 +631,6 @@
   priority_and_reason_.SetAndMaybeNotify(this, priority_and_reason);
 }
 
-base::WeakPtr<FrameNodeImpl> FrameNodeImpl::GetWeakPtrOnUIThread() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  return weak_this_;
-}
-
 base::WeakPtr<FrameNodeImpl> FrameNodeImpl::GetWeakPtr() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
   return weak_factory_.GetWeakPtr();
@@ -777,12 +766,6 @@
 
 void FrameNodeImpl::OnInitializingProperties() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
-  // Make sure all weak pointers, even `weak_this_` that was created on the UI
-  // thread in the constructor, can only be dereferenced on the graph sequence.
-  weak_factory_.BindToCurrentSequence(
-      base::subtle::BindWeakPtrFactoryPassKey());
-
   NodeAttachedDataStorage::Create(this);
   execution_context::FrameExecutionContext::Create(this, this);
 
diff --git a/components/performance_manager/graph/frame_node_impl.h b/components/performance_manager/graph/frame_node_impl.h
index 9e9ab921..51be697 100644
--- a/components/performance_manager/graph/frame_node_impl.h
+++ b/components/performance_manager/graph/frame_node_impl.h
@@ -172,7 +172,6 @@
   // Invoked to set the frame priority, and the reason behind it.
   void SetPriorityAndReason(const PriorityAndReason& priority_and_reason);
 
-  base::WeakPtr<FrameNodeImpl> GetWeakPtrOnUIThread();
   base::WeakPtr<FrameNodeImpl> GetWeakPtr();
 
   void SeverPageRelationshipsAndMaybeReparentForTesting() {
@@ -444,7 +443,6 @@
   // true, frame visibility updates are ignored.
   bool has_viewport_intersection_updates_ = false;
 
-  base::WeakPtr<FrameNodeImpl> weak_this_;
   base::WeakPtrFactory<FrameNodeImpl> weak_factory_
       GUARDED_BY_CONTEXT(sequence_checker_){this};
 };
diff --git a/components/performance_manager/graph/page_node_impl.cc b/components/performance_manager/graph/page_node_impl.cc
index 921a07f2..61594e63 100644
--- a/components/performance_manager/graph/page_node_impl.cc
+++ b/components/performance_manager/graph/page_node_impl.cc
@@ -42,14 +42,7 @@
   // TODO(crbug.com/40121561): Remove `visible_url` from the constructor in M132
   // if no issues are found with this CHECK.
   CHECK(main_frame_url_.value().is_empty(), base::NotFatalUntil::M132);
-
-  // Nodes are created on the UI thread, then accessed on the PM sequence.
-  // `weak_this_` can be returned from GetWeakPtrOnUIThread() and dereferenced
-  // on the PM sequence.
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  DETACH_FROM_SEQUENCE(sequence_checker_);
-  weak_this_ = weak_factory_.GetWeakPtr();
-
   if (is_audible_.value()) {
     audible_change_time_ = base::TimeTicks::Now();
   }
@@ -235,11 +228,6 @@
   return total;
 }
 
-base::WeakPtr<PageNodeImpl> PageNodeImpl::GetWeakPtrOnUIThread() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  return weak_this_;
-}
-
 base::WeakPtr<PageNodeImpl> PageNodeImpl::GetWeakPtr() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
   return weak_factory_.GetWeakPtr();
@@ -512,12 +500,6 @@
 
 void PageNodeImpl::OnInitializingProperties() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
-  // Make sure all weak pointers, even `weak_this_` that was created on the UI
-  // thread in the constructor, can only be dereferenced on the graph sequence.
-  weak_factory_.BindToCurrentSequence(
-      base::subtle::BindWeakPtrFactoryPassKey());
-
   NodeAttachedDataStorage::Create(this);
 }
 
diff --git a/components/performance_manager/graph/page_node_impl.h b/components/performance_manager/graph/page_node_impl.h
index 345a45ad0..d5be9bb5 100644
--- a/components/performance_manager/graph/page_node_impl.h
+++ b/components/performance_manager/graph/page_node_impl.h
@@ -195,7 +195,6 @@
     SetHadUserEdits(had_user_edits);
   }
 
-  base::WeakPtr<PageNodeImpl> GetWeakPtrOnUIThread();
   base::WeakPtr<PageNodeImpl> GetWeakPtr();
 
   // Functions meant to be called by a FrameNodeImpl:
@@ -415,7 +414,6 @@
       NotifiesOnlyOnChanges<bool, &PageNodeObserver::OnHadUserEditsChanged>
           had_user_edits_ GUARDED_BY_CONTEXT(sequence_checker_){false};
 
-  base::WeakPtr<PageNodeImpl> weak_this_;
   base::WeakPtrFactory<PageNodeImpl> weak_factory_
       GUARDED_BY_CONTEXT(sequence_checker_){this};
 };
diff --git a/components/performance_manager/graph/process_node_impl.cc b/components/performance_manager/graph/process_node_impl.cc
index 2415964..c1915fe9 100644
--- a/components/performance_manager/graph/process_node_impl.cc
+++ b/components/performance_manager/graph/process_node_impl.cc
@@ -66,13 +66,7 @@
     : process_type_(process_type),
       child_process_host_proxy_(std::move(proxy)),
       priority_(priority) {
-  // Nodes are created on the UI thread, then accessed on the PM sequence.
-  // `weak_this_` can be returned from GetWeakPtrOnUIThread() and dereferenced
-  // on the PM sequence.
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  DETACH_FROM_SEQUENCE(sequence_checker_);
-  weak_this_ = weak_factory_.GetWeakPtr();
-
   // Child process nodes must have a valid proxy.
   switch (process_type) {
     case content::PROCESS_TYPE_BROWSER:
@@ -392,11 +386,6 @@
   hosted_content_types_.Put(content_type);
 }
 
-base::WeakPtr<ProcessNodeImpl> ProcessNodeImpl::GetWeakPtrOnUIThread() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  return weak_this_;
-}
-
 base::WeakPtr<ProcessNodeImpl> ProcessNodeImpl::GetWeakPtr() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
   return weak_factory_.GetWeakPtr();
@@ -450,12 +439,6 @@
 
 void ProcessNodeImpl::OnInitializingProperties() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
-  // Make sure all weak pointers, even `weak_this_` that was created on the UI
-  // thread in the constructor, can only be dereferenced on the graph sequence.
-  weak_factory_.BindToCurrentSequence(
-      base::subtle::BindWeakPtrFactoryPassKey());
-
   NodeAttachedDataStorage::Create(this);
 }
 
diff --git a/components/performance_manager/graph/process_node_impl.h b/components/performance_manager/graph/process_node_impl.h
index f7f2cfc7..9fb83899 100644
--- a/components/performance_manager/graph/process_node_impl.h
+++ b/components/performance_manager/graph/process_node_impl.h
@@ -181,7 +181,6 @@
 
   void OnAllFramesInProcessFrozenForTesting() { OnAllFramesInProcessFrozen(); }
 
-  base::WeakPtr<ProcessNodeImpl> GetWeakPtrOnUIThread();
   base::WeakPtr<ProcessNodeImpl> GetWeakPtr();
 
   static PassKey CreatePassKeyForTesting() { return PassKey(); }
@@ -273,7 +272,6 @@
 
   NodeSet worker_nodes_ GUARDED_BY_CONTEXT(sequence_checker_);
 
-  base::WeakPtr<ProcessNodeImpl> weak_this_;
   base::WeakPtrFactory<ProcessNodeImpl> weak_factory_
       GUARDED_BY_CONTEXT(sequence_checker_){this};
 };
diff --git a/components/performance_manager/graph/worker_node_impl.cc b/components/performance_manager/graph/worker_node_impl.cc
index 4433ff2b..e8c036b 100644
--- a/components/performance_manager/graph/worker_node_impl.cc
+++ b/components/performance_manager/graph/worker_node_impl.cc
@@ -27,13 +27,7 @@
       process_node_(process_node),
       worker_token_(worker_token),
       origin_(origin) {
-  // Nodes are created on the UI thread, then accessed on the PM sequence.
-  // `weak_this_` can be returned from GetWeakPtrOnUIThread() and dereferenced
-  // on the PM sequence.
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  DETACH_FROM_SEQUENCE(sequence_checker_);
-  weak_this_ = weak_factory_.GetWeakPtr();
-
   DCHECK(process_node);
 }
 
@@ -211,11 +205,6 @@
   return NodeSetView<WorkerNodeImpl*>(child_workers_);
 }
 
-base::WeakPtr<WorkerNodeImpl> WorkerNodeImpl::GetWeakPtrOnUIThread() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  return weak_this_;
-}
-
 base::WeakPtr<WorkerNodeImpl> WorkerNodeImpl::GetWeakPtr() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
   return weak_factory_.GetWeakPtr();
@@ -223,12 +212,6 @@
 
 void WorkerNodeImpl::OnInitializingProperties() {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
-  // Make sure all weak pointers, even `weak_this_` that was created on the UI
-  // thread in the constructor, can only be dereferenced on the graph sequence.
-  weak_factory_.BindToCurrentSequence(
-      base::subtle::BindWeakPtrFactoryPassKey());
-
   NodeAttachedDataStorage::Create(this);
   execution_context::WorkerExecutionContext::Create(this, this);
 }
diff --git a/components/performance_manager/graph/worker_node_impl.h b/components/performance_manager/graph/worker_node_impl.h
index f3a3e071..5864c0de 100644
--- a/components/performance_manager/graph/worker_node_impl.h
+++ b/components/performance_manager/graph/worker_node_impl.h
@@ -86,7 +86,6 @@
   NodeSetView<WorkerNodeImpl*> client_workers() const;
   NodeSetView<WorkerNodeImpl*> child_workers() const;
 
-  base::WeakPtr<WorkerNodeImpl> GetWeakPtrOnUIThread();
   base::WeakPtr<WorkerNodeImpl> GetWeakPtr();
 
  private:
@@ -157,7 +156,6 @@
           PriorityAndReason(base::TaskPriority::LOWEST,
                             kDefaultPriorityReason)};
 
-  base::WeakPtr<WorkerNodeImpl> weak_this_;
   base::WeakPtrFactory<WorkerNodeImpl> weak_factory_
       GUARDED_BY_CONTEXT(sequence_checker_){this};
 };
diff --git a/components/performance_manager/performance_manager.cc b/components/performance_manager/performance_manager.cc
index ab5a404..6c10ca2 100644
--- a/components/performance_manager/performance_manager.cc
+++ b/components/performance_manager/performance_manager.cc
@@ -76,7 +76,7 @@
       PerformanceManagerTabHelper::FromWebContents(wc);
   if (!helper)
     return nullptr;
-  return helper->primary_page_node()->GetWeakPtrOnUIThread();
+  return helper->primary_page_node()->GetWeakPtr();
 }
 
 // static
@@ -95,7 +95,7 @@
     DCHECK(!rfh->IsRenderFrameLive());
     return nullptr;
   }
-  return frame_node->GetWeakPtrOnUIThread();
+  return frame_node->GetWeakPtr();
 }
 
 // static
@@ -106,7 +106,7 @@
     return nullptr;
   }
   ProcessNodeImpl* process_node = registry->GetBrowserProcessNode();
-  return process_node ? process_node->GetWeakPtrOnUIThread() : nullptr;
+  return process_node ? process_node->GetWeakPtr() : nullptr;
 }
 
 // static
@@ -121,7 +121,7 @@
   // indirectly from RenderProcessHost::Init.)
   if (!user_data)
     return nullptr;
-  return user_data->process_node()->GetWeakPtrOnUIThread();
+  return user_data->process_node()->GetWeakPtr();
 }
 
 // static
@@ -154,7 +154,7 @@
     return nullptr;
   }
   ProcessNodeImpl* process_node = registry->GetBrowserChildProcessNode(id);
-  return process_node ? process_node->GetWeakPtrOnUIThread() : nullptr;
+  return process_node ? process_node->GetWeakPtr() : nullptr;
 }
 
 // static
@@ -165,7 +165,7 @@
     return nullptr;
   }
   WorkerNodeImpl* worker_node = registry->FindWorkerNodeForToken(token);
-  return worker_node ? worker_node->GetWeakPtrOnUIThread() : nullptr;
+  return worker_node ? worker_node->GetWeakPtr() : nullptr;
 }
 
 // static
diff --git a/components/performance_manager/resource_attribution/page_context.cc b/components/performance_manager/resource_attribution/page_context.cc
index ef3f8cd..1e946ff 100644
--- a/components/performance_manager/resource_attribution/page_context.cc
+++ b/components/performance_manager/resource_attribution/page_context.cc
@@ -53,7 +53,7 @@
   PageNodeImpl* node_impl = tab_helper->primary_page_node();
   CHECK(node_impl);
   return PageContext(node_impl->page_token().value(), contents->GetWeakPtr(),
-                     node_impl->GetWeakPtrOnUIThread());
+                     node_impl->GetWeakPtr());
 }
 
 content::WebContents* PageContext::GetWebContents() const {