#ifndef CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_EXTENSIONS_DELEGATE_IMPL_H_
#define CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_EXTENSIONS_DELEGATE_IMPL_H_
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/keyword_extensions_delegate.h"
#include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/omnibox_input_watcher.h"
#include "components/omnibox/browser/omnibox_suggestions_watcher.h"
#include "extensions/buildflags/buildflags.h"
#if !BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#error "Should not be included when extensions are disabled"
#endif
class Profile;
class KeywordExtensionsDelegateImpl
: public KeywordExtensionsDelegate,
public OmniboxInputWatcher::Observer,
public OmniboxSuggestionsWatcher::Observer {
public:
KeywordExtensionsDelegateImpl(Profile* profile, KeywordProvider* provider);
KeywordExtensionsDelegateImpl(const KeywordExtensionsDelegateImpl&) = delete;
KeywordExtensionsDelegateImpl& operator=(
const KeywordExtensionsDelegateImpl&) = delete;
~KeywordExtensionsDelegateImpl() override;
void DeleteSuggestion(const TemplateURL* template_url,
const std::u16string& suggestion_text) override;
private:
void IncrementInputId() override;
bool IsEnabledExtension(const std::string& extension_id) override;
bool Start(const AutocompleteInput& input,
bool minimal_changes,
const TemplateURL* template_url,
const std::u16string& remaining_input) override;
void EnterExtensionKeywordMode(const std::string& extension_id) override;
void MaybeEndExtensionKeywordMode() override;
void OnOmniboxInputEntered() override;
void OnOmniboxSuggestionsReady(
const std::vector<ExtensionSuggestion>& suggestions,
const int request_id,
const std::string& extension_id) override;
void OnOmniboxDefaultSuggestionChanged() override;
ACMatches* matches() { return &provider_->matches_; }
void set_done(bool done) { provider_->done_ = done; }
void OnProviderUpdate(bool updated_matches);
int current_input_id_;
AutocompleteInput extension_suggest_last_input_;
std::vector<AutocompleteMatch> extension_suggest_matches_;
std::string current_keyword_extension_id_;
raw_ptr<Profile> profile_;
raw_ptr<KeywordProvider> provider_;
static int global_input_uid_;
base::ScopedObservation<OmniboxInputWatcher, OmniboxInputWatcher::Observer>
omnibox_input_observation_{this};
base::ScopedObservation<OmniboxSuggestionsWatcher,
OmniboxSuggestionsWatcher::Observer>
omnibox_suggestions_observation_{this};
};
#endif