| 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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 // AutocompleteControllerDelegate: | 76 // AutocompleteControllerDelegate: |
| 77 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; | 77 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; |
| 78 | 78 |
| 79 scoped_ptr<AutocompleteController> controller_; | 79 scoped_ptr<AutocompleteController> controller_; |
| 80 base::OneShotTimer<ZeroSuggestPrefetcher> expire_timer_; | 80 base::OneShotTimer<ZeroSuggestPrefetcher> expire_timer_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile) | 83 ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile) |
| 84 : controller_(new AutocompleteController( | 84 : controller_(new AutocompleteController( |
| 85 profile, TemplateURLServiceFactory::GetForProfile(profile), this, | 85 profile, this, AutocompleteProvider::TYPE_ZERO_SUGGEST)) { |
| 86 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { | |
| 87 // Creating an arbitrary fake_request_source to avoid passing in an invalid | 86 // Creating an arbitrary fake_request_source to avoid passing in an invalid |
| 88 // AutocompleteInput object. | 87 // AutocompleteInput object. |
| 89 base::string16 fake_request_source(base::ASCIIToUTF16( | 88 base::string16 fake_request_source(base::ASCIIToUTF16( |
| 90 "http://www.foobarbazblah.com")); | 89 "http://www.foobarbazblah.com")); |
| 91 controller_->StartZeroSuggest(AutocompleteInput( | 90 controller_->StartZeroSuggest(AutocompleteInput( |
| 92 fake_request_source, base::string16::npos, base::string16(), | 91 fake_request_source, base::string16::npos, base::string16(), |
| 93 GURL(fake_request_source), OmniboxEventProto::INVALID_SPEC, false, false, | 92 GURL(fake_request_source), OmniboxEventProto::INVALID_SPEC, false, false, |
| 94 true, true, ChromeAutocompleteSchemeClassifier(profile))); | 93 true, true, ChromeAutocompleteSchemeClassifier(profile))); |
| 95 // Delete ourselves after 10s. This is enough time to cache results or | 94 // Delete ourselves after 10s. This is enough time to cache results or |
| 96 // give up if the results haven't been received. | 95 // give up if the results haven't been received. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) { | 108 void ZeroSuggestPrefetcher::OnResultChanged(bool default_match_changed) { |
| 110 // Nothing to do here, the results have been cached. | 109 // Nothing to do here, the results have been cached. |
| 111 // We don't want to trigger deletion here because this is being called by the | 110 // We don't want to trigger deletion here because this is being called by the |
| 112 // AutocompleteController object. | 111 // AutocompleteController object. |
| 113 } | 112 } |
| 114 | 113 |
| 115 } // namespace | 114 } // namespace |
| 116 | 115 |
| 117 AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile) | 116 AutocompleteControllerAndroid::AutocompleteControllerAndroid(Profile* profile) |
| 118 : autocomplete_controller_(new AutocompleteController( | 117 : autocomplete_controller_(new AutocompleteController( |
| 119 profile, TemplateURLServiceFactory::GetForProfile(profile), this, | 118 profile, this, kAndroidAutocompleteProviders)), |
| 120 kAndroidAutocompleteProviders)), | |
| 121 inside_synchronous_start_(false), | 119 inside_synchronous_start_(false), |
| 122 profile_(profile) { | 120 profile_(profile) { |
| 123 } | 121 } |
| 124 | 122 |
| 125 void AutocompleteControllerAndroid::Start(JNIEnv* env, | 123 void AutocompleteControllerAndroid::Start(JNIEnv* env, |
| 126 jobject obj, | 124 jobject obj, |
| 127 jstring j_text, | 125 jstring j_text, |
| 128 jstring j_desired_tld, | 126 jstring j_desired_tld, |
| 129 jstring j_current_url, | 127 jstring j_current_url, |
| 130 bool prevent_inline_autocomplete, | 128 bool prevent_inline_autocomplete, |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 return; | 547 return; |
| 550 | 548 |
| 551 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 549 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 552 new ZeroSuggestPrefetcher(profile); | 550 new ZeroSuggestPrefetcher(profile); |
| 553 } | 551 } |
| 554 | 552 |
| 555 // Register native methods | 553 // Register native methods |
| 556 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 554 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 557 return RegisterNativesImpl(env); | 555 return RegisterNativesImpl(env); |
| 558 } | 556 } |
| OLD | NEW |