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