Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 13932034: Omnibox refactor, introduced OmniboxController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Answered Peter's comments. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/omnibox/omnibox_edit_model.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
index a7df58c557662e9b66bd60289121be4c23dc92a8..0aa077f7c4e2099d5d5110259d655dedd695c033 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -134,12 +134,7 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
in_revert_(false),
in_escape_handler_(false),
allow_exact_keyword_match_(false) {
- // Use a restricted subset of the autocomplete providers if we're using the
- // Instant Extended API, as it doesn't support them all.
- autocomplete_controller_.reset(new AutocompleteController(profile, this,
- chrome::IsInstantExtendedAPIEnabled() ?
- AutocompleteClassifier::kInstantExtendedOmniboxProviders :
- AutocompleteClassifier::kDefaultOmniboxProviders));
+ omnibox_controller_.reset(new OmniboxController(this, profile));
delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile));
}
@@ -238,7 +233,7 @@ void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text,
view_->OnAfterPossibleChange();
} else if (popup_->IsOpen()) {
SearchProvider* search_provider =
- autocomplete_controller_->search_provider();
+ autocomplete_controller()->search_provider();
// There may be no providers during testing; guard against that.
if (search_provider)
search_provider->FinalizeInstantQuery(input_text, suggestion);
@@ -258,7 +253,7 @@ void OmniboxEditModel::SetInstantSuggestion(
DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type);
view_->SetInstantSuggestion(suggestion.text);
SearchProvider* search_provider =
- autocomplete_controller_->search_provider();
+ autocomplete_controller()->search_provider();
if (search_provider)
search_provider->ClearInstantSuggestion();
break;
@@ -372,7 +367,7 @@ bool OmniboxEditModel::UseVerbatimInstant() {
#if defined(OS_MACOSX)
// TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView,
// so that we can display Instant suggest along with composition text.
- const AutocompleteInput& input = autocomplete_controller_->input();
+ const AutocompleteInput& input = autocomplete_controller()->input();
if (input.prevent_inline_autocomplete())
return true;
#endif
@@ -468,7 +463,7 @@ void OmniboxEditModel::SetInputInProgress(bool in_progress) {
if (user_input_in_progress_) {
time_user_first_modified_omnibox_ = base::TimeTicks::Now();
content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress"));
- autocomplete_controller_->ResetSession();
+ autocomplete_controller()->ResetSession();
}
controller_->OnInputInProgress(in_progress);
@@ -527,7 +522,7 @@ void OmniboxEditModel::StartAutocomplete(
// We don't explicitly clear OmniboxPopupModel::manually_selected_match, as
// Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it.
- autocomplete_controller_->Start(AutocompleteInput(
+ autocomplete_controller()->Start(AutocompleteInput(
user_text_, cursor_position, string16(), GURL(),
prevent_inline_autocomplete || just_deleted_text_ ||
(has_selected_text && inline_autocomplete_text_.empty()) ||
@@ -537,7 +532,7 @@ void OmniboxEditModel::StartAutocomplete(
}
void OmniboxEditModel::StopAutocomplete() {
- autocomplete_controller_->Stop(true);
+ autocomplete_controller()->Stop(true);
}
bool OmniboxEditModel::CanPasteAndGo(const string16& text) const {
@@ -577,7 +572,7 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition,
// that, then we use this. These matches are marked as generated by the
// HistoryURLProvider so we only generate them if this provider is present.
if (control_key_state_ == DOWN_WITHOUT_CHANGE && !KeywordIsSelected() &&
- autocomplete_controller_->history_url_provider()) {
+ autocomplete_controller()->history_url_provider()) {
// Generate a new AutocompleteInput, copying the latest one but using "com"
// as the desired TLD. Then use this autocomplete input to generate a
// URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent
@@ -586,14 +581,14 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition,
// to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not
// "foodnetwork.com". At the time of writing, this behavior matches
// Internet Explorer, but not Firefox.
- const AutocompleteInput& old_input = autocomplete_controller_->input();
+ const AutocompleteInput& old_input = autocomplete_controller()->input();
AutocompleteInput input(
old_input.text(), old_input.cursor_position(), ASCIIToUTF16("com"),
GURL(), old_input.prevent_inline_autocomplete(),
old_input.prefer_keyword(), old_input.allow_exact_keyword_match(),
old_input.matches_requested());
AutocompleteMatch url_match = HistoryURLProvider::SuggestExactInput(
- autocomplete_controller_->history_url_provider(), input, true);
+ autocomplete_controller()->history_url_provider(), input, true);
if (url_match.destination_url.is_valid()) {
// We have a valid URL, we use this newly generated AutocompleteMatch.
@@ -644,16 +639,16 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match,
const base::TimeTicks& now(base::TimeTicks::Now());
// TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly.
AutocompleteLog log(
- autocomplete_controller_->input().text(),
+ autocomplete_controller()->input().text(),
just_deleted_text_,
- autocomplete_controller_->input().type(),
+ autocomplete_controller()->input().type(),
popup_->selected_line(),
-1, // don't yet know tab ID; set later if appropriate
delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) :
metrics::OmniboxEventProto_PageClassification_OTHER,
now - time_user_first_modified_omnibox_,
string16::npos, // completed_length; possibly set later
- now - autocomplete_controller_->last_time_default_match_changed(),
+ now - autocomplete_controller()->last_time_default_match_changed(),
result());
DCHECK(user_input_in_progress_ ||
match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST)
@@ -680,7 +675,7 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match,
// tab, we don't know the tab ID yet.)
log.tab_id = delegate_->GetSessionID().id();
}
- autocomplete_controller_->AddProvidersInfo(&log.providers_info);
+ autocomplete_controller()->AddProvidersInfo(&log.providers_info);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
content::Source<Profile>(profile_),
@@ -734,7 +729,7 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match,
} else {
base::TimeDelta query_formulation_time =
base::TimeTicks::Now() - time_user_first_modified_omnibox_;
- const GURL destination_url = autocomplete_controller_->
+ const GURL destination_url = autocomplete_controller()->
GetDestinationURL(match, query_formulation_time);
// If running with instant, notify the instant controller that a navigation
@@ -762,7 +757,7 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match,
bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) {
DCHECK(is_keyword_hint_ && !keyword_.empty());
- autocomplete_controller_->Stop(false);
+ autocomplete_controller()->Stop(false);
is_keyword_hint_ = false;
if (popup_->IsOpen())
@@ -788,7 +783,7 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) {
}
void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
- autocomplete_controller_->Stop(false);
+ autocomplete_controller()->Stop(false);
ClearPopupKeywordMode();
const string16 window_text(keyword_ + visible_text);
@@ -813,7 +808,7 @@ void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
}
const AutocompleteResult& OmniboxEditModel::result() const {
- return autocomplete_controller_->result();
+ return autocomplete_controller()->result();
}
void OmniboxEditModel::OnSetFocus(bool control_down) {
@@ -830,8 +825,8 @@ void OmniboxEditModel::OnSetFocus(bool control_down) {
// that we avoid PermanentURL() here because it's not guaranteed to give us
// the actual underlying current URL, e.g. if we're on the NTP and the
// |permanent_text_| is empty.
- autocomplete_controller_->StartZeroSuggest(delegate_->GetURL(),
- user_text_);
+ autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(),
+ user_text_);
}
delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
@@ -854,7 +849,7 @@ void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
}
// TODO(jered): Rip this out along with StartZeroSuggest.
- autocomplete_controller_->StopZeroSuggest();
+ autocomplete_controller()->StopZeroSuggest();
delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
}
@@ -951,7 +946,7 @@ void OmniboxEditModel::OnUpOrDownKeyPressed(int count) {
// that it's stepping through. In that case, our popup model is
// irrelevant, so don't process the key press ourselves. However, do stop
// the autocomplete system from changing the results.
- autocomplete_controller_->Stop(false);
+ autocomplete_controller()->Stop(false);
} else {
// The popup is open, so the user should be able to interact with it
// normally.
@@ -1184,7 +1179,7 @@ void OmniboxEditModel::OnResultChanged(bool default_match_changed) {
InstantController* instant = controller_->GetInstant();
if (instant && !in_revert_) {
instant->HandleAutocompleteResults(
- *autocomplete_controller_->providers());
+ *autocomplete_controller()->providers());
}
} else if (was_open) {
// Accepts the temporary text as the user text, because it makes little
@@ -1198,7 +1193,7 @@ void OmniboxEditModel::OnResultChanged(bool default_match_changed) {
}
bool OmniboxEditModel::query_in_progress() const {
- return !autocomplete_controller_->done();
+ return !autocomplete_controller()->done();
}
void OmniboxEditModel::InternalSetUserText(const string16& text) {
@@ -1230,7 +1225,7 @@ void OmniboxEditModel::InfoForCurrentSelection(AutocompleteMatch* match,
GURL* alternate_nav_url) const {
DCHECK(match != NULL);
const AutocompleteResult& result = this->result();
- if (!autocomplete_controller_->done()) {
+ if (!autocomplete_controller()->done()) {
// It's technically possible for |result| to be empty if no provider returns
// a synchronous result but the query has not completed synchronously;
// pratically, however, that should never actually happen.
@@ -1334,8 +1329,8 @@ bool OmniboxEditModel::CreatedKeywordSearchByInsertingSpaceInMiddle(
TrimWhitespace(new_text.substr(0, space_position), TRIM_LEADING, &keyword);
// TODO(sreeram): Once the Instant extended API supports keywords properly,
// keyword_provider() should never be NULL. Remove that clause.
- return !keyword.empty() && autocomplete_controller_->keyword_provider() &&
- !autocomplete_controller_->keyword_provider()->
+ return !keyword.empty() && autocomplete_controller()->keyword_provider() &&
+ !autocomplete_controller()->keyword_provider()->
GetKeywordForText(keyword).empty();
}
@@ -1357,9 +1352,9 @@ bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) {
// Remove "?" if we're in forced query mode.
AutocompleteInput::RemoveForcedQueryStringIfNecessary(
- autocomplete_controller_->input().type(), &user_text);
+ autocomplete_controller()->input().type(), &user_text);
AutocompleteInput::RemoveForcedQueryStringIfNecessary(
- autocomplete_controller_->input().type(), &full_text);
+ autocomplete_controller()->input().type(), &full_text);
size_t start, end;
view_->GetSelectionBounds(&start, &end);

Powered by Google App Engine
This is Rietveld 408576698