| Index: chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc
|
| diff --git a/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc b/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc
|
| index 7adf73b56980dc5ec11585bee1f120e79c7996c1..2b767ac522b432fb09229012a520136cdcaa55da 100644
|
| --- a/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc
|
| +++ b/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc
|
| @@ -6,16 +6,20 @@
|
|
|
| #include <utility>
|
|
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "components/ukm/public/interfaces/ukm_interface.mojom.h"
|
| +#include "components/ukm/public/ukm_recorder.h"
|
| #include "content/public/browser/navigation_handle.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/common/service_manager_connection.h"
|
| #include "content/public/common/service_names.mojom.h"
|
| #include "services/resource_coordinator/public/cpp/resource_coordinator_features.h"
|
| -#include "services/resource_coordinator/public/interfaces/service_callbacks.mojom.h"
|
| +#include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h"
|
| #include "services/resource_coordinator/public/interfaces/service_constants.mojom.h"
|
| #include "services/service_manager/public/cpp/connector.h"
|
| +#include "url/gurl.h"
|
|
|
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver);
|
|
|
| @@ -97,6 +101,11 @@ void ResourceCoordinatorWebContentsObserver::DidFinishNavigation(
|
| return;
|
| }
|
|
|
| + if (navigation_handle->IsInMainFrame()) {
|
| + url_ = navigation_handle->GetURL().spec();
|
| + UpdateUkmRecorder();
|
| + }
|
| +
|
| content::RenderFrameHost* render_frame_host =
|
| navigation_handle->GetRenderFrameHost();
|
|
|
| @@ -104,7 +113,31 @@ void ResourceCoordinatorWebContentsObserver::DidFinishNavigation(
|
| render_frame_host->GetFrameResourceCoordinator();
|
| tab_resource_coordinator_->AddChild(*frame_resource_coordinator);
|
|
|
| + auto* parent_render_frame_host = render_frame_host->GetParent();
|
| + if (parent_render_frame_host) {
|
| + auto* parent_frame_resource_coordinator =
|
| + parent_render_frame_host->GetFrameResourceCoordinator();
|
| + parent_frame_resource_coordinator->AddChild(*frame_resource_coordinator);
|
| + }
|
| +
|
| + // the frame's coordination unit needs to registered as the process
|
| + // coordination unit's child after it is registered as the parent
|
| + // frame's child so that the process coordination can immediately
|
| + // determine whether or not the the added frame child is the main frame.
|
| auto* process_resource_coordinator =
|
| render_frame_host->GetProcess()->GetProcessResourceCoordinator();
|
| process_resource_coordinator->AddChild(*frame_resource_coordinator);
|
| }
|
| +
|
| +void ResourceCoordinatorWebContentsObserver::UpdateUkmRecorder() {
|
| + ukm_source_id_ = ukm::UkmRecorder::GetNewSourceID();
|
| + g_browser_process->ukm_recorder()->UpdateSourceURL(ukm_source_id_,
|
| + GURL(url_));
|
| + // SourceID types need to be converted to a string because base::Value
|
| + // does not guarrantee that its int type will be 64 bits. Instead
|
| + // std:string is used as a canonical format. base::Int64ToString
|
| + // and base::StringToInt64 are used for encoding/decoding respectively.
|
| + tab_resource_coordinator_->SetProperty(
|
| + resource_coordinator::mojom::PropertyType::kTabUkmSourceId,
|
| + base::MakeUnique<base::Value>(base::Int64ToString(ukm_source_id_)));
|
| +}
|
|
|