Remove ScopedObserver from base.

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.

Bug: 1145565
Change-Id: I3169858882de4efb16a63a847940a9e3bc249d96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2944549
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Sigurður Ásgeirsson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#890208}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index cc586f8..02341cbc 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -948,16 +948,6 @@
       ),
     ),
     (
-      r'/\bScopedObserver',
-      (
-          'ScopedObserver is deprecated.',
-          'Please use base::ScopedObservation for observing a single source,',
-          'or base::ScopedMultiSourceObservation for observing multple sources',
-      ),
-      True,
-      (),
-    ),
-    (
       'RoInitialize',
       (
         'Improper use of [base::win]::RoInitialize() has been implicated in a ',
diff --git a/base/BUILD.gn b/base/BUILD.gn
index fad1f1b0..7b11be6d 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -536,7 +536,6 @@
     "scoped_native_library.cc",
     "scoped_native_library.h",
     "scoped_observation.h",
-    "scoped_observer.h",
     "sequence_checker.h",
     "sequence_checker_impl.cc",
     "sequence_checker_impl.h",
diff --git a/base/scoped_multi_source_observation.h b/base/scoped_multi_source_observation.h
index 8e30417..44e656af 100644
--- a/base/scoped_multi_source_observation.h
+++ b/base/scoped_multi_source_observation.h
@@ -19,7 +19,6 @@
 // e.g. where an observer observes more than a single source.
 //
 // Use base::ScopedObservation for objects that observe only a single source.
-// This class and base::ScopedObservation replace ScopedObserver.
 //
 // When ScopedMultiSourceObservation is destroyed, it removes the object as an
 // observer from all sources it has been added to.
diff --git a/base/scoped_observation.h b/base/scoped_observation.h
index 909aafa..305c99c 100644
--- a/base/scoped_observation.h
+++ b/base/scoped_observation.h
@@ -15,8 +15,7 @@
 // where an observer observes a single source only.
 //
 // Use base::ScopedMultiSourceObservation for objects that observe multiple
-// sources. This class and base::ScopedMultiSourceObservation replace
-// ScopedObserver.
+// sources.
 //
 // When ScopedObservation is destroyed, it removes the registered observation,
 // if any. Basic example (as a member variable):
diff --git a/base/scoped_observer.h b/base/scoped_observer.h
deleted file mode 100644
index 2909a18..0000000
--- a/base/scoped_observer.h
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (c) 2012 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 BASE_SCOPED_OBSERVER_H_
-#define BASE_SCOPED_OBSERVER_H_
-
-#include <stddef.h>
-
-#include <vector>
-
-#include "base/check.h"
-#include "base/containers/contains.h"
-#include "base/ranges/algorithm.h"
-
-// This class is DEPRECATED. Instead please use one of:
-// - base::ScopedObservation for observing a single source.
-// - base::ScopedMultiSourceObservation for observing multiple sources.
-//
-// ScopedObserver is used to keep track of the set of sources an object has
-// attached itself to as an observer. When ScopedObserver is destroyed it
-// removes the object as an observer from all sources it has been added to.
-// Basic example (as a member variable):
-//
-//   class MyFooObserver : public FooObserver {
-//     ...
-//    private:
-//     ScopedObserver<Foo, FooObserver> observed_foo_{this};
-//   };
-//
-// For cases with methods not named AddObserver/RemoveObserver:
-//
-//   class MyFooStateObserver : public FooStateObserver {
-//     ...
-//    private:
-//     ScopedObserver<Foo,
-//                    FooStateObserver,
-//                    &Foo::AddStateObserver,
-//                    &Foo::RemoveStateObserver>
-//       observed_foo_{this};
-//   };
-template <class Source,
-          class Observer,
-          void (Source::*AddObsFn)(Observer*) = &Source::AddObserver,
-          void (Source::*RemoveObsFn)(Observer*) = &Source::RemoveObserver>
-class ScopedObserver {
- public:
-  explicit ScopedObserver(Observer* observer) : observer_(observer) {}
-  ScopedObserver(const ScopedObserver&) = delete;
-  ScopedObserver& operator=(const ScopedObserver&) = delete;
-  ~ScopedObserver() {
-    RemoveAll();
-  }
-
-  // Adds the object passed to the constructor as an observer on |source|.
-  void Add(Source* source) {
-    sources_.push_back(source);
-    (source->*AddObsFn)(observer_);
-  }
-
-  // Remove the object passed to the constructor as an observer from |source|.
-  void Remove(Source* source) {
-    auto it = base::ranges::find(sources_, source);
-    DCHECK(it != sources_.end());
-    sources_.erase(it);
-    (source->*RemoveObsFn)(observer_);
-  }
-
-  void RemoveAll() {
-    for (size_t i = 0; i < sources_.size(); ++i)
-      (sources_[i]->*RemoveObsFn)(observer_);
-    sources_.clear();
-  }
-
-  bool IsObserving(Source* source) const {
-    return base::Contains(sources_, source);
-  }
-
-  bool IsObservingSources() const { return !sources_.empty(); }
-
-  size_t GetSourcesCount() const { return sources_.size(); }
-
- private:
-  Observer* observer_;
-
-  std::vector<Source*> sources_;
-};
-
-#endif  // BASE_SCOPED_OBSERVER_H_