Commit 22400017 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Retire ScopedObserver in /components/metrics.

ScopedObserver is being deprecated in favor of two new classes:
- base::ScopedObservation for observers that only ever observe
  a single source.
- base::ScopedMultiSourceObservation for observers that do or may
  observe more than a single source.

This CL was uploaded by git cl split.

R=bcwhite@chromium.org

Bug: 1145565
Change-Id: I68423d748501ffba5239606311b518844e1c51a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532955
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Commit-Queue: Brian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826489}
parent 8f0eeca9
......@@ -28,12 +28,7 @@ namespace metrics {
ContentStabilityMetricsProvider::ContentStabilityMetricsProvider(
PrefService* local_state,
std::unique_ptr<ExtensionsHelper> extensions_helper)
:
#if defined(OS_ANDROID)
scoped_observer_(this),
#endif // defined(OS_ANDROID)
helper_(local_state),
extensions_helper_(std::move(extensions_helper)) {
: helper_(local_state), extensions_helper_(std::move(extensions_helper)) {
BrowserChildProcessObserver::Add(this);
registrar_.Add(this, content::NOTIFICATION_LOAD_START,
......@@ -48,7 +43,7 @@ ContentStabilityMetricsProvider::ContentStabilityMetricsProvider(
#if defined(OS_ANDROID)
auto* crash_manager = crash_reporter::CrashMetricsReporter::GetInstance();
DCHECK(crash_manager);
scoped_observer_.Add(crash_manager);
scoped_observation_.Observe(crash_manager);
#endif // defined(OS_ANDROID)
}
......
......@@ -8,7 +8,7 @@
#include <memory>
#include "base/gtest_prod_util.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/stability_metrics_helper.h"
......@@ -84,9 +84,9 @@ class ContentStabilityMetricsProvider
const crash_reporter::CrashMetricsReporter::ReportedCrashTypeSet&
reported_counts) override;
ScopedObserver<crash_reporter::CrashMetricsReporter,
crash_reporter::CrashMetricsReporter::Observer>
scoped_observer_;
base::ScopedObservation<crash_reporter::CrashMetricsReporter,
crash_reporter::CrashMetricsReporter::Observer>
scoped_observation_{this};
#endif // defined(OS_ANDROID)
StabilityMetricsHelper helper_;
......
......@@ -162,8 +162,8 @@ void SubprocessMetricsProvider::OnRenderProcessHostCreated(
content::RenderProcessHost* host) {
// Sometimes, the same host will cause multiple notifications in tests so
// could possibly do the same in a release build.
if (!scoped_observer_.IsObserving(host))
scoped_observer_.Add(host);
if (!scoped_observations_.IsObservingSource(host))
scoped_observations_.AddObservation(host);
}
void SubprocessMetricsProvider::RenderProcessReady(
......@@ -198,7 +198,7 @@ void SubprocessMetricsProvider::RenderProcessHostDestroyed(
// destruction of the host. If both get called, no harm is done.
DeregisterSubprocessAllocator(host->GetID());
scoped_observer_.Remove(host);
scoped_observations_.RemoveObservation(host);
}
// static
......
......@@ -12,7 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/statistics_recorder.h"
#include "base/scoped_observer.h"
#include "base/scoped_multi_source_observation.h"
#include "base/threading/thread_checker.h"
#include "components/metrics/metrics_provider.h"
#include "content/public/browser/browser_child_process_observer.h"
......@@ -109,8 +109,9 @@ class SubprocessMetricsProvider
AllocatorByIdMap allocators_by_id_;
// Track all observed render processes to un-observe them on exit.
ScopedObserver<content::RenderProcessHost, content::RenderProcessHostObserver>
scoped_observer_{this};
base::ScopedMultiSourceObservation<content::RenderProcessHost,
content::RenderProcessHostObserver>
scoped_observations_{this};
base::WeakPtrFactory<SubprocessMetricsProvider> weak_ptr_factory_{this};
......
......@@ -66,10 +66,10 @@ class SubprocessMetricsProviderBrowserTest
return provider_->allocators_by_id_;
}
ScopedObserver<content::RenderProcessHost,
content::RenderProcessHostObserver>&
get_scoped_observer() {
return provider_->scoped_observer_;
base::ScopedMultiSourceObservation<content::RenderProcessHost,
content::RenderProcessHostObserver>&
get_scoped_observations() {
return provider_->scoped_observations_;
}
base::PersistentHistogramAllocator* GetMainFrameAllocator() {
......@@ -114,7 +114,7 @@ IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
RegisterExistingNotReadyRenderProcesses) {
ASSERT_TRUE(GetRenderProcessHostCount() > 0);
CreateSubprocessMetricsProvider();
EXPECT_EQ(get_scoped_observer().GetSourcesCount(),
EXPECT_EQ(get_scoped_observations().GetSourcesCount(),
GetRenderProcessHostCount());
EXPECT_EQ(get_allocators_by_id().size(), 0u);
......@@ -123,7 +123,7 @@ IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
// Verify that the number of scoped observer matches the number of
// RenderProcessHost and the main frame allocator exists.
EXPECT_EQ(get_scoped_observer().GetSourcesCount(),
EXPECT_EQ(get_scoped_observations().GetSourcesCount(),
GetRenderProcessHostCount());
auto* main_frame_allocator = GetMainFrameAllocator();
EXPECT_TRUE(main_frame_allocator);
......@@ -156,7 +156,8 @@ IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
shell()->web_contents()->GetMainFrame()->GetProcess();
SimulateRenderProcessHostDestroyed();
// Verify the observer removed.
EXPECT_FALSE(get_scoped_observer().IsObserving(main_frame_process_host));
EXPECT_FALSE(
get_scoped_observations().IsObservingSource(main_frame_process_host));
}
IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
......@@ -169,7 +170,7 @@ IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
// Verify that the number of scoped observer matches the number of
// RenderProcessHost and the main frame allocator exists.
EXPECT_EQ(get_scoped_observer().GetSourcesCount(),
EXPECT_EQ(get_scoped_observations().GetSourcesCount(),
GetRenderProcessHostCount());
auto* main_frame_allocator = GetMainFrameAllocator();
EXPECT_TRUE(main_frame_allocator);
......@@ -202,7 +203,8 @@ IN_PROC_BROWSER_TEST_F(SubprocessMetricsProviderBrowserTest,
shell()->web_contents()->GetMainFrame()->GetProcess();
SimulateRenderProcessHostDestroyed();
// Verify the observer removed.
EXPECT_FALSE(get_scoped_observer().IsObserving(main_frame_process_host));
EXPECT_FALSE(
get_scoped_observations().IsObservingSource(main_frame_process_host));
}
} // namespace metrics
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