Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: chrome/browser/android/omnibox/autocomplete_controller_android.cc

Issue 820063002: Add support for providers called when the omnibox is focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android build. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 using base::android::ConvertUTF16ToJavaString; 57 using base::android::ConvertUTF16ToJavaString;
58 using metrics::OmniboxEventProto; 58 using metrics::OmniboxEventProto;
59 59
60 namespace { 60 namespace {
61 61
62 const int kAndroidAutocompleteProviders = 62 const int kAndroidAutocompleteProviders =
63 AutocompleteClassifier::kDefaultOmniboxProviders; 63 AutocompleteClassifier::kDefaultOmniboxProviders;
64 64
65 /** 65 /**
66 * A prefetcher class responsible for triggering zero suggest prefetch. 66 * A prefetcher class responsible for triggering zero suggest prefetch.
67 * The prefetch occurs as a side-effect of calling StartZeroSuggest() on 67 * The prefetch occurs as a side-effect of calling OnOmniboxFocused() on
68 * the AutocompleteController object. 68 * the AutocompleteController object.
69 */ 69 */
70 class ZeroSuggestPrefetcher : public AutocompleteControllerDelegate { 70 class ZeroSuggestPrefetcher : public AutocompleteControllerDelegate {
71 public: 71 public:
72 explicit ZeroSuggestPrefetcher(Profile* profile); 72 explicit ZeroSuggestPrefetcher(Profile* profile);
73 73
74 private: 74 private:
75 virtual ~ZeroSuggestPrefetcher(); 75 virtual ~ZeroSuggestPrefetcher();
76 void SelfDestruct(); 76 void SelfDestruct();
77 77
78 // AutocompleteControllerDelegate: 78 // AutocompleteControllerDelegate:
79 virtual void OnResultChanged(bool default_match_changed) override; 79 virtual void OnResultChanged(bool default_match_changed) override;
80 80
81 scoped_ptr<AutocompleteController> controller_; 81 scoped_ptr<AutocompleteController> controller_;
82 base::OneShotTimer<ZeroSuggestPrefetcher> expire_timer_; 82 base::OneShotTimer<ZeroSuggestPrefetcher> expire_timer_;
83 }; 83 };
84 84
85 ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile) 85 ZeroSuggestPrefetcher::ZeroSuggestPrefetcher(Profile* profile)
86 : controller_(new AutocompleteController( 86 : controller_(new AutocompleteController(
87 profile, TemplateURLServiceFactory::GetForProfile(profile), this, 87 profile, TemplateURLServiceFactory::GetForProfile(profile), this,
88 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { 88 AutocompleteProvider::TYPE_ZERO_SUGGEST)) {
89 // Creating an arbitrary fake_request_source to avoid passing in an invalid 89 // Creating an arbitrary fake_request_source to avoid passing in an invalid
90 // AutocompleteInput object. 90 // AutocompleteInput object.
91 base::string16 fake_request_source(base::ASCIIToUTF16( 91 base::string16 fake_request_source(base::ASCIIToUTF16(
92 "http://www.foobarbazblah.com")); 92 "http://www.foobarbazblah.com"));
93 controller_->StartZeroSuggest(AutocompleteInput( 93 controller_->OnOmniboxFocused(AutocompleteInput(
94 fake_request_source, base::string16::npos, std::string(), 94 fake_request_source, base::string16::npos, std::string(),
95 GURL(fake_request_source), OmniboxEventProto::INVALID_SPEC, false, false, 95 GURL(fake_request_source), OmniboxEventProto::INVALID_SPEC, false, false,
96 true, true, ChromeAutocompleteSchemeClassifier(profile))); 96 true, true, ChromeAutocompleteSchemeClassifier(profile)));
97 // Delete ourselves after 10s. This is enough time to cache results or 97 // Delete ourselves after 10s. This is enough time to cache results or
98 // give up if the results haven't been received. 98 // give up if the results haven't been received.
99 expire_timer_.Start(FROM_HERE, 99 expire_timer_.Start(FROM_HERE,
100 base::TimeDelta::FromMilliseconds(10000), 100 base::TimeDelta::FromMilliseconds(10000),
101 this, &ZeroSuggestPrefetcher::SelfDestruct); 101 this, &ZeroSuggestPrefetcher::SelfDestruct);
102 } 102 }
103 103
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 autocomplete_controller_->Start(input_); 154 autocomplete_controller_->Start(input_);
155 } 155 }
156 156
157 ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify( 157 ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify(
158 JNIEnv* env, 158 JNIEnv* env,
159 jobject obj, 159 jobject obj,
160 jstring j_text) { 160 jstring j_text) {
161 return GetTopSynchronousResult(env, obj, j_text, true); 161 return GetTopSynchronousResult(env, obj, j_text, true);
162 } 162 }
163 163
164 void AutocompleteControllerAndroid::StartZeroSuggest( 164 void AutocompleteControllerAndroid::OnOmniboxFocused(
165 JNIEnv* env, 165 JNIEnv* env,
166 jobject obj, 166 jobject obj,
167 jstring j_omnibox_text, 167 jstring j_omnibox_text,
168 jstring j_current_url, 168 jstring j_current_url,
169 jboolean is_query_in_omnibox, 169 jboolean is_query_in_omnibox,
170 jboolean focused_from_fakebox) { 170 jboolean focused_from_fakebox) {
171 if (!autocomplete_controller_) 171 if (!autocomplete_controller_)
172 return; 172 return;
173 173
174 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); 174 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url);
175 const GURL current_url = GURL(url); 175 const GURL current_url = GURL(url);
176 base::string16 omnibox_text = ConvertJavaStringToUTF16(env, j_omnibox_text); 176 base::string16 omnibox_text = ConvertJavaStringToUTF16(env, j_omnibox_text);
177 177
178 // If omnibox text is empty, set it to the current URL for the purposes of 178 // If omnibox text is empty, set it to the current URL for the purposes of
179 // populating the verbatim match. 179 // populating the verbatim match.
180 if (omnibox_text.empty()) 180 if (omnibox_text.empty())
181 omnibox_text = url; 181 omnibox_text = url;
182 182
183 input_ = AutocompleteInput( 183 input_ = AutocompleteInput(
184 omnibox_text, base::string16::npos, std::string(), current_url, 184 omnibox_text, base::string16::npos, std::string(), current_url,
185 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox), 185 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox),
186 false, false, true, true, ChromeAutocompleteSchemeClassifier(profile_)); 186 false, false, true, true, ChromeAutocompleteSchemeClassifier(profile_));
187 autocomplete_controller_->StartZeroSuggest(input_); 187 autocomplete_controller_->OnOmniboxFocused(input_);
188 } 188 }
189 189
190 void AutocompleteControllerAndroid::Stop(JNIEnv* env, 190 void AutocompleteControllerAndroid::Stop(JNIEnv* env,
191 jobject obj, 191 jobject obj,
192 bool clear_results) { 192 bool clear_results) {
193 if (autocomplete_controller_ != NULL) 193 if (autocomplete_controller_ != NULL)
194 autocomplete_controller_->Stop(clear_results); 194 autocomplete_controller_->Stop(clear_results);
195 } 195 }
196 196
197 void AutocompleteControllerAndroid::ResetSession(JNIEnv* env, jobject obj) { 197 void AutocompleteControllerAndroid::ResetSession(JNIEnv* env, jobject obj) {
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return; 556 return;
557 557
558 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. 558 // ZeroSuggestPrefetcher deletes itself after it's done prefetching.
559 new ZeroSuggestPrefetcher(profile); 559 new ZeroSuggestPrefetcher(profile);
560 } 560 }
561 561
562 // Register native methods 562 // Register native methods
563 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { 563 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) {
564 return RegisterNativesImpl(env); 564 return RegisterNativesImpl(env);
565 } 565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698