#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
}
void AutocompleteActionPredictor::RegisterTransitionalMatches(
- const string16& user_text,
+ const base::string16& user_text,
const AutocompleteResult& result) {
if (user_text.length() < kMinimumUserTextLength)
return;
- const string16 lower_user_text(base::i18n::ToLower(user_text));
+ const base::string16 lower_user_text(base::i18n::ToLower(user_text));
// Merge this in to an existing match if we already saw |user_text|
std::vector<TransitionalMatch>::iterator match_it =
transitional_matches_.clear();
}
+void AutocompleteActionPredictor::CancelPrerender() {
+ // If the prerender has already been abandoned, leave it to its own timeout;
+ // this normally gets called immediately after OnOmniboxOpenedUrl.
+ if (prerender_handle_ && !prerender_handle_->IsAbandoned()) {
+ prerender_handle_->OnCancel();
+ prerender_handle_.reset();
+ }
+}
+
void AutocompleteActionPredictor::StartPrerendering(
const GURL& url,
const content::SessionStorageNamespaceMap& session_storage_namespace_map,
// Given a match, return a recommended action.
AutocompleteActionPredictor::Action
AutocompleteActionPredictor::RecommendAction(
- const string16& user_text,
+ const base::string16& user_text,
const AutocompleteMatch& match) const {
bool is_in_db = false;
const double confidence = CalculateConfidence(user_text, match, &is_in_db);
return AutocompleteMatch::IsSearchType(match.type);
}
+bool AutocompleteActionPredictor::IsPrerenderAbandonedForTesting() {
+ return prerender_handle_ && prerender_handle_->IsAbandoned();
+}
+
void AutocompleteActionPredictor::Observe(
int type,
const content::NotificationSource& source,
break;
}
- // This notification does not catch all instances of the user navigating
- // from the Omnibox, but it does catch the cases where the dropdown is open
- // and those are the events we're most interested in.
case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: {
DCHECK(initialized_);
if (log.text.length() < kMinimumUserTextLength)
return;
- const AutocompleteMatch& match = log.result.match_at(log.selected_index);
+ // Do not attempt to learn from omnibox interactions where the omnibox
+ // dropdown is closed. In these cases the user text (|log.text|) that we
+ // learn from is either empty or effectively identical to the destination
+ // string. In either case, it can't teach us much. Also do not attempt
+ // to learn from paste-and-go actions even if the popup is open because
+ // the paste-and-go destination has no relation to whatever text the user
+ // may have typed.
+ if (!log.is_popup_open || log.is_paste_and_go)
+ return;
+
+ // Abandon the current prerender. If it is to be used, it will be used very
+ // soon, so use the lower timeout.
+ if (prerender_handle_) {
+ prerender_handle_->OnNavigateAway();
+ // Don't release |prerender_handle_| so it is canceled if it survives to the
+ // next StartPrerendering call.
+ }
UMA_HISTOGRAM_BOOLEAN(
base::StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s",
prerender::PrerenderManager::GetModeString()).c_str(),
prerender::IsOmniboxEnabled(profile_));
+ const AutocompleteMatch& match = log.result.match_at(log.selected_index);
const GURL& opened_url = match.destination_url;
- const string16 lower_user_text(base::i18n::ToLower(log.text));
+ const base::string16 lower_user_text(base::i18n::ToLower(log.text));
// Traverse transitional matches for those that have a user_text that is a
// prefix of |lower_user_text|.
}
double AutocompleteActionPredictor::CalculateConfidence(
- const string16& user_text,
+ const base::string16& user_text,
const AutocompleteMatch& match,
bool* is_in_db) const {
const DBCacheKey key = { user_text, match.destination_url };