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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 false); | 501 false); |
502 inside_synchronous_start_ = false; | 502 inside_synchronous_start_ = false; |
503 DCHECK(autocomplete_controller_->done()); | 503 DCHECK(autocomplete_controller_->done()); |
504 const AutocompleteResult& result = autocomplete_controller_->result(); | 504 const AutocompleteResult& result = autocomplete_controller_->result(); |
505 if (result.empty()) | 505 if (result.empty()) |
506 return ScopedJavaLocalRef<jobject>(); | 506 return ScopedJavaLocalRef<jobject>(); |
507 | 507 |
508 return BuildOmniboxSuggestion(env, *result.begin()); | 508 return BuildOmniboxSuggestion(env, *result.begin()); |
509 } | 509 } |
510 | 510 |
511 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { | 511 static jlong Init(JNIEnv* env, |
| 512 const JavaParamRef<jobject>& obj, |
| 513 const JavaParamRef<jobject>& jprofile) { |
512 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 514 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
513 if (!profile) | 515 if (!profile) |
514 return 0; | 516 return 0; |
515 | 517 |
516 AutocompleteControllerAndroid* native_bridge = | 518 AutocompleteControllerAndroid* native_bridge = |
517 AutocompleteControllerAndroid::Factory::GetForProfile(profile, env, obj); | 519 AutocompleteControllerAndroid::Factory::GetForProfile(profile, env, obj); |
518 return reinterpret_cast<intptr_t>(native_bridge); | 520 return reinterpret_cast<intptr_t>(native_bridge); |
519 } | 521 } |
520 | 522 |
521 static ScopedJavaLocalRef<jstring> QualifyPartialURLQuery(JNIEnv* env, | 523 static ScopedJavaLocalRef<jstring> QualifyPartialURLQuery( |
522 jclass clazz, | 524 JNIEnv* env, |
523 jstring jquery) { | 525 const JavaParamRef<jclass>& clazz, |
| 526 const JavaParamRef<jstring>& jquery) { |
524 Profile* profile = ProfileManager::GetActiveUserProfile(); | 527 Profile* profile = ProfileManager::GetActiveUserProfile(); |
525 if (!profile) | 528 if (!profile) |
526 return ScopedJavaLocalRef<jstring>(); | 529 return ScopedJavaLocalRef<jstring>(); |
527 AutocompleteMatch match; | 530 AutocompleteMatch match; |
528 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); | 531 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); |
529 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( | 532 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( |
530 query_string, | 533 query_string, |
531 false, | 534 false, |
532 false, | 535 false, |
533 OmniboxEventProto::INVALID_SPEC, | 536 OmniboxEventProto::INVALID_SPEC, |
534 &match, | 537 &match, |
535 NULL); | 538 NULL); |
536 if (!match.destination_url.is_valid()) | 539 if (!match.destination_url.is_valid()) |
537 return ScopedJavaLocalRef<jstring>(); | 540 return ScopedJavaLocalRef<jstring>(); |
538 | 541 |
539 // Only return a URL if the match is a URL type. | 542 // Only return a URL if the match is a URL type. |
540 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && | 543 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && |
541 match.type != AutocompleteMatchType::HISTORY_URL && | 544 match.type != AutocompleteMatchType::HISTORY_URL && |
542 match.type != AutocompleteMatchType::NAVSUGGEST) | 545 match.type != AutocompleteMatchType::NAVSUGGEST) |
543 return ScopedJavaLocalRef<jstring>(); | 546 return ScopedJavaLocalRef<jstring>(); |
544 | 547 |
545 // As we are returning to Java, it is fine to call Release(). | 548 // As we are returning to Java, it is fine to call Release(). |
546 return ConvertUTF8ToJavaString(env, match.destination_url.spec()); | 549 return ConvertUTF8ToJavaString(env, match.destination_url.spec()); |
547 } | 550 } |
548 | 551 |
549 static void PrefetchZeroSuggestResults(JNIEnv* env, jclass clazz) { | 552 static void PrefetchZeroSuggestResults(JNIEnv* env, |
| 553 const JavaParamRef<jclass>& clazz) { |
550 Profile* profile = ProfileManager::GetActiveUserProfile(); | 554 Profile* profile = ProfileManager::GetActiveUserProfile(); |
551 if (!profile) | 555 if (!profile) |
552 return; | 556 return; |
553 | 557 |
554 if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) | 558 if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) |
555 return; | 559 return; |
556 | 560 |
557 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 561 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
558 new ZeroSuggestPrefetcher(profile); | 562 new ZeroSuggestPrefetcher(profile); |
559 } | 563 } |
560 | 564 |
561 // Register native methods | 565 // Register native methods |
562 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 566 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
563 return RegisterNativesImpl(env); | 567 return RegisterNativesImpl(env); |
564 } | 568 } |
OLD | NEW |