process-internals: Show agent_scheduling_group_id for frames

This CL extends the chrome://process-internals UI to display
AgentSchedulingGroupHost ID.

Bug: 1111231
Change-Id: I26656239d6e860d646402eb93ec8ee9c799fd7ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546346
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Tal Pressman <talp@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829474}
diff --git a/content/browser/process_internals/process_internals.mojom b/content/browser/process_internals/process_internals.mojom
index 1a9498e7..7109cb1f 100644
--- a/content/browser/process_internals/process_internals.mojom
+++ b/content/browser/process_internals/process_internals.mojom
@@ -27,6 +27,7 @@
 // Basic information describing a frame and all of its subframes.
 struct FrameInfo {
   int32 routing_id;
+  int32 agent_scheduling_group_id;
   int32 process_id;
 
   SiteInstanceInfo site_instance;
diff --git a/content/browser/process_internals/process_internals_handler_impl.cc b/content/browser/process_internals/process_internals_handler_impl.cc
index ad8b19e..5eed173 100644
--- a/content/browser/process_internals/process_internals_handler_impl.cc
+++ b/content/browser/process_internals/process_internals_handler_impl.cc
@@ -11,6 +11,7 @@
 #include "base/strings/string_piece.h"
 #include "content/browser/child_process_security_policy_impl.h"
 #include "content/browser/process_internals/process_internals.mojom.h"
+#include "content/browser/renderer_host/agent_scheduling_group_host.h"
 #include "content/browser/renderer_host/back_forward_cache_impl.h"
 #include "content/browser/renderer_host/navigation_controller_impl.h"
 #include "content/browser/renderer_host/navigation_entry_impl.h"
@@ -32,6 +33,8 @@
   auto frame_info = ::mojom::FrameInfo::New();
 
   frame_info->routing_id = frame->GetRoutingID();
+  frame_info->agent_scheduling_group_id =
+      frame->agent_scheduling_group().id_for_debugging();
   frame_info->process_id = frame->GetProcess()->GetID();
   frame_info->last_committed_url =
       frame->GetLastCommittedURL().is_valid()
diff --git a/content/browser/renderer_host/agent_scheduling_group_host.cc b/content/browser/renderer_host/agent_scheduling_group_host.cc
index 492dfe5c..7954769a 100644
--- a/content/browser/renderer_host/agent_scheduling_group_host.cc
+++ b/content/browser/renderer_host/agent_scheduling_group_host.cc
@@ -72,6 +72,11 @@
   return agent_group;
 }
 
+int32_t AgentSchedulingGroupHost::GetNextID() {
+  static int32_t next_id = 0;
+  return next_id++;
+}
+
 AgentSchedulingGroupHost::AgentSchedulingGroupHost(RenderProcessHost& process)
     : process_(process),
       association_mode_(base::FeatureList::IsEnabled(
diff --git a/content/browser/renderer_host/agent_scheduling_group_host.h b/content/browser/renderer_host/agent_scheduling_group_host.h
index db4e4d71..6993ca0 100644
--- a/content/browser/renderer_host/agent_scheduling_group_host.h
+++ b/content/browser/renderer_host/agent_scheduling_group_host.h
@@ -63,6 +63,8 @@
   // Returns |false| if any part of the initialization failed.
   bool Init();
 
+  int32_t id_for_debugging() const { return id_for_debugging_; }
+
   // IPC and mojo messages to be forwarded to the RenderProcessHost, for now. In
   // the future they will be handled directly by the AgentSchedulingGroupHost.
   // IPC:
@@ -136,6 +138,8 @@
 
   IPC::Listener* GetListener(int32_t routing_id);
 
+  static int32_t GetNextID();
+
   // The RenderProcessHost this AgentSchedulingGroup is assigned to.
   RenderProcessHost& process_;
 
@@ -152,6 +156,8 @@
   };
   const IPCAssociationMode association_mode_;
 
+  int32_t id_for_debugging_{GetNextID()};
+
   // This AgentSchedulingGroup's legacy IPC channel. Will only be used in
   // `kUnassociated` mode.
   std::unique_ptr<IPC::ChannelProxy> channel_;
diff --git a/content/browser/resources/process/process_internals.html b/content/browser/resources/process/process_internals.html
index fdebf2b..21ba2fe 100644
--- a/content/browser/resources/process/process_internals.html
+++ b/content/browser/resources/process/process_internals.html
@@ -45,7 +45,7 @@
       <div id="tree-view-container">
         <button id="refresh-button">Refresh</button>
         <div>Legend:</div>
-        <div>Frame[<i>process_id</i>:<i>routing_id</i>]:
+        <div>Frame[<i>process_id</i>:<i>routing_id</i>:<i>agent_scheduling_group_id</i>]:
           SI:<i>site_instance_id</i>, <i>whether process is locked to a
             site</i>, site: <i>site_url</i> | url:
           <i>last_committed_url</i>
diff --git a/content/browser/resources/process/process_internals.js b/content/browser/resources/process/process_internals.js
index 782f193..af659f7 100644
--- a/content/browser/resources/process/process_internals.js
+++ b/content/browser/resources/process/process_internals.js
@@ -87,7 +87,8 @@
  */
 function frameToTreeItem(frame) {
   // Compose the string which will appear in the entry for this frame.
-  let itemLabel = `Frame[${frame.processId}:${frame.routingId}]:`;
+  let itemLabel = `Frame[${frame.processId}:${frame.routingId}:${
+    frame.agentSchedulingGroupId}]:`;
   if (frame.isBfcached) {
     itemLabel += ` bfcached`;
   }