Skip to content

Commit

Permalink
PM: Move the PerformanceManager mojom files into the component.
Browse files Browse the repository at this point in the history
Bug: 953031
Change-Id: I1f74e20583840d40ab8d2c99c86f44125bad7143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845966
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704283}
  • Loading branch information
sigurasg authored and Commit Bot committed Oct 9, 2019
1 parent 0bbefb9 commit e643af0
Show file tree
Hide file tree
Showing 40 changed files with 140 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
#include "components/performance_manager/render_process_user_data.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"

namespace {

void BindProcessNode(
int render_process_host_id,
mojo::PendingReceiver<resource_coordinator::mojom::ProcessCoordinationUnit>
mojo::PendingReceiver<performance_manager::mojom::ProcessCoordinationUnit>
receiver) {
content::RenderProcessHost* render_process_host =
content::RenderProcessHost::FromID(render_process_host_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace performance_manager {

using LifecycleState = resource_coordinator::mojom::LifecycleState;
using LifecycleState = performance_manager::mojom::LifecycleState;

// Provides FrozenFrameAggregator machinery access to some internals of a
// PageNodeImpl and ProcessNodeImpl.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#include "components/performance_manager/graph/node_attached_data_impl.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"

namespace performance_manager {

using resource_coordinator::mojom::InterventionPolicy;
using performance_manager::mojom::InterventionPolicy;

// Provides PageAggregator machinery access to some internals
// of a PageNodeImpl.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "components/performance_manager/graph/graph_impl_operations.h"
#include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
#include "components/performance_manager/test_support/graph_test_harness.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace performance_manager {

using resource_coordinator::mojom::InterventionPolicy;
using performance_manager::mojom::InterventionPolicy;

namespace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ std::string GetContentForURL(const std::string& url) {
}

void RunOriginTrialTestOnPMSequence(
const resource_coordinator::mojom::InterventionPolicy expected_policy) {
const mojom::InterventionPolicy expected_policy) {
auto* perf_manager = PerformanceManagerImpl::GetInstance();
ASSERT_TRUE(perf_manager);
base::RunLoop run_loop;
perf_manager->CallOnGraphImpl(
FROM_HERE, base::BindOnce(
[](base::OnceClosure quit_closure,
const resource_coordinator::mojom::InterventionPolicy
expected_policy,
const mojom::InterventionPolicy expected_policy,
performance_manager::GraphImpl* graph) {
auto page_nodes = graph->GetAllPageNodeImpls();
EXPECT_EQ(1U, page_nodes.size());
Expand Down Expand Up @@ -225,8 +224,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest, PageFreezeOriginTrialOptIn) {
{kOriginTrialTestHostname,
kOriginTrialFreezePolicyTestPath, kOriginTrialOptInPage},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptIn);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptIn);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest, PageFreezeOriginTrialOptOut) {
Expand All @@ -235,8 +233,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest, PageFreezeOriginTrialOptOut) {
{kOriginTrialTestHostname,
kOriginTrialFreezePolicyTestPath, kOriginTrialOptOutPage},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptOut);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptOut);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest, PageFreezeOriginTrialDefault) {
Expand All @@ -245,8 +242,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest, PageFreezeOriginTrialDefault) {
kOriginTrialFreezePolicyTestPath,
kOriginTrialDefaultPage},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kDefault);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kDefault);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -255,8 +251,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialOptInOptOut},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptOut);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptOut);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -265,8 +260,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialOptOutOptIn},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptOut);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptOut);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -275,8 +269,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialDefaultOptIn},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptIn);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptIn);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -285,8 +278,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialDefaultOptOut},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptOut);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptOut);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -295,8 +287,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialOptInOptIn},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptIn);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptIn);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -305,8 +296,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialOptOutOptOut},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kOptOut);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kOptOut);
}

IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
Expand All @@ -315,8 +305,7 @@ IN_PROC_BROWSER_TEST_F(PageNodeImplBrowserTest,
browser(), GURL(base::JoinString({kOriginTrialTestHostname, k2iFramesPath,
kOriginTrialDefaultDefault},
"/")));
RunOriginTrialTestOnPMSequence(
resource_coordinator::mojom::InterventionPolicy::kDefault);
RunOriginTrialTestOnPMSequence(mojom::InterventionPolicy::kDefault);
}

// TODO(sebmarchand): Add more tests, e.g. a test where the main frame and a
Expand Down
16 changes: 8 additions & 8 deletions chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ void TabLifecycleUnitSource::TabLifecycleUnit::SetRecentlyAudible(
}

void TabLifecycleUnitSource::TabLifecycleUnit::UpdateLifecycleState(
mojom::LifecycleState state) {
performance_manager::mojom::LifecycleState state) {
switch (state) {
case mojom::LifecycleState::kFrozen: {
case performance_manager::mojom::LifecycleState::kFrozen: {
switch (GetState()) {
case LifecycleUnitState::PENDING_DISCARD: {
freeze_timeout_timer_->Stop();
Expand All @@ -405,7 +405,7 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateLifecycleState(
break;
}

case mojom::LifecycleState::kRunning: {
case performance_manager::mojom::LifecycleState::kRunning: {
SetState(LifecycleUnitState::ACTIVE,
StateChangeReason::RENDERER_INITIATED);
break;
Expand All @@ -419,7 +419,7 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateLifecycleState(
}

void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy(
mojom::InterventionPolicy policy) {
performance_manager::mojom::InterventionPolicy policy) {
origin_trial_freeze_policy_ = policy;
}

Expand Down Expand Up @@ -1024,16 +1024,16 @@ void TabLifecycleUnitSource::TabLifecycleUnit::CanFreezeHeuristicsChecks(

// Apply origin trial opt-in/opt-out (policy is per page).
switch (origin_trial_freeze_policy_) {
case mojom::InterventionPolicy::kUnknown:
case performance_manager::mojom::InterventionPolicy::kUnknown:
decision_details->AddReason(DecisionFailureReason::ORIGIN_TRIAL_UNKNOWN);
break;
case mojom::InterventionPolicy::kOptOut:
case performance_manager::mojom::InterventionPolicy::kOptOut:
decision_details->AddReason(DecisionFailureReason::ORIGIN_TRIAL_OPT_OUT);
break;
case mojom::InterventionPolicy::kOptIn:
case performance_manager::mojom::InterventionPolicy::kOptIn:
decision_details->AddReason(DecisionSuccessReason::ORIGIN_TRIAL_OPT_IN);
break;
case mojom::InterventionPolicy::kDefault:
case performance_manager::mojom::InterventionPolicy::kDefault:
// Let other heuristics determine whether the tab can be frozen.
break;
}
Expand Down
11 changes: 6 additions & 5 deletions chrome/browser/resource_coordinator/tab_lifecycle_unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h"
#include "chrome/browser/resource_coordinator/time.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/page_importance_signals.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"

class TabStripModel;

Expand Down Expand Up @@ -88,10 +88,11 @@ class TabLifecycleUnitSource::TabLifecycleUnit

// Updates the tab's lifecycle state when changed outside the tab lifecycle
// unit.
void UpdateLifecycleState(mojom::LifecycleState state);
void UpdateLifecycleState(performance_manager::mojom::LifecycleState state);

// Updates the tab's origin trial freeze policy.
void UpdateOriginTrialFreezePolicy(mojom::InterventionPolicy policy);
void UpdateOriginTrialFreezePolicy(
performance_manager::mojom::InterventionPolicy policy);

// Setters for the WebLock and IndexedDB lock usage properties.
void SetIsHoldingWebLock(bool is_holding_weblock);
Expand Down Expand Up @@ -212,8 +213,8 @@ class TabLifecycleUnitSource::TabLifecycleUnit

// The freeze policy set via origin trial. Initial value is kDefault to avoid
// affecting CanFreeze() before the policy is set for the first time.
mojom::InterventionPolicy origin_trial_freeze_policy_ =
mojom::InterventionPolicy::kDefault;
performance_manager::mojom::InterventionPolicy origin_trial_freeze_policy_ =
performance_manager::mojom::InterventionPolicy::kDefault;

// Maintains the most recent LifecycleUnitDiscardReason that was passed into
// Discard().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TabLifecycleStateObserver
private:
static void OnLifecycleStateChangedImpl(
const WebContentsProxy& contents_proxy,
mojom::LifecycleState state) {
performance_manager::mojom::LifecycleState state) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If the web contents is still alive then dispatch to the actual
// implementation in TabLifecycleUnitSource.
Expand All @@ -87,7 +87,7 @@ class TabLifecycleStateObserver

static void OnOriginTrialFreezePolicyChangedImpl(
const WebContentsProxy& contents_proxy,
mojom::InterventionPolicy policy) {
performance_manager::mojom::InterventionPolicy policy) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If the web contents is still alive then dispatch to the actual
// implementation in TabLifecycleUnitSource.
Expand Down Expand Up @@ -404,7 +404,7 @@ void TabLifecycleUnitSource::OnBrowserNoLongerActive(Browser* browser) {
// static
void TabLifecycleUnitSource::OnLifecycleStateChanged(
content::WebContents* web_contents,
mojom::LifecycleState state) {
performance_manager::mojom::LifecycleState state) {
TabLifecycleUnit* lifecycle_unit = GetTabLifecycleUnit(web_contents);

// Some WebContents aren't attached to a tab, so there is no corresponding
Expand All @@ -417,7 +417,7 @@ void TabLifecycleUnitSource::OnLifecycleStateChanged(
// static
void TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
content::WebContents* web_contents,
mojom::InterventionPolicy policy) {
performance_manager::mojom::InterventionPolicy policy) {
TabLifecycleUnit* lifecycle_unit = GetTabLifecycleUnit(web_contents);

// Some WebContents aren't attached to a tab, so there is no corresponding
Expand Down
11 changes: 6 additions & 5 deletions chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_tab_strip_tracker.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"
#include "services/resource_coordinator/public/mojom/lifecycle.mojom.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
#include "components/performance_manager/public/mojom/lifecycle.mojom.h"

class PrefChangeRegistrar;
class PrefService;
Expand Down Expand Up @@ -149,11 +149,12 @@ class TabLifecycleUnitSource : public BrowserListObserver,

// This is called indirectly from the corresponding event on a PageNode in the
// performance_manager Graph.
static void OnLifecycleStateChanged(content::WebContents* web_contents,
mojom::LifecycleState state);
static void OnLifecycleStateChanged(
content::WebContents* web_contents,
performance_manager::mojom::LifecycleState state);
static void OnOriginTrialFreezePolicyChanged(
content::WebContents* web_contents,
mojom::InterventionPolicy policy);
performance_manager::mojom::InterventionPolicy policy);
static void OnIsHoldingWebLockChanged(content::WebContents* web_contents,
bool is_holding_weblock);
static void OnIsHoldingIndexedDBLockChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ TEST_F(TabLifecycleUnitSourceTest, CannotFreezeOriginTrialOptOut) {

// Tab cannot be frozen if it opted-out via origin trial.
TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
background_contents, mojom::InterventionPolicy::kOptOut);
background_contents,
performance_manager::mojom::InterventionPolicy::kOptOut);
EXPECT_FALSE(background_lifecycle_unit->CanFreeze(&decision_details));
EXPECT_FALSE(decision_details.IsPositive());
EXPECT_EQ(DecisionFailureReason::ORIGIN_TRIAL_OPT_OUT,
Expand All @@ -656,7 +657,8 @@ TEST_F(TabLifecycleUnitSourceTest, CannotFreezeOriginTrialUnknown) {

// Tab cannot be frozen if its origin trial policy is still unknown.
TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
background_contents, mojom::InterventionPolicy::kUnknown);
background_contents,
performance_manager::mojom::InterventionPolicy::kUnknown);
EXPECT_FALSE(background_lifecycle_unit->CanFreeze(&decision_details));
EXPECT_FALSE(decision_details.IsPositive());
EXPECT_EQ(DecisionFailureReason::ORIGIN_TRIAL_UNKNOWN,
Expand Down Expand Up @@ -700,7 +702,8 @@ TEST_F(TabLifecycleUnitSourceTest, CanFreezeOriginTrialOptIn) {
// The background tab can be frozen if it opted-in via origin trial, even if
// it uses notifications in background.
TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
background_contents, mojom::InterventionPolicy::kOptIn);
background_contents,
performance_manager::mojom::InterventionPolicy::kOptIn);
EXPECT_TRUE(background_lifecycle_unit->CanFreeze(&decision_details));
EXPECT_TRUE(decision_details.IsPositive());
EXPECT_EQ(DecisionSuccessReason::ORIGIN_TRIAL_OPT_IN,
Expand All @@ -709,7 +712,8 @@ TEST_F(TabLifecycleUnitSourceTest, CanFreezeOriginTrialOptIn) {

// The foreground tab cannot be frozen, even if it opted-in via origin trial.
TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
foreground_contents, mojom::InterventionPolicy::kOptIn);
foreground_contents,
performance_manager::mojom::InterventionPolicy::kOptIn);
EXPECT_FALSE(foreground_lifecycle_unit->CanFreeze(&decision_details));
EXPECT_FALSE(decision_details.IsPositive());
EXPECT_EQ(DecisionFailureReason::LIVE_STATE_VISIBLE,
Expand Down Expand Up @@ -781,7 +785,8 @@ TEST_F(TabLifecycleUnitSourceTest, TabProactiveDiscardedByFrozenCallback) {

reinterpret_cast<TabLifecycleUnitSource::TabLifecycleUnit*>(
background_lifecycle_unit)
->UpdateLifecycleState(mojom::LifecycleState::kFrozen);
->UpdateLifecycleState(
performance_manager::mojom::LifecycleState::kFrozen);
EXPECT_EQ(LifecycleUnitState::DISCARDED,
background_lifecycle_unit->GetState());
EXPECT_CALL(tab_observer_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ class TabManagerTest : public InProcessBrowserTest {
void SimulateFreezeSignal(content::WebContents* contents) {
GetTabLifecycleUnitSource()
->GetTabLifecycleUnit(contents)
->UpdateLifecycleState(mojom::LifecycleState::kFrozen);
->UpdateLifecycleState(
performance_manager::mojom::LifecycleState::kFrozen);
}

TabManager* tab_manager() { return g_browser_process->GetTabManager(); }
Expand Down Expand Up @@ -1270,7 +1271,8 @@ IN_PROC_BROWSER_TEST_F(TabManagerTestWithTwoTabs,
// Pretend that the background tab reported its origin trial freeze policy, to
// prevent CanFreeze() from returning false.
TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
GetWebContentsAt(1), mojom::InterventionPolicy::kDefault);
GetWebContentsAt(1),
performance_manager::mojom::InterventionPolicy::kDefault);

// Proactively discard the background tab.
EXPECT_EQ(LifecycleUnitState::ACTIVE, GetLifecycleUnitAt(1)->GetState());
Expand Down
Loading

0 comments on commit e643af0

Please sign in to comment.