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