forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start on PerformanceMeasurementManager.
This will glue together the measurement cycle from event notifications from the TabLoadTracker to the measurements in RenderProcessProbe. Eventually this class will also persist complete measurements issued from an observer in the RC service by sinking notifications and persisting to the feature database. Bug: 755840 Change-Id: I8c6673fcf205709ad96435295f9010a6aceb3017 Reviewed-on: https://chromium-review.googlesource.com/1072232 Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org> Reviewed-by: François Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/master@{#562258}
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
chrome/browser/resource_coordinator/performance_measurement_manager.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/resource_coordinator/performance_measurement_manager.h" | ||
|
||
#include "chrome/browser/resource_coordinator/render_process_probe.h" | ||
#include "chrome/browser/resource_coordinator/tab_load_tracker.h" | ||
|
||
namespace resource_coordinator { | ||
|
||
PerformanceMeasurementManager::PerformanceMeasurementManager( | ||
TabLoadTracker* tab_load_tracker, | ||
RenderProcessProbe* render_process_probe) | ||
: scoped_observer_(this), render_process_probe_(render_process_probe) { | ||
scoped_observer_.Add(tab_load_tracker); | ||
} | ||
|
||
PerformanceMeasurementManager::~PerformanceMeasurementManager() = default; | ||
|
||
void PerformanceMeasurementManager::OnStartTracking( | ||
content::WebContents* web_contents, | ||
LoadingState loading_state) { | ||
if (loading_state == TabLoadTracker::LOADED) | ||
render_process_probe_->StartSingleGather(); | ||
} | ||
|
||
void PerformanceMeasurementManager::OnLoadingStateChange( | ||
content::WebContents* web_contents, | ||
LoadingState loading_state) { | ||
if (loading_state == TabLoadTracker::LOADED) | ||
render_process_probe_->StartSingleGather(); | ||
} | ||
|
||
} // namespace resource_coordinator |
45 changes: 45 additions & 0 deletions
45
chrome/browser/resource_coordinator/performance_measurement_manager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_ | ||
#define CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/scoped_observer.h" | ||
#include "base/sequence_checker.h" | ||
#include "chrome/browser/resource_coordinator/tab_load_tracker.h" | ||
|
||
namespace resource_coordinator { | ||
|
||
class RenderProcessProbe; | ||
class TabLoadTracker; | ||
|
||
// This class observes tab state change notifications issued by the | ||
// TabLoadTracker and uses them to drive performance measurement requests | ||
// to the RenderProcessProbe. Results then funnel through the resource | ||
// coordinator service, back to this class, which stores them in the feature | ||
// database. | ||
class PerformanceMeasurementManager : public TabLoadTracker::Observer { | ||
public: | ||
PerformanceMeasurementManager(TabLoadTracker* tab_load_tracker, | ||
RenderProcessProbe* render_process_probe); | ||
~PerformanceMeasurementManager() override; | ||
|
||
// TabLoadTracker::Observer implementation. | ||
void OnStartTracking(content::WebContents* web_contents, | ||
LoadingState loading_state) override; | ||
void OnLoadingStateChange(content::WebContents* web_contents, | ||
LoadingState loading_state) override; | ||
|
||
private: | ||
ScopedObserver<TabLoadTracker, PerformanceMeasurementManager> | ||
scoped_observer_; | ||
RenderProcessProbe* render_process_probe_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PerformanceMeasurementManager); | ||
}; | ||
|
||
} // namespace resource_coordinator | ||
|
||
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_ |
58 changes: 58 additions & 0 deletions
58
chrome/browser/resource_coordinator/performance_measurement_manager_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/resource_coordinator/performance_measurement_manager.h" | ||
#include "chrome/browser/resource_coordinator/render_process_probe.h" | ||
#include "chrome/browser/resource_coordinator/tab_helper.h" | ||
#include "chrome/browser/resource_coordinator/tab_load_tracker.h" | ||
#include "chrome/test/base/chrome_render_view_host_test_harness.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace resource_coordinator { | ||
|
||
class LenientMockRenderProcessProbe : public RenderProcessProbe { | ||
public: | ||
MOCK_METHOD0(StartGatherCycle, void()); | ||
MOCK_METHOD0(StartSingleGather, void()); | ||
}; | ||
using MockRenderProcessProbe = | ||
testing::StrictMock<LenientMockRenderProcessProbe>; | ||
|
||
class PerformanceMeasurementManagerTest | ||
: public ChromeRenderViewHostTestHarness { | ||
public: | ||
std::unique_ptr<content::WebContents> CreateWebContents() { | ||
std::unique_ptr<content::WebContents> contents = CreateTestWebContents(); | ||
ResourceCoordinatorTabHelper::CreateForWebContents(contents.get()); | ||
return contents; | ||
} | ||
|
||
MockRenderProcessProbe& mock_render_process_probe() { | ||
return mock_render_process_probe_; | ||
} | ||
|
||
private: | ||
MockRenderProcessProbe mock_render_process_probe_; | ||
}; | ||
|
||
TEST_F(PerformanceMeasurementManagerTest, NoMeasurementOnCreation) { | ||
PerformanceMeasurementManager performance_measurement_manager( | ||
TabLoadTracker::Get(), &mock_render_process_probe()); | ||
|
||
auto contents = CreateWebContents(); | ||
} | ||
|
||
TEST_F(PerformanceMeasurementManagerTest, StartMeasurementOnLoaded) { | ||
PerformanceMeasurementManager performance_measurement_manager( | ||
TabLoadTracker::Get(), &mock_render_process_probe()); | ||
|
||
auto contents = CreateWebContents(); | ||
|
||
EXPECT_CALL(mock_render_process_probe(), StartSingleGather()); | ||
TabLoadTracker::Get()->TransitionStateForTesting(contents.get(), | ||
TabLoadTracker::LOADED); | ||
} | ||
|
||
} // namespace resource_coordinator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters