| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/omnibox/autocomplete_controller_android.h" | 5 #include "chrome/browser/android/omnibox/autocomplete_controller_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
| 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 21 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 21 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 24 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 25 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 25 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
| 26 #include "chrome/browser/profiles/incognito_helpers.h" | 26 #include "chrome/browser/profiles/incognito_helpers.h" |
| 27 #include "chrome/browser/profiles/profile_android.h" | 27 #include "chrome/browser/profiles/profile_android.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/browser/search/search.h" | |
| 30 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 31 #include "chrome/browser/sessions/session_tab_helper.h" | 30 #include "chrome/browser/sessions/session_tab_helper.h" |
| 32 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | |
| 33 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/search/instant_types.h" | |
| 35 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 36 #include "components/bookmarks/browser/bookmark_model.h" | 33 #include "components/bookmarks/browser/bookmark_model.h" |
| 37 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 34 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 38 #include "components/metrics/proto/omnibox_event.pb.h" | 35 #include "components/metrics/proto/omnibox_event.pb.h" |
| 39 #include "components/omnibox/browser/autocomplete_classifier.h" | 36 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 40 #include "components/omnibox/browser/autocomplete_controller.h" | 37 #include "components/omnibox/browser/autocomplete_controller.h" |
| 41 #include "components/omnibox/browser/autocomplete_input.h" | 38 #include "components/omnibox/browser/autocomplete_input.h" |
| 42 #include "components/omnibox/browser/autocomplete_match.h" | 39 #include "components/omnibox/browser/autocomplete_match.h" |
| 43 #include "components/omnibox/browser/autocomplete_match_type.h" | 40 #include "components/omnibox/browser/autocomplete_match_type.h" |
| 44 #include "components/omnibox/browser/omnibox_event_global_tracker.h" | 41 #include "components/omnibox/browser/omnibox_event_global_tracker.h" |
| 45 #include "components/omnibox/browser/omnibox_field_trial.h" | 42 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 46 #include "components/omnibox/browser/omnibox_log.h" | 43 #include "components/omnibox/browser/omnibox_log.h" |
| 47 #include "components/omnibox/browser/search_provider.h" | 44 #include "components/omnibox/browser/search_provider.h" |
| 48 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 49 #include "components/search/search.h" | |
| 50 #include "components/search_engines/template_url_service.h" | 46 #include "components/search_engines/template_url_service.h" |
| 51 #include "components/toolbar/toolbar_model.h" | 47 #include "components/toolbar/toolbar_model.h" |
| 52 #include "components/url_formatter/url_formatter.h" | 48 #include "components/url_formatter/url_formatter.h" |
| 53 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/common/url_constants.h" | 50 #include "content/public/common/url_constants.h" |
| 55 #include "jni/AutocompleteController_jni.h" | 51 #include "jni/AutocompleteController_jni.h" |
| 56 #include "net/base/escape.h" | 52 #include "net/base/escape.h" |
| 57 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 53 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 58 | 54 |
| 59 using base::android::AttachCurrentThread; | 55 using base::android::AttachCurrentThread; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 AutocompleteControllerAndroid::~AutocompleteControllerAndroid() { | 331 AutocompleteControllerAndroid::~AutocompleteControllerAndroid() { |
| 336 } | 332 } |
| 337 | 333 |
| 338 void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) { | 334 void AutocompleteControllerAndroid::InitJNI(JNIEnv* env, jobject obj) { |
| 339 weak_java_autocomplete_controller_android_ = | 335 weak_java_autocomplete_controller_android_ = |
| 340 JavaObjectWeakGlobalRef(env, obj); | 336 JavaObjectWeakGlobalRef(env, obj); |
| 341 } | 337 } |
| 342 | 338 |
| 343 void AutocompleteControllerAndroid::OnResultChanged( | 339 void AutocompleteControllerAndroid::OnResultChanged( |
| 344 bool default_match_changed) { | 340 bool default_match_changed) { |
| 345 if (!autocomplete_controller_) | 341 if (autocomplete_controller_ && !inside_synchronous_start_) |
| 346 return; | |
| 347 | |
| 348 const AutocompleteResult& result = autocomplete_controller_->result(); | |
| 349 const AutocompleteResult::const_iterator default_match( | |
| 350 result.default_match()); | |
| 351 if ((default_match != result.end()) && default_match_changed && | |
| 352 search::IsInstantExtendedAPIEnabled() && | |
| 353 search::ShouldPrefetchSearchResults()) { | |
| 354 InstantSuggestion prefetch_suggestion; | |
| 355 // If the default match should be prefetched, do that. | |
| 356 if (SearchProvider::ShouldPrefetch(*default_match)) { | |
| 357 prefetch_suggestion.text = default_match->contents; | |
| 358 prefetch_suggestion.metadata = | |
| 359 SearchProvider::GetSuggestMetadata(*default_match); | |
| 360 } | |
| 361 // Send the prefetch suggestion unconditionally to the Instant search base | |
| 362 // page. If there is no suggestion to prefetch, we need to send a blank | |
| 363 // query to clear the prefetched results. | |
| 364 InstantSearchPrerenderer* prerenderer = | |
| 365 InstantSearchPrerenderer::GetForProfile(profile_); | |
| 366 if (prerenderer) | |
| 367 prerenderer->Prerender(prefetch_suggestion); | |
| 368 } | |
| 369 if (!inside_synchronous_start_) | |
| 370 NotifySuggestionsReceived(autocomplete_controller_->result()); | 342 NotifySuggestionsReceived(autocomplete_controller_->result()); |
| 371 } | 343 } |
| 372 | 344 |
| 373 void AutocompleteControllerAndroid::NotifySuggestionsReceived( | 345 void AutocompleteControllerAndroid::NotifySuggestionsReceived( |
| 374 const AutocompleteResult& autocomplete_result) { | 346 const AutocompleteResult& autocomplete_result) { |
| 375 JNIEnv* env = AttachCurrentThread(); | 347 JNIEnv* env = AttachCurrentThread(); |
| 376 ScopedJavaLocalRef<jobject> java_bridge = | 348 ScopedJavaLocalRef<jobject> java_bridge = |
| 377 weak_java_autocomplete_controller_android_.get(env); | 349 weak_java_autocomplete_controller_android_.get(env); |
| 378 if (!java_bridge.obj()) | 350 if (!java_bridge.obj()) |
| 379 return; | 351 return; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 return; | 595 return; |
| 624 | 596 |
| 625 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 597 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 626 new ZeroSuggestPrefetcher(profile); | 598 new ZeroSuggestPrefetcher(profile); |
| 627 } | 599 } |
| 628 | 600 |
| 629 // Register native methods | 601 // Register native methods |
| 630 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 602 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 631 return RegisterNativesImpl(env); | 603 return RegisterNativesImpl(env); |
| 632 } | 604 } |
| OLD | NEW |