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

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

Issue 1288183004: jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some newlines for readability Created 5 years, 4 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 jstring QualifyPartialURLQuery( 524 static ScopedJavaLocalRef<jstring> QualifyPartialURLQuery(JNIEnv* env,
525 JNIEnv* env, jclass clazz, jstring jquery) { 525 jclass clazz,
526 jstring jquery) {
526 Profile* profile = ProfileManager::GetActiveUserProfile(); 527 Profile* profile = ProfileManager::GetActiveUserProfile();
527 if (!profile) 528 if (!profile)
528 return NULL; 529 return ScopedJavaLocalRef<jstring>();
529 AutocompleteMatch match; 530 AutocompleteMatch match;
530 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); 531 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery));
531 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( 532 AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
532 query_string, 533 query_string,
533 false, 534 false,
534 false, 535 false,
535 OmniboxEventProto::INVALID_SPEC, 536 OmniboxEventProto::INVALID_SPEC,
536 &match, 537 &match,
537 NULL); 538 NULL);
538 if (!match.destination_url.is_valid()) 539 if (!match.destination_url.is_valid())
539 return NULL; 540 return ScopedJavaLocalRef<jstring>();
540 541
541 // Only return a URL if the match is a URL type. 542 // Only return a URL if the match is a URL type.
542 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && 543 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED &&
543 match.type != AutocompleteMatchType::HISTORY_URL && 544 match.type != AutocompleteMatchType::HISTORY_URL &&
544 match.type != AutocompleteMatchType::NAVSUGGEST) 545 match.type != AutocompleteMatchType::NAVSUGGEST)
545 return NULL; 546 return ScopedJavaLocalRef<jstring>();
546 547
547 // 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().
548 return ConvertUTF8ToJavaString(env, match.destination_url.spec()).Release(); 549 return ConvertUTF8ToJavaString(env, match.destination_url.spec());
549 } 550 }
550 551
551 static void PrefetchZeroSuggestResults(JNIEnv* env, jclass clazz) { 552 static void PrefetchZeroSuggestResults(JNIEnv* env, jclass clazz) {
552 Profile* profile = ProfileManager::GetActiveUserProfile(); 553 Profile* profile = ProfileManager::GetActiveUserProfile();
553 if (!profile) 554 if (!profile)
554 return; 555 return;
555 556
556 if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial()) 557 if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial())
557 return; 558 return;
558 559
559 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. 560 // ZeroSuggestPrefetcher deletes itself after it's done prefetching.
560 new ZeroSuggestPrefetcher(profile); 561 new ZeroSuggestPrefetcher(profile);
561 } 562 }
562 563
563 // Register native methods 564 // Register native methods
564 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { 565 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) {
565 return RegisterNativesImpl(env); 566 return RegisterNativesImpl(env);
566 } 567 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698