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

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

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 6 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 | Annotate | Revision Log
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 29 matching lines...) Expand all
40 #include "jni/AutocompleteController_jni.h" 40 #include "jni/AutocompleteController_jni.h"
41 #include "net/base/escape.h" 41 #include "net/base/escape.h"
42 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
44 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
45 45
46 using base::android::AttachCurrentThread; 46 using base::android::AttachCurrentThread;
47 using base::android::ConvertJavaStringToUTF16; 47 using base::android::ConvertJavaStringToUTF16;
48 using base::android::ConvertUTF8ToJavaString; 48 using base::android::ConvertUTF8ToJavaString;
49 using base::android::ConvertUTF16ToJavaString; 49 using base::android::ConvertUTF16ToJavaString;
50 using metrics::OmniboxEventProto;
50 51
51 namespace { 52 namespace {
52 53
53 const int kAndroidAutocompleteProviders = 54 const int kAndroidAutocompleteProviders =
54 AutocompleteClassifier::kDefaultOmniboxProviders; 55 AutocompleteClassifier::kDefaultOmniboxProviders;
55 56
56 /** 57 /**
57 * A prefetcher class responsible for triggering zero suggest prefetch. 58 * A prefetcher class responsible for triggering zero suggest prefetch.
58 * The prefetch occurs as a side-effect of calling StartZeroSuggest() on 59 * The prefetch occurs as a side-effect of calling StartZeroSuggest() on
59 * the AutocompleteController object. 60 * the AutocompleteController object.
(...skipping 18 matching lines...) Expand all
78 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { 79 AutocompleteProvider::TYPE_ZERO_SUGGEST)) {
79 // Creating an arbitrary fake_request_source to avoid passing in an invalid 80 // Creating an arbitrary fake_request_source to avoid passing in an invalid
80 // AutocompleteInput object. 81 // AutocompleteInput object.
81 base::string16 fake_request_source(base::ASCIIToUTF16( 82 base::string16 fake_request_source(base::ASCIIToUTF16(
82 "http://www.foobarbazblah.com")); 83 "http://www.foobarbazblah.com"));
83 controller_->StartZeroSuggest(AutocompleteInput( 84 controller_->StartZeroSuggest(AutocompleteInput(
84 fake_request_source, 85 fake_request_source,
85 base::string16::npos, 86 base::string16::npos,
86 base::string16(), 87 base::string16(),
87 GURL(fake_request_source), 88 GURL(fake_request_source),
88 AutocompleteInput::INVALID_SPEC, 89 OmniboxEventProto::INVALID_SPEC,
89 false, 90 false,
90 false, 91 false,
91 true, 92 true,
92 true)); 93 true));
93 // 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
94 // give up if the results haven't been received. 95 // give up if the results haven't been received.
95 expire_timer_.Start(FROM_HERE, 96 expire_timer_.Start(FROM_HERE,
96 base::TimeDelta::FromMilliseconds(10000), 97 base::TimeDelta::FromMilliseconds(10000),
97 this, &ZeroSuggestPrefetcher::SelfDestruct); 98 this, &ZeroSuggestPrefetcher::SelfDestruct);
98 } 99 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (!autocomplete_controller_) 132 if (!autocomplete_controller_)
132 return; 133 return;
133 134
134 base::string16 desired_tld; 135 base::string16 desired_tld;
135 GURL current_url; 136 GURL current_url;
136 if (j_current_url != NULL) 137 if (j_current_url != NULL)
137 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url)); 138 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url));
138 if (j_desired_tld != NULL) 139 if (j_desired_tld != NULL)
139 desired_tld = ConvertJavaStringToUTF16(env, j_desired_tld); 140 desired_tld = ConvertJavaStringToUTF16(env, j_desired_tld);
140 base::string16 text = ConvertJavaStringToUTF16(env, j_text); 141 base::string16 text = ConvertJavaStringToUTF16(env, j_text);
141 AutocompleteInput::PageClassification page_classification = 142 OmniboxEventProto::PageClassification page_classification =
142 AutocompleteInput::OTHER; 143 OmniboxEventProto::OTHER;
143 input_ = AutocompleteInput(text, 144 input_ = AutocompleteInput(text,
144 base::string16::npos, 145 base::string16::npos,
145 desired_tld, 146 desired_tld,
146 current_url, 147 current_url,
147 page_classification, 148 page_classification,
148 prevent_inline_autocomplete, 149 prevent_inline_autocomplete,
149 prefer_keyword, 150 prefer_keyword,
150 allow_exact_keyword_match, 151 allow_exact_keyword_match,
151 want_asynchronous_matches); 152 want_asynchronous_matches);
152 autocomplete_controller_->Start(input_); 153 autocomplete_controller_->Start(input_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 JNIEnv* env, 202 JNIEnv* env,
202 jobject obj, 203 jobject obj,
203 jint selected_index, 204 jint selected_index,
204 jstring j_current_url, 205 jstring j_current_url,
205 jboolean is_query_in_omnibox, 206 jboolean is_query_in_omnibox,
206 jboolean focused_from_fakebox, 207 jboolean focused_from_fakebox,
207 jlong elapsed_time_since_first_modified, 208 jlong elapsed_time_since_first_modified,
208 jobject j_web_contents) { 209 jobject j_web_contents) {
209 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); 210 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url);
210 const GURL current_url = GURL(url); 211 const GURL current_url = GURL(url);
211 AutocompleteInput::PageClassification current_page_classification = 212 OmniboxEventProto::PageClassification current_page_classification =
212 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox); 213 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox);
213 const base::TimeTicks& now(base::TimeTicks::Now()); 214 const base::TimeTicks& now(base::TimeTicks::Now());
214 content::WebContents* web_contents = 215 content::WebContents* web_contents =
215 content::WebContents::FromJavaWebContents(j_web_contents); 216 content::WebContents::FromJavaWebContents(j_web_contents);
216 217
217 OmniboxLog log( 218 OmniboxLog log(
218 input_.text(), 219 input_.text(),
219 false, /* don't know */ 220 false, /* don't know */
220 input_.type(), 221 input_.type(),
221 true, 222 true,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ConvertUTF16ToJavaString(env, inline_autocomplete_text); 363 ConvertUTF16ToJavaString(env, inline_autocomplete_text);
363 jlong j_autocomplete_result = 364 jlong j_autocomplete_result =
364 reinterpret_cast<intptr_t>(&(autocomplete_result)); 365 reinterpret_cast<intptr_t>(&(autocomplete_result));
365 Java_AutocompleteController_onSuggestionsReceived(env, 366 Java_AutocompleteController_onSuggestionsReceived(env,
366 java_bridge.obj(), 367 java_bridge.obj(),
367 suggestion_list_obj.obj(), 368 suggestion_list_obj.obj(),
368 inline_text.obj(), 369 inline_text.obj(),
369 j_autocomplete_result); 370 j_autocomplete_result);
370 } 371 }
371 372
372 AutocompleteInput::PageClassification 373 OmniboxEventProto::PageClassification
373 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, 374 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl,
374 bool is_query_in_omnibox, 375 bool is_query_in_omnibox,
375 bool focused_from_fakebox) const { 376 bool focused_from_fakebox) const {
376 if (!gurl.is_valid()) 377 if (!gurl.is_valid())
377 return AutocompleteInput::INVALID_SPEC; 378 return OmniboxEventProto::INVALID_SPEC;
378 379
379 const std::string& url = gurl.spec(); 380 const std::string& url = gurl.spec();
380 381
381 if (gurl.SchemeIs(content::kChromeUIScheme) && 382 if (gurl.SchemeIs(content::kChromeUIScheme) &&
382 gurl.host() == chrome::kChromeUINewTabHost) { 383 gurl.host() == chrome::kChromeUINewTabHost) {
383 return AutocompleteInput::NTP; 384 return OmniboxEventProto::NTP;
384 } 385 }
385 386
386 if (url == chrome::kChromeUINativeNewTabURL) { 387 if (url == chrome::kChromeUINativeNewTabURL) {
387 return focused_from_fakebox ? 388 return focused_from_fakebox ?
388 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : 389 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS :
389 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; 390 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
390 } 391 }
391 392
392 if (url == url::kAboutBlankURL) 393 if (url == url::kAboutBlankURL)
393 return AutocompleteInput::BLANK; 394 return OmniboxEventProto::BLANK;
394 395
395 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) 396 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage))
396 return AutocompleteInput::HOME_PAGE; 397 return OmniboxEventProto::HOME_PAGE;
397 398
398 if (is_query_in_omnibox) 399 if (is_query_in_omnibox)
399 return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; 400 return OmniboxEventProto::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
400 401
401 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> 402 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)->
402 IsSearchResultsPageFromDefaultSearchProvider(gurl); 403 IsSearchResultsPageFromDefaultSearchProvider(gurl);
403 if (is_search_url) 404 if (is_search_url)
404 return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; 405 return OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
405 406
406 return AutocompleteInput::OTHER; 407 return OmniboxEventProto::OTHER;
407 } 408 }
408 409
409 ScopedJavaLocalRef<jobject> 410 ScopedJavaLocalRef<jobject>
410 AutocompleteControllerAndroid::BuildOmniboxSuggestion( 411 AutocompleteControllerAndroid::BuildOmniboxSuggestion(
411 JNIEnv* env, 412 JNIEnv* env,
412 const AutocompleteMatch& match) { 413 const AutocompleteMatch& match) {
413 ScopedJavaLocalRef<jstring> contents = 414 ScopedJavaLocalRef<jstring> contents =
414 ConvertUTF16ToJavaString(env, match.contents); 415 ConvertUTF16ToJavaString(env, match.contents);
415 ScopedJavaLocalRef<jstring> description = 416 ScopedJavaLocalRef<jstring> description =
416 ConvertUTF16ToJavaString(env, match.description); 417 ConvertUTF16ToJavaString(env, match.description);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 JNIEnv* env, jclass clazz, jstring jquery) { 496 JNIEnv* env, jclass clazz, jstring jquery) {
496 Profile* profile = ProfileManager::GetActiveUserProfile(); 497 Profile* profile = ProfileManager::GetActiveUserProfile();
497 if (!profile) 498 if (!profile)
498 return NULL; 499 return NULL;
499 AutocompleteMatch match; 500 AutocompleteMatch match;
500 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); 501 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery));
501 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( 502 AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
502 query_string, 503 query_string,
503 false, 504 false,
504 false, 505 false,
505 AutocompleteInput::INVALID_SPEC, 506 OmniboxEventProto::INVALID_SPEC,
506 &match, 507 &match,
507 NULL); 508 NULL);
508 if (!match.destination_url.is_valid()) 509 if (!match.destination_url.is_valid())
509 return NULL; 510 return NULL;
510 511
511 // Only return a URL if the match is a URL type. 512 // Only return a URL if the match is a URL type.
512 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && 513 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED &&
513 match.type != AutocompleteMatchType::HISTORY_URL && 514 match.type != AutocompleteMatchType::HISTORY_URL &&
514 match.type != AutocompleteMatchType::NAVSUGGEST) 515 match.type != AutocompleteMatchType::NAVSUGGEST)
515 return NULL; 516 return NULL;
(...skipping 11 matching lines...) Expand all
527 return; 528 return;
528 529
529 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. 530 // ZeroSuggestPrefetcher deletes itself after it's done prefetching.
530 new ZeroSuggestPrefetcher(profile); 531 new ZeroSuggestPrefetcher(profile);
531 } 532 }
532 533
533 // Register native methods 534 // Register native methods
534 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { 535 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) {
535 return RegisterNativesImpl(env); 536 return RegisterNativesImpl(env);
536 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698