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