Commit c9d02005 authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

[omnibox] Combine AutocompleteController observer classes

This CL combines AutocompleteControllerDelegate and
OmniboxControllerEmitter::Observer classes into a single
AutocompleteController::Observer class.

This is because these two classes are essentially the same, both
observing the AutocompleteController.

In the future, we can also make OmniboxControllerEmitter itself an
instance of AutocompleteController::Observer, because it too, is
essentially an observer class that's a KeyedService.

The ultimate goal is to hook up the Android omnibox and NTP realbox
to the chrome://omnibox debug surfaces.

This refactor is to pave the way for that. See the bug for the full
engineering plan on how to get there.

Bug: 1058486
Change-Id: Ieb65cc2570a5af1ba417be6a87f4779bbe4710ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088223Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751822}
parent 2432631b
......@@ -36,7 +36,6 @@
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
......@@ -105,17 +104,13 @@ void RecordClipboardMetrics(AutocompleteMatchType::Type match_type) {
* The prefetch occurs as a side-effect of calling OnOmniboxFocused() on
* the AutocompleteController object.
*/
class ZeroSuggestPrefetcher : public AutocompleteControllerDelegate {
class ZeroSuggestPrefetcher {
public:
explicit ZeroSuggestPrefetcher(Profile* profile);
private:
~ZeroSuggestPrefetcher() override = default;
void SelfDestruct();
// AutocompleteControllerDelegate:
void OnResultChanged(bool default_match_changed) override;
std::unique_ptr<AutocompleteController> controller_;
base::OneShotTimer expire_timer_;
};
......@@ -123,7 +118,7 @@ class ZeroSuggestPrefetcher : public AutocompleteControllerDelegate {
ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile)
: controller_(new AutocompleteController(
std::make_unique<ChromeAutocompleteProviderClient>(profile),
this,
nullptr, // We only want to warm up the cache, don't need the result.
AutocompleteProvider::TYPE_ZERO_SUGGEST)) {
AutocompleteInput input(base::string16(), metrics::OmniboxEventProto::NTP,
ChromeAutocompleteSchemeClassifier(profile));
......@@ -140,12 +135,6 @@ void ZeroSuggestPrefetcher::SelfDestruct() {
delete this;
}
void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) {
// Nothing to do here, the results have been cached.
// We don't want to trigger deletion here because this is being called by the
// AutocompleteController object.
}
} // namespace
AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile)
......@@ -400,7 +389,9 @@ void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) {
}
void AutocompleteControllerAndroid::OnResultChanged(
AutocompleteController* controller,
bool default_match_changed) {
DCHECK(controller == autocomplete_controller_.get());
if (autocomplete_controller_ && !inside_synchronous_start_)
NotifySuggestionsReceived(autocomplete_controller_->result());
}
......
......@@ -13,7 +13,7 @@
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -26,7 +26,7 @@ class AutocompleteResult;
class Profile;
// The native part of the Java AutocompleteController class.
class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
class AutocompleteControllerAndroid : public AutocompleteController::Observer,
public KeyedService {
public:
explicit AutocompleteControllerAndroid(Profile* profile);
......@@ -112,8 +112,9 @@ class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
~AutocompleteControllerAndroid() override;
void InitJNI(JNIEnv* env, jobject obj);
// AutocompleteControllerDelegate implementation.
void OnResultChanged(bool default_match_changed) override;
// AutocompleteController::Observer implementation.
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
// Notifies the Java AutocompleteController that suggestions were received
// based on the text the user typed in last.
......
......@@ -11,7 +11,6 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/search_engines/util.h"
......@@ -71,7 +70,11 @@ std::tuple<GURL, bool> AutocompleteController::GetUrlFromVoiceInput(
false};
}
void AutocompleteController::OnResultChanged(bool default_match_changed) {
void AutocompleteController::OnResultChanged(
::AutocompleteController* controller,
bool default_match_changed) {
DCHECK(controller == autocomplete_controller_.get());
std::vector<OmniboxSuggestion> suggestions;
for (const auto& match : autocomplete_controller_->result()) {
const gfx::VectorIcon* icon = &match.GetVectorIcon(false);
......
......@@ -12,7 +12,7 @@
#include "base/macros.h"
#include "base/values.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "url/gurl.h"
class AutocompleteController;
......@@ -21,7 +21,7 @@ class Profile;
namespace vr {
class AutocompleteController : public AutocompleteControllerDelegate {
class AutocompleteController : public ::AutocompleteController::Observer {
public:
using SuggestionCallback =
base::RepeatingCallback<void(std::vector<OmniboxSuggestion>)>;
......@@ -41,7 +41,9 @@ class AutocompleteController : public AutocompleteControllerDelegate {
std::tuple<GURL, bool> GetUrlFromVoiceInput(const base::string16& input);
private:
void OnResultChanged(bool default_match_changed) override;
// ::AutocompleteController::Observer:
void OnResultChanged(::AutocompleteController* controller,
bool default_match_changed) override;
Profile* profile_;
ChromeAutocompleteProviderClient* client_;
......
......@@ -14,7 +14,6 @@
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/search/omnibox_result.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "url/gurl.h"
......@@ -76,7 +75,10 @@ void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) {
SwapResults(&new_results);
}
void OmniboxProvider::OnResultChanged(bool default_match_changed) {
void OmniboxProvider::OnResultChanged(AutocompleteController* controller,
bool default_match_changed) {
DCHECK(controller == controller_.get());
// Record the query latency.
RecordQueryLatencyHistogram();
......
......@@ -9,7 +9,7 @@
#include "base/macros.h"
#include "chrome/browser/ui/app_list/search/search_provider.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_controller.h"
class AppListControllerDelegate;
class AutocompleteController;
......@@ -20,7 +20,7 @@ namespace app_list {
// OmniboxProvider wraps AutocompleteController to provide omnibox results.
class OmniboxProvider : public SearchProvider,
public AutocompleteControllerDelegate {
public AutocompleteController::Observer {
public:
explicit OmniboxProvider(Profile* profile,
AppListControllerDelegate* list_controller);
......@@ -33,8 +33,9 @@ class OmniboxProvider : public SearchProvider,
// Populates result list from AutocompleteResult.
void PopulateFromACResult(const AutocompleteResult& result);
// AutocompleteControllerDelegate overrides:
void OnResultChanged(bool default_match_changed) override;
// AutocompleteController::Observer overrides:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
void RecordQueryLatencyHistogram();
......
......@@ -449,7 +449,10 @@ void SearchTabHelper::FileSelectionCanceled(void* params) {
->LogEvent(NTP_BACKGROUND_UPLOAD_CANCEL, base::TimeDelta::FromSeconds(0));
}
void SearchTabHelper::OnResultChanged(bool default_result_changed) {
void SearchTabHelper::OnResultChanged(AutocompleteController* controller,
bool default_result_changed) {
DCHECK(controller == autocomplete_controller_.get());
if (!autocomplete_controller_) {
NOTREACHED();
return;
......
......@@ -23,7 +23,7 @@
#include "chrome/common/search/instant_types.h"
#include "chrome/common/search/ntp_logging_events.h"
#include "components/ntp_tiles/ntp_tile_impression.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/common/omnibox_focus_state.h"
#include "content/public/browser/reload_type.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -54,7 +54,7 @@ class SearchTabHelper : public content::WebContentsObserver,
public InstantServiceObserver,
public SearchIPCRouter::Delegate,
public ui::SelectFileDialog::Listener,
public AutocompleteControllerDelegate,
public AutocompleteController::Observer,
public OmniboxTabHelper::Observer {
public:
~SearchTabHelper() override;
......@@ -164,8 +164,9 @@ class SearchTabHelper : public content::WebContentsObserver,
void* params) override;
void FileSelectionCanceled(void* params) override;
// Overridden from AutocompleteControllerDelegate:
void OnResultChanged(bool default_match_changed) override;
// Overridden from AutocompleteController::Observer:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
// Overridden from OmniboxTabHelper::Observer:
void OnOmniboxInputStateChanged() override;
......
......@@ -29,7 +29,6 @@
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/url_database.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/omnibox_controller_emitter.h"
......@@ -205,23 +204,18 @@ OmniboxPageHandler::OmniboxPageHandler(
ResetController();
}
OmniboxPageHandler::~OmniboxPageHandler() {}
OmniboxPageHandler::~OmniboxPageHandler() = default;
void OmniboxPageHandler::OnResultChanged(bool default_match_changed) {
OnOmniboxResultChanged(default_match_changed, controller_.get());
}
void OmniboxPageHandler::OnOmniboxQuery(AutocompleteController* controller,
const AutocompleteInput& input) {
void OmniboxPageHandler::OnStart(AutocompleteController* controller,
const AutocompleteInput& input) {
time_omnibox_started_ = base::Time::Now();
input_ = input;
page_->HandleNewAutocompleteQuery(controller == controller_.get(),
base::UTF16ToUTF8(input.text()));
}
void OmniboxPageHandler::OnOmniboxResultChanged(
bool default_match_changed,
AutocompleteController* controller) {
void OmniboxPageHandler::OnResultChanged(AutocompleteController* controller,
bool default_match_changed) {
mojom::OmniboxResponsePtr response(mojom::OmniboxResponse::New());
response->cursor_position = input_.cursor_position();
response->time_since_omnibox_started_ms =
......@@ -355,8 +349,7 @@ void OmniboxPageHandler::StartOmniboxQuery(const std::string& input_string,
input.set_keyword_mode_entry_method(metrics::OmniboxEventProto::TAB);
input.set_from_omnibox_focus(zero_suggest);
OnOmniboxQuery(controller_.get(), input);
controller_->Start(input_);
controller_->Start(input);
}
void OmniboxPageHandler::ResetController() {
......
......@@ -14,7 +14,7 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_controller_emitter.h"
......@@ -30,23 +30,19 @@ class Profile;
// private AutocompleteController. It also listens for updates from the
// AutocompleteController to OnResultChanged() and passes those results to
// the OmniboxPage.
class OmniboxPageHandler : public AutocompleteControllerDelegate,
public mojom::OmniboxPageHandler,
public OmniboxControllerEmitter::Observer {
class OmniboxPageHandler : public AutocompleteController::Observer,
public mojom::OmniboxPageHandler {
public:
// OmniboxPageHandler is deleted when the supplied pipe is destroyed.
OmniboxPageHandler(Profile* profile,
mojo::PendingReceiver<mojom::OmniboxPageHandler> receiver);
~OmniboxPageHandler() override;
// AutocompleteControllerDelegate overrides:
void OnResultChanged(bool default_match_changed) override;
// OmniboxControllerEmitter::Observer overrides:
void OnOmniboxQuery(AutocompleteController* controller,
const AutocompleteInput& input) override;
void OnOmniboxResultChanged(bool default_match_changed,
AutocompleteController* controller) override;
// AutocompleteController::Observer overrides:
void OnStart(AutocompleteController* controller,
const AutocompleteInput& input) override;
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
// mojom::OmniboxPageHandler overrides:
void SetClientPage(mojo::PendingRemote<mojom::OmniboxPage> page) override;
......@@ -93,7 +89,7 @@ class OmniboxPageHandler : public AutocompleteControllerDelegate,
mojo::Receiver<mojom::OmniboxPageHandler> receiver_;
ScopedObserver<OmniboxControllerEmitter, OmniboxControllerEmitter::Observer>
ScopedObserver<OmniboxControllerEmitter, AutocompleteController::Observer>
observer_;
base::WeakPtrFactory<OmniboxPageHandler> weak_factory_{this};
......
......@@ -206,7 +206,7 @@ class BrowserChangeObserver : public BrowserListObserver {
DISALLOW_COPY_AND_ASSIGN(BrowserChangeObserver);
};
class AutocompleteChangeObserver : public OmniboxControllerEmitter::Observer {
class AutocompleteChangeObserver : public AutocompleteController::Observer {
public:
explicit AutocompleteChangeObserver(Profile* profile) {
scoped_observer_.Add(
......@@ -217,18 +217,16 @@ class AutocompleteChangeObserver : public OmniboxControllerEmitter::Observer {
void Wait() { run_loop_.Run(); }
// OmniboxControllerEmitter::Observer:
void OnOmniboxQuery(AutocompleteController* controller,
const AutocompleteInput& input) override {}
void OnOmniboxResultChanged(bool default_match_changed,
AutocompleteController* controller) override {
// AutocompleteController::Observer:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override {
if (run_loop_.running())
run_loop_.Quit();
}
private:
base::RunLoop run_loop_;
ScopedObserver<OmniboxControllerEmitter, OmniboxControllerEmitter::Observer>
ScopedObserver<OmniboxControllerEmitter, AutocompleteController::Observer>
scoped_observer_{this};
DISALLOW_COPY_AND_ASSIGN(AutocompleteChangeObserver);
......
......@@ -82,7 +82,6 @@ jumbo_static_library("browser") {
"autocomplete_classifier.h",
"autocomplete_controller.cc",
"autocomplete_controller.h",
"autocomplete_controller_delegate.h",
"autocomplete_input.cc",
"autocomplete_input.h",
"autocomplete_match.cc",
......
......@@ -30,7 +30,6 @@
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/bookmark_provider.h"
#include "components/omnibox/browser/builtin_provider.h"
#include "components/omnibox/browser/clipboard_provider.h"
......@@ -208,10 +207,9 @@ bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) {
AutocompleteController::AutocompleteController(
std::unique_ptr<AutocompleteProviderClient> provider_client,
AutocompleteControllerDelegate* delegate,
Observer* observer,
int provider_types)
: delegate_(delegate),
provider_client_(std::move(provider_client)),
: provider_client_(std::move(provider_client)),
document_provider_(nullptr),
history_url_provider_(nullptr),
keyword_provider_(nullptr),
......@@ -224,6 +222,11 @@ AutocompleteController::AutocompleteController(
first_query_(true),
search_service_worker_signal_sent_(false),
template_url_service_(provider_client_->GetTemplateURLService()) {
// TODO(tommycli): We should make a separate AddObserver method on this class
// and take |observer| out of the constructor. Tests pass nullptr anyways.
if (observer)
observers_.AddObserver(observer);
provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes();
if (provider_types & AutocompleteProvider::TYPE_BOOKMARK)
providers_.push_back(new BookmarkProvider(provider_client_.get()));
......@@ -327,6 +330,14 @@ AutocompleteController::~AutocompleteController() {
void AutocompleteController::Start(const AutocompleteInput& input) {
TRACE_EVENT1("omnibox", "AutocompleteController::Start",
"text", base::UTF16ToUTF8(input.text()));
// When input.want_asynchronous_matches() is false, the AutocompleteController
// is being used for text classification, which should not notify observers.
if (input.want_asynchronous_matches()) {
for (Observer& obs : observers_)
obs.OnStart(this, input);
}
const base::string16 old_input_text(input_.text());
const bool old_allow_exact_keyword_match = input_.allow_exact_keyword_match();
const bool old_want_asynchronous_matches = input_.want_asynchronous_matches();
......@@ -855,8 +866,8 @@ void AutocompleteController::UpdateAssistedQueryStats(
}
void AutocompleteController::NotifyChanged(bool notify_default_match) {
if (delegate_)
delegate_->OnResultChanged(notify_default_match);
for (Observer& obs : observers_)
obs.OnResultChanged(this, notify_default_match);
if (done_)
provider_client_->OnAutocompleteControllerResultReady(this);
}
......
......@@ -12,6 +12,8 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
......@@ -23,7 +25,6 @@
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/autocomplete_result.h"
class AutocompleteControllerDelegate;
class DocumentProvider;
class HistoryURLProvider;
class KeywordProvider;
......@@ -57,15 +58,32 @@ class AutocompleteController : public AutocompleteProviderListener,
public:
typedef std::vector<scoped_refptr<AutocompleteProvider> > Providers;
class Observer : public base::CheckedObserver {
public:
// Invoked when the |controller| Start() is called with an |input| that
// wants asynchronous matches. This is meant to exclude text classification
// requests. The |controller| parameter is only useful for observers that
// are observing multiple AutocompleteController instances.
virtual void OnStart(AutocompleteController* controller,
const AutocompleteInput& input) {}
// Invoked when the result set of |controller| changes. If
// |default_match_changed| is true, the default match of the result set has
// changed. The |controller| parameter is only useful for observers that
// are observing multiple AutocompleteController instances.
virtual void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) {}
};
// |provider_types| is a bitmap containing AutocompleteProvider::Type values
// that will (potentially, depending on platform, flags, etc.) be
// instantiated. |provider_client| is passed to all those providers, and
// is used to get access to the template URL service. |delegate| is a
// is used to get access to the template URL service. |observer| is a
// proxy for UI elements which need to be notified when the results get
// updated.
AutocompleteController(
std::unique_ptr<AutocompleteProviderClient> provider_client,
AutocompleteControllerDelegate* delegate,
Observer* observer,
int provider_types);
~AutocompleteController() override;
......@@ -76,9 +94,9 @@ class AutocompleteController : public AutocompleteProviderListener,
// See AutocompleteInput::AutocompleteInput(...) for more details regarding
// |input| params.
//
// The controller calls AutocompleteControllerDelegate::OnResultChanged() from
// inside this call at least once. If matches are available later on that
// result in changing the result set the delegate is notified again. When the
// The controller calls AutocompleteController::Observer::OnResultChanged()
// from inside this call at least once. If matches are available later on that
// result in changing the result set the observers is notified again. When the
// controller is done the notification AUTOCOMPLETE_CONTROLLER_RESULT_READY is
// sent.
void Start(const AutocompleteInput& input);
......@@ -214,7 +232,7 @@ class AutocompleteController : public AutocompleteProviderListener,
// stats.
void UpdateAssistedQueryStats(AutocompleteResult* result);
// Calls AutocompleteControllerDelegate::OnResultChanged() and if done sends
// Calls AutocompleteController::Observer::OnResultChanged() and if done sends
// AUTOCOMPLETE_CONTROLLER_RESULT_READY.
void NotifyChanged(bool notify_default_match);
......@@ -242,7 +260,7 @@ class AutocompleteController : public AutocompleteProviderListener,
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) override;
AutocompleteControllerDelegate* delegate_;
base::ObserverList<Observer> observers_;
// The client passed to the providers.
std::unique_ptr<AutocompleteProviderClient> provider_client_;
......
// Copyright (c) 2010 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 COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_DELEGATE_H_
#define COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_DELEGATE_H_
class AutocompleteControllerDelegate {
public:
// Invoked when the result set of the AutocompleteController changes. If
// |default_match_changed| is true, the default match of the result set has
// changed.
virtual void OnResultChanged(bool default_match_changed) = 0;
protected:
virtual ~AutocompleteControllerDelegate() {}
};
#endif // COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_DELEGATE_H_
......@@ -43,7 +43,10 @@ void OmniboxController::StartAutocomplete(
autocomplete_controller_->Start(input);
}
void OmniboxController::OnResultChanged(bool default_match_changed) {
void OmniboxController::OnResultChanged(AutocompleteController* controller,
bool default_match_changed) {
DCHECK(controller == autocomplete_controller_.get());
if (client_->GetOmniboxControllerEmitter())
client_->GetOmniboxControllerEmitter()->NotifyOmniboxResultChanged(
default_match_changed, autocomplete_controller_.get());
......
......@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_match.h"
struct AutocompleteMatch;
......@@ -29,7 +28,7 @@ class OmniboxPopupModel;
// this the point of contact between InstantController and OmniboxEditModel.
// As the refactor progresses, keep the class comment up to date to
// precisely explain what this class is doing.
class OmniboxController : public AutocompleteControllerDelegate {
class OmniboxController : public AutocompleteController::Observer {
public:
OmniboxController(OmniboxEditModel* omnibox_edit_model,
OmniboxClient* client);
......@@ -38,8 +37,9 @@ class OmniboxController : public AutocompleteControllerDelegate {
// The |current_url| field of input is only set for mobile ports.
void StartAutocomplete(const AutocompleteInput& input) const;
// AutocompleteControllerDelegate:
void OnResultChanged(bool default_match_changed) override;
// AutocompleteController::Observer:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
AutocompleteController* autocomplete_controller() {
return autocomplete_controller_.get();
......
......@@ -59,24 +59,26 @@ OmniboxControllerEmitter* OmniboxControllerEmitter::GetForBrowserContext(
}
#endif // !defined(OS_IOS)
void OmniboxControllerEmitter::AddObserver(Observer* observer) {
void OmniboxControllerEmitter::AddObserver(
AutocompleteController::Observer* observer) {
observers_.AddObserver(observer);
}
void OmniboxControllerEmitter::RemoveObserver(Observer* observer) {
void OmniboxControllerEmitter::RemoveObserver(
AutocompleteController::Observer* observer) {
observers_.RemoveObserver(observer);
}
void OmniboxControllerEmitter::NotifyOmniboxQuery(
AutocompleteController* controller,
const AutocompleteInput& input) {
for (Observer& observer : observers_)
observer.OnOmniboxQuery(controller, input);
for (auto& observer : observers_)
observer.OnStart(controller, input);
}
void OmniboxControllerEmitter::NotifyOmniboxResultChanged(
bool default_match_changed,
AutocompleteController* controller) {
for (Observer& observer : observers_)
observer.OnOmniboxResultChanged(default_match_changed, controller);
for (auto& observer : observers_)
observer.OnResultChanged(controller, default_match_changed);
}
......@@ -8,7 +8,6 @@
#include "build/build_config.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#if !defined(OS_IOS)
#include "content/public/browser/browser_context.h"
......@@ -18,16 +17,6 @@
// and notifies observers (chrome://omnibox debug page).
class OmniboxControllerEmitter : public KeyedService {
public:
class Observer : public base::CheckedObserver {
public:
// Invoked when new autocomplete queries are made from the omnibox
// controller or when those queries' results change.
virtual void OnOmniboxQuery(AutocompleteController* controller,
const AutocompleteInput& input) = 0;
virtual void OnOmniboxResultChanged(bool default_match_changed,
AutocompleteController* controller) = 0;
};
#if !defined(OS_IOS)
static OmniboxControllerEmitter* GetForBrowserContext(
content::BrowserContext* browser_context);
......@@ -37,18 +26,21 @@ class OmniboxControllerEmitter : public KeyedService {
~OmniboxControllerEmitter() override;
// Add/remove observer.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void AddObserver(AutocompleteController::Observer* observer);
void RemoveObserver(AutocompleteController::Observer* observer);
// Notifies registered observers when new autocomplete queries are made from
// the omnibox controller or when those queries' results change.
//
// TODO(tommycli): These two methods themselves should be overrides of
// AutocompleteController::Observer.
void NotifyOmniboxQuery(AutocompleteController* controller,
const AutocompleteInput& input);
void NotifyOmniboxResultChanged(bool default_match_changed,
AutocompleteController* controller);
private:
base::ObserverList<Observer> observers_;
base::ObserverList<AutocompleteController::Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(OmniboxControllerEmitter);
};
......
......@@ -14,7 +14,6 @@
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_controller.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment