// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_SCOPED_AUTOFILL_MANAGERS_OBSERVATION_H_ #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_SCOPED_AUTOFILL_MANAGERS_OBSERVATION_H_ #include "base/scoped_multi_source_observation.h" #include "base/scoped_observation.h" #include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/autofill/core/browser/autofill_manager.h" namespace content { class WebContents; } namespace autofill { class ContentAutofillDriver; // `ScopedAutofillManagersObservation` is a helper to reduce boilerplate when // observing all `AutofillManagers` of a `WebContents`. Instead of having to // implement both `ContentAutofillDriverFactory`'s and `AutofillManager`'s // observer interfaces, the consumer now only needs to implement // `AutofillManager::Observer` and add a member variable of this type. // // Example: // class AutofillInformationConsumer : public AutofillManager::Observer { // public: // AutofillInformationConsumer(content::WebContents* contents) { // autofill_managers_observation.Observe(contents); // } // // // AutofillManager::Observer: // void OnAfterLanguageDetermined(AutofillManager& manager) { // // Do something. // } // // private: // ScopedAutofillManagersObservation autofill_managers_observation_{this}; // }; class ScopedAutofillManagersObservation final : public ContentAutofillDriverFactory::Observer { … }; } // namespace autofill #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_SCOPED_AUTOFILL_MANAGERS_OBSERVATION_H_