Commit 427710a7 authored by Peiyong Lin's avatar Peiyong Lin Committed by Commit Bot

[GRC] Replace TabSignalObserver generic APIs with concrete APIs.

As part of the progress to make GRC strongly typed, we also lean towards to
making output mojo interface strongly-typed when needed. This patch removes the
current two generic APIs from the mojo interface and creates two APIs that are
used by the current TabSignalObserver implementation.

BUG=775691

Change-Id: I3ddd06fc723dd63982be21ee39e5809305765751
Reviewed-on: https://chromium-review.googlesource.com/747962Reviewed-by: default avatarZhen Wang <zhenw@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: lpy <lpy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513269}
parent cf7bb4c0
......@@ -55,33 +55,25 @@ TabManager::GRCTabSignalObserver::GRCTabSignalObserver() : binding_(this) {
TabManager::GRCTabSignalObserver::~GRCTabSignalObserver() = default;
void TabManager::GRCTabSignalObserver::OnEventReceived(
const CoordinationUnitID& cu_id,
mojom::TabEvent event) {
if (event == mojom::TabEvent::kDoneLoading) {
auto web_contents_iter = cu_id_web_contents_map_.find(cu_id);
if (web_contents_iter == cu_id_web_contents_map_.end())
return;
auto* web_contents_data =
TabManager::WebContentsData::FromWebContents(web_contents_iter->second);
web_contents_data->DoneLoading();
}
void TabManager::GRCTabSignalObserver::NotifyPageAlmostIdle(
const CoordinationUnitID& cu_id) {
auto web_contents_iter = cu_id_web_contents_map_.find(cu_id);
if (web_contents_iter == cu_id_web_contents_map_.end())
return;
auto* web_contents_data =
TabManager::WebContentsData::FromWebContents(web_contents_iter->second);
web_contents_data->NotifyAlmostIdle();
}
void TabManager::GRCTabSignalObserver::OnPropertyChanged(
void TabManager::GRCTabSignalObserver::SetExpectedTaskQueueingDuration(
const CoordinationUnitID& cu_id,
mojom::PropertyType property_type,
int64_t value) {
if (property_type == mojom::PropertyType::kExpectedTaskQueueingDuration) {
auto web_contents_iter = cu_id_web_contents_map_.find(cu_id);
if (web_contents_iter == cu_id_web_contents_map_.end())
return;
g_browser_process->GetTabManager()
->stats_collector()
->RecordExpectedTaskQueueingDuration(
web_contents_iter->second,
base::TimeDelta::FromMilliseconds(value));
}
base::TimeDelta duration) {
auto web_contents_iter = cu_id_web_contents_map_.find(cu_id);
if (web_contents_iter == cu_id_web_contents_map_.end())
return;
g_browser_process->GetTabManager()
->stats_collector()
->RecordExpectedTaskQueueingDuration(web_contents_iter->second, duration);
}
void TabManager::GRCTabSignalObserver::
......
......@@ -30,11 +30,9 @@ class TabManager::GRCTabSignalObserver : public mojom::TabSignalObserver {
static GRCTabSignalObserver* GetInstance();
// mojom::TabSignalObserver implementation.
void OnEventReceived(const CoordinationUnitID& cu_id,
mojom::TabEvent event) override;
void OnPropertyChanged(const CoordinationUnitID& cu_id,
mojom::PropertyType property_type,
int64_t value) override;
void NotifyPageAlmostIdle(const CoordinationUnitID& cu_id) override;
void SetExpectedTaskQueueingDuration(const CoordinationUnitID& cu_id,
base::TimeDelta duration) override;
void AssociateCoordinationUnitIDWithWebContents(
const CoordinationUnitID& cu_id,
......
......@@ -63,8 +63,8 @@ class TabManager::WebContentsData
void WasShown() override;
void WebContentsDestroyed() override;
// Tab signal received from GRC.
void DoneLoading() {}
// idle signal received from GRC.
void NotifyAlmostIdle() {}
// Returns true if the tab has been discarded to save memory.
bool IsDiscarded();
......
......@@ -6,16 +6,15 @@
#include <utility>
#include "base/values.h"
#include "services/resource_coordinator/coordination_unit/frame_coordination_unit_impl.h"
#include "services/resource_coordinator/coordination_unit/page_coordination_unit_impl.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
namespace resource_coordinator {
#define DISPATCH_TAB_SIGNAL(observers, METHOD, cu, ...) \
#define DISPATCH_TAB_SIGNAL(observers, METHOD, ...) \
observers.ForAllPtrs([&](mojom::TabSignalObserver* observer) { \
observer->METHOD(cu->id(), __VA_ARGS__); \
observer->METHOD(__VA_ARGS__); \
});
TabSignalGeneratorImpl::TabSignalGeneratorImpl() = default;
......@@ -43,8 +42,7 @@ void TabSignalGeneratorImpl::OnFramePropertyChanged(
return;
// TODO(lpy) Combine CPU usage or long task idleness signal.
if (auto* page_cu = frame_cu->GetPageCoordinationUnit()) {
DISPATCH_TAB_SIGNAL(observers_, OnEventReceived, page_cu,
mojom::TabEvent::kDoneLoading);
DISPATCH_TAB_SIGNAL(observers_, NotifyPageAlmostIdle, page_cu->id());
}
}
}
......@@ -54,8 +52,9 @@ void TabSignalGeneratorImpl::OnPagePropertyChanged(
const mojom::PropertyType property_type,
int64_t value) {
if (property_type == mojom::PropertyType::kExpectedTaskQueueingDuration) {
DISPATCH_TAB_SIGNAL(observers_, OnPropertyChanged, page_cu, property_type,
value);
DISPATCH_TAB_SIGNAL(observers_, SetExpectedTaskQueueingDuration,
page_cu->id(),
base::TimeDelta::FromMilliseconds(value));
}
}
......
......@@ -5,13 +5,7 @@
module resource_coordinator.mojom;
import "coordination_unit.mojom";
import "mojo/common/values.mojom";
import "signals.mojom";
// Event signal scoped to a tab.
enum TabEvent {
kDoneLoading,
};
import "mojo/common/time.mojom";
// A TabSignalObserver implementation receives tab-scoped signal from
// TabSignalGenerator.
......@@ -20,9 +14,9 @@ enum TabEvent {
// pass the interface pointer of mojo channel to TabSignalGenerator through
// TabSignalGenerator::AddObserver.
interface TabSignalObserver {
OnEventReceived(CoordinationUnitID cu_id, TabEvent event);
OnPropertyChanged(CoordinationUnitID cu_id, PropertyType property_type,
int64 value);
NotifyPageAlmostIdle(CoordinationUnitID cu_id);
SetExpectedTaskQueueingDuration(CoordinationUnitID cu_id,
mojo.common.mojom.TimeDelta duration);
};
// A TabSignalGenerator implementation will be implemented inside GRC to observe
......
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