summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc84
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h14
-rw-r--r--chrome/browser/automation/automation_profile_impl.h3
-rw-r--r--chrome/browser/profile.cc16
-rw-r--r--chrome/browser/profile.h9
-rw-r--r--chrome/browser/search_versus_navigate_classifier.cc56
-rw-r--r--chrome/browser/search_versus_navigate_classifier.h52
-rwxr-xr-xchrome/chrome.gyp2
-rw-r--r--chrome/test/testing_profile.h3
9 files changed, 156 insertions, 83 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index cd7ea1e..218fdd5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
@@ -25,14 +26,6 @@
///////////////////////////////////////////////////////////////////////////////
// AutocompleteEditModel
-// A single AutocompleteController used solely for making synchronous calls. We
-// avoid using the popup's controller here because we don't want to interrupt
-// in-progress queries or modify the popup state. We don't need a controller
-// for every edit because this will always be accessed on the main thread, so we
-// won't have thread-safety problems.
-static AutocompleteController* synchronous_controller = NULL;
-static int synchronous_controller_refcount = 0;
-
AutocompleteEditModel::AutocompleteEditModel(
AutocompleteEditView* view,
AutocompleteEditController* controller,
@@ -52,16 +45,6 @@ AutocompleteEditModel::AutocompleteEditModel(
show_search_hint_(true),
paste_and_go_transition_(PageTransition::TYPED),
profile_(profile) {
- if (++synchronous_controller_refcount == 1) {
- // We don't have a controller yet, so create one. No profile is set since
- // we'll set this before each call to the controller.
- synchronous_controller = new AutocompleteController(NULL);
- }
-}
-
-AutocompleteEditModel::~AutocompleteEditModel() {
- if (--synchronous_controller_refcount == 0)
- delete synchronous_controller;
}
void AutocompleteEditModel::SetPopupModel(AutocompletePopupModel* popup_model) {
@@ -203,28 +186,13 @@ void AutocompleteEditModel::StartAutocomplete(
}
bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
- // Reset local state.
paste_and_go_url_ = GURL();
paste_and_go_transition_ = PageTransition::TYPED;
paste_and_go_alternate_nav_url_ = GURL();
- // Ask the controller what do do with this input.
- // Setting the profile is cheap, and since there's one synchronous_controller
- // for many tabs which may all have different profiles, it ensures we're
- // always using the right one.
- synchronous_controller->SetProfile(profile_);
- synchronous_controller->Start(text, std::wstring(), true, false, true);
- DCHECK(synchronous_controller->done());
- const AutocompleteResult& result = synchronous_controller->result();
- if (result.empty())
- return false;
-
- // Set local state based on the default action for this input.
- const AutocompleteResult::const_iterator match(result.default_match());
- DCHECK(match != result.end());
- paste_and_go_url_ = match->destination_url;
- paste_and_go_transition_ = match->transition;
- paste_and_go_alternate_nav_url_ = result.alternate_nav_url();
+ profile_->GetSearchVersusNavigateClassifier()->Classify(text, std::wstring(),
+ NULL, &paste_and_go_url_, &paste_and_go_transition_, NULL,
+ &paste_and_go_alternate_nav_url_);
return paste_and_go_url_.is_valid();
}
@@ -600,38 +568,16 @@ GURL AutocompleteEditModel::GetURLForCurrentText(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) const {
- return (popup_->IsOpen() || query_in_progress()) ?
- popup_->URLsForCurrentSelection(transition,
- is_history_what_you_typed_match,
- alternate_nav_url) :
- URLsForDefaultMatch(transition, is_history_what_you_typed_match,
- alternate_nav_url);
-}
+ if (popup_->IsOpen() || query_in_progress()) {
+ return popup_->URLsForCurrentSelection(transition,
+ is_history_what_you_typed_match,
+ alternate_nav_url);
+ }
-GURL AutocompleteEditModel::URLsForDefaultMatch(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const {
- // Ask the controller what do do with this input.
- // Setting the profile is cheap, and since there's one synchronous_controller
- // for many tabs which may all have different profiles, it ensures we're
- // always using the right one.
- synchronous_controller->SetProfile(profile_);
- synchronous_controller->Start(UserTextFromDisplayText(view_->GetText()),
- GetDesiredTLD(), true, false, true);
- CHECK(synchronous_controller->done());
-
- const AutocompleteResult& result = synchronous_controller->result();
- if (result.empty())
- return GURL();
-
- // Get the URLs for the default match.
- const AutocompleteResult::const_iterator match = result.default_match();
- if (transition)
- *transition = match->transition;
- if (is_history_what_you_typed_match)
- *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
- if (alternate_nav_url)
- *alternate_nav_url = result.alternate_nav_url();
- return match->destination_url;
+ GURL destination_url;
+ profile_->GetSearchVersusNavigateClassifier()->Classify(
+ UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), NULL,
+ &destination_url, transition, is_history_what_you_typed_match,
+ alternate_nav_url);
+ return destination_url;
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 741b8a0..a4f4e69 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -101,7 +101,7 @@ class AutocompleteEditModel : public NotificationObserver {
AutocompleteEditModel(AutocompleteEditView* view,
AutocompleteEditController* controller,
Profile* profile);
- ~AutocompleteEditModel();
+ ~AutocompleteEditModel() {}
void SetPopupModel(AutocompletePopupModel* popup_model);
@@ -334,18 +334,6 @@ class AutocompleteEditModel : public NotificationObserver {
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) const;
- // Performs a query for only the synchronously available matches for the
- // current input, sets |transition|, |is_history_what_you_typed_match|, and
- // |alternate_nav_url| (if applicable) based on the default match, and returns
- // its url. |transition|, |is_history_what_you_typed_match| and/or
- // |alternate_nav_url| may be null, in which case they are not updated.
- //
- // If there are no matches for the input, leaves the outparams unset and
- // returns the empty string.
- GURL URLsForDefaultMatch(PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const;
-
AutocompleteEditView* view_;
AutocompletePopupModel* popup_;
diff --git a/chrome/browser/automation/automation_profile_impl.h b/chrome/browser/automation/automation_profile_impl.h
index 77401dc..a794c97 100644
--- a/chrome/browser/automation/automation_profile_impl.h
+++ b/chrome/browser/automation/automation_profile_impl.h
@@ -84,6 +84,9 @@ class AutomationProfileImpl : public Profile {
virtual HistoryService* GetHistoryServiceWithoutCreating() {
return original_profile_->GetHistoryServiceWithoutCreating();
}
+ virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
+ return original_profile_->GetSearchVersusNavigateClassifier();
+ }
virtual WebDataService* GetWebDataService(ServiceAccessType access) {
return original_profile_->GetWebDataService(access);
}
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index ac9f01a..43a5640 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/privacy_blacklist/blacklist_io.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/sessions/session_service.h"
@@ -301,6 +302,10 @@ class OffTheRecordProfileImpl : public Profile,
}
}
+ virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
+ return profile_->GetSearchVersusNavigateClassifier();
+ }
+
virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
if (sat == EXPLICIT_ACCESS) {
return profile_->GetWebDataService(sat);
@@ -546,7 +551,7 @@ class OffTheRecordProfileImpl : public Profile,
// Time we were started.
Time start_time_;
- DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl);
+ DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
};
ProfileImpl::ProfileImpl(const FilePath& path)
@@ -1006,6 +1011,15 @@ TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
return template_url_fetcher_.get();
}
+SearchVersusNavigateClassifier* ProfileImpl::GetSearchVersusNavigateClassifier()
+{
+ if (!search_versus_navigate_classifier_.get()) {
+ search_versus_navigate_classifier_.reset(
+ new SearchVersusNavigateClassifier(this));
+ }
+ return search_versus_navigate_classifier_.get();
+}
+
WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
if (!created_web_data_service_)
CreateWebDataService();
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 116310d..78d2c9a 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -43,6 +43,7 @@ class NavigationController;
class PasswordStore;
class PrefService;
class ProfileSyncService;
+class SearchVersusNavigateClassifier;
class SessionService;
class SpellChecker;
class SSLConfigServiceManager;
@@ -201,6 +202,12 @@ class Profile {
// doesn't already exist.
virtual HistoryService* GetHistoryServiceWithoutCreating() = 0;
+ // Retrieves a pointer to the SearchVersusNavigateClassifier associated with
+ // this profile. The SearchVersusNavigateClassifier is lazily created the
+ // first time that this method is called.
+ virtual SearchVersusNavigateClassifier*
+ GetSearchVersusNavigateClassifier() = 0;
+
// Returns the WebDataService for this profile. This is owned by
// the Profile. Callers that outlive the life of this profile need to be
// sure they refcount the returned value.
@@ -405,6 +412,7 @@ class ProfileImpl : public Profile,
virtual FaviconService* GetFaviconService(ServiceAccessType sat);
virtual HistoryService* GetHistoryService(ServiceAccessType sat);
virtual HistoryService* GetHistoryServiceWithoutCreating();
+ virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier();
virtual WebDataService* GetWebDataService(ServiceAccessType sat);
virtual WebDataService* GetWebDataServiceWithoutCreating();
virtual PasswordStore* GetPasswordStore(ServiceAccessType sat);
@@ -515,6 +523,7 @@ class ProfileImpl : public Profile,
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<HistoryService> history_service_;
scoped_refptr<FaviconService> favicon_service_;
+ scoped_ptr<SearchVersusNavigateClassifier> search_versus_navigate_classifier_;
scoped_refptr<WebDataService> web_data_service_;
scoped_refptr<PasswordStore> password_store_;
scoped_refptr<SessionService> session_service_;
diff --git a/chrome/browser/search_versus_navigate_classifier.cc b/chrome/browser/search_versus_navigate_classifier.cc
new file mode 100644
index 0000000..b32b92b
--- /dev/null
+++ b/chrome/browser/search_versus_navigate_classifier.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/search_versus_navigate_classifier.h"
+
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "googleurl/src/gurl.h"
+
+SearchVersusNavigateClassifier::SearchVersusNavigateClassifier(Profile* profile)
+ : controller_(new AutocompleteController(profile)) {
+}
+
+SearchVersusNavigateClassifier::~SearchVersusNavigateClassifier() {
+}
+
+void SearchVersusNavigateClassifier::Classify(const std::wstring& text,
+ const std::wstring& desired_tld,
+ bool* is_search,
+ GURL* destination_url,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url) {
+ controller_->Start(text, desired_tld, true, false, true);
+ DCHECK(controller_->done());
+ const AutocompleteResult& result = controller_->result();
+ if (result.empty()) {
+ if (is_search)
+ *is_search = false;
+ if (destination_url)
+ *destination_url = GURL();
+ if (transition)
+ *transition = PageTransition::TYPED;
+ if (is_history_what_you_typed_match)
+ *is_history_what_you_typed_match = false;
+ if (alternate_nav_url)
+ *alternate_nav_url = GURL();
+ return;
+ }
+
+ const AutocompleteResult::const_iterator match(result.default_match());
+ DCHECK(match != result.end());
+
+ // If this is a search, the page transition will be GENERATED rather than
+ // TYPED.
+ if (is_search)
+ *is_search = (match->transition != PageTransition::TYPED);
+ if (destination_url)
+ *destination_url = match->destination_url;
+ if (transition)
+ *transition = match->transition;
+ if (is_history_what_you_typed_match)
+ *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
+ if (alternate_nav_url)
+ *alternate_nav_url = result.alternate_nav_url();
+}
diff --git a/chrome/browser/search_versus_navigate_classifier.h b/chrome/browser/search_versus_navigate_classifier.h
new file mode 100644
index 0000000..94471b8
--- /dev/null
+++ b/chrome/browser/search_versus_navigate_classifier.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2009 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 CHROME_BROWSER_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
+#define CHROME_BROWSER_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "chrome/common/page_transition_types.h"
+
+class AutocompleteController;
+class GURL;
+class Profile;
+
+class SearchVersusNavigateClassifier {
+ public:
+ explicit SearchVersusNavigateClassifier(Profile* profile);
+ virtual ~SearchVersusNavigateClassifier();
+
+ // Given some string |text| that the user wants to use for navigation,
+ // determines whether to treat it as a search query or a URL, and returns the
+ // details of the resulting navigation.
+ // NOTE: After |desired_tld|, all parameters are potentially-NULL outparams.
+ // |desired_tld| - User's desired TLD.
+ // See AutocompleteInput::desired_tld().
+ // |is_search| - Set to true if this is to be treated as a
+ // query rather than URL.
+ // |destination_url| - The URL to load. It may be empty if there is no
+ // possible navigation (when |text| is empty).
+ // |transition| - The transition type.
+ // |is_history_what_you_typed_match|
+ // - Set to true when the default match is the
+ // "what you typed" match from the history.
+ // |alternate_nav_url| - The navigational URL in case of an accidental
+ // search; see comments on
+ // AutocompleteResult::alternate_nav_url_ in
+ // autocomplete.h.
+ void Classify(const std::wstring& text,
+ const std::wstring& desired_tld,
+ bool* is_search,
+ GURL* destination_url,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
+
+ private:
+ scoped_ptr<AutocompleteController> controller_;
+};
+
+#endif // CHROME_BROWSER_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d89a9af..f536735 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -2006,6 +2006,8 @@
'browser/safe_browsing/safe_browsing_util.h',
'browser/sandbox_policy.cc',
'browser/sandbox_policy.h',
+ 'browser/search_versus_navigate_classifier.cc',
+ 'browser/search_versus_navigate_classifier.h',
'browser/search_engines/edit_search_engine_controller.cc',
'browser/search_engines/edit_search_engine_controller.h',
'browser/search_engines/keyword_editor_controller.cc',
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 8791295..adbb7dd4 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -98,6 +98,9 @@ class TestingProfile : public Profile {
void set_has_history_service(bool has_history_service) {
has_history_service_ = has_history_service;
}
+ virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
+ return NULL;
+ }
virtual WebDataService* GetWebDataService(ServiceAccessType access) {
return NULL;
}