#ifndef CHROME_BROWSER_AUTOCOMPLETE_UNSCOPED_EXTENSION_PROVIDER_DELEGATE_IMPL_H_
#define CHROME_BROWSER_AUTOCOMPLETE_UNSCOPED_EXTENSION_PROVIDER_DELEGATE_IMPL_H_
#include <string>
#include <unordered_map>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_input_watcher.h"
#include "components/omnibox/browser/unscoped_extension_provider.h"
#include "components/omnibox/browser/unscoped_extension_provider_delegate.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/extension_id.h"
#if !BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#error "Should not be included when extensions are disabled"
#endif
class UnscopedExtensionProvider;
class Profile;
class UnscopedExtensionProviderDelegateImpl
: public UnscopedExtensionProviderDelegate,
public OmniboxInputWatcher::Observer,
public OmniboxSuggestionsWatcher::Observer {
public:
UnscopedExtensionProviderDelegateImpl(Profile* profile,
UnscopedExtensionProvider* provider);
UnscopedExtensionProviderDelegateImpl(
const UnscopedExtensionProviderDelegateImpl&) = delete;
UnscopedExtensionProviderDelegateImpl& operator=(
const UnscopedExtensionProviderDelegateImpl&) = delete;
~UnscopedExtensionProviderDelegateImpl() override;
void Start(const AutocompleteInput& input,
bool minimal_changes,
std::set<std::string> unscoped_mode_extension_ids) override;
void Stop(bool clear_cached_results) override;
void DeleteSuggestion(const TemplateURL* template_url,
const std::u16string& suggestion_text) override;
void OnOmniboxInputEntered() override;
void OnOmniboxSuggestionsReady(
const std::vector<ExtensionSuggestion>& suggestions,
const int request_id,
const std::string& extension_id) override;
private:
AutocompleteMatch CreateAutocompleteMatch(
const ExtensionSuggestion& suggestion,
int relevance,
const std::string& extension_id);
bool IsEnabledExtension(const std::string& extension_id);
void ClearSuggestions();
void OnActionExecuted(const std::string& extension_id,
const std::string& action_name,
const std::string& contents);
int current_request_id_ = 0;
int first_suggestion_relevance_ = 0;
std::vector<AutocompleteMatch> extension_suggest_matches_;
size_t next_available_group_index_ = 0;
size_t next_available_section_index_ = 0;
std::unordered_map<extensions::ExtensionId, omnibox::GroupId>
extension_id_to_group_id_map_;
raw_ptr<Profile> profile_;
raw_ptr<UnscopedExtensionProvider> provider_;
base::ScopedObservation<OmniboxInputWatcher, OmniboxInputWatcher::Observer>
omnibox_input_observation_{this};
base::ScopedObservation<OmniboxSuggestionsWatcher,
OmniboxSuggestionsWatcher::Observer>
omnibox_suggestions_observation_{this};
base::WeakPtrFactory<UnscopedExtensionProviderDelegateImpl> weak_factory_{
this};
};
#endif