Sorry for the late feedback, but looking at the fix CL (
https://crrev.com/c/4002909) I'm not sure I like the solution, so I'd like to propose an alternative solution.
The currently proposed solution changes this
```
namespace my_namespace {
class MyParentClass {
private:
base::ScopedObservation<LinuxUi,
CursorThemeManagerObserver,
&LinuxUi::AddCursorThemeObserver,
&LinuxUi::RemoveCursorThemeObserver>
cursor_theme_observation_{this};
};
} // namespace my_namespace
```
into the much more unwieldy and harder to write
```
// Must be in namespace base!
namespace base {
template <>
struct ScopedObservationTraits<ui::LinuxUi, ui::CursorThemeManagerObserver> {
static void AddObserver(ui::LinuxUi* source,
ui::CursorThemeManagerObserver* observer) {
source->AddCursorThemeObserver(observer);
}
static void RemoveObserver(ui::LinuxUi* source,
ui::CursorThemeManagerObserver* observer) {
source->RemoveCursorThemeObserver(observer);
}
};
} // namespace base
namespace my_namespace {
class MyParentClass {
private:
base::ScopedObservation<LinuxUi, CursorThemeManagerObserver,>
cursor_theme_observation_{this};
};
} // namespace my_namespace
```
Which looks like a serious regression to me.
So what if we simply create 2 different templated classes:
* `ScopedObservation`, which can be used for any class that has `AddObserver()`/`RemoveObserver()` methods, and which allows the observer class to be forward declared, and
* `CustomScopedObservation`, which allows custom method names but doesn't allow the observer class to be forward declared (which makes this exactly the same as the old `ScopedObservation` class).
This changes the above example back to
```
namespace my_namespace {
class MyParentClass {
private:
base::CustomScopedObservation<LinuxUi,
CursorThemeManagerObserver,
&LinuxUi::AddCursorThemeObserver,
&LinuxUi::RemoveCursorThemeObserver>
cursor_theme_observation_{this};
};
} // namespace my_namespace
```
at the small(ish) cost of some one time duplication (the `CustomScopedObservation` class, which costs about 22 lines of code (44 if you add in all the comments and closing `}`).
WDYT?
With regards,
Jeroen