Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / android / omnibox / autocomplete_controller_android.h
blob8ecd258eabc36d018cbc9fcca598dc4f9132b018
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_
8 #include <string>
10 #include "base/android/jni_weak_ref.h"
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h"
14 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "components/metrics/proto/omnibox_event.pb.h"
17 #include "components/omnibox/browser/autocomplete_controller_delegate.h"
18 #include "components/omnibox/browser/autocomplete_input.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h"
23 class AutocompleteController;
24 struct AutocompleteMatch;
25 class AutocompleteResult;
26 class Profile;
27 class Tab;
29 // The native part of the Java AutocompleteController class.
30 class AutocompleteControllerAndroid : public AutocompleteControllerDelegate,
31 public KeyedService {
32 public:
33 explicit AutocompleteControllerAndroid(Profile* profile);
35 // Methods that forward to AutocompleteController:
36 void Start(JNIEnv* env,
37 jobject obj,
38 jstring j_text,
39 jint j_cursor_pos,
40 jstring j_desired_tld,
41 jstring j_current_url,
42 bool prevent_inline_autocomplete,
43 bool prefer_keyword,
44 bool allow_exact_keyword_match,
45 bool best_match_only);
46 base::android::ScopedJavaLocalRef<jobject> Classify(JNIEnv* env,
47 jobject obj,
48 jstring j_text);
49 void OnOmniboxFocused(JNIEnv* env,
50 jobject obj,
51 jstring j_omnibox_text,
52 jstring j_current_url,
53 jboolean is_query_in_omnibox,
54 jboolean focused_from_fakebox);
55 void Stop(JNIEnv* env, jobject obj, bool clear_result);
56 void ResetSession(JNIEnv* env, jobject obj);
57 void OnSuggestionSelected(JNIEnv* env,
58 jobject obj,
59 jint selected_index,
60 jstring j_current_url,
61 jboolean is_query_in_omnibox,
62 jboolean focused_from_fakebox,
63 jlong elapsed_time_since_first_modified,
64 jobject j_web_contents);
65 void DeleteSuggestion(JNIEnv* env, jobject obj, int selected_index);
66 base::android::ScopedJavaLocalRef<jstring>
67 UpdateMatchDestinationURLWithQueryFormulationTime(
68 JNIEnv* env,
69 jobject obj,
70 jint selected_index,
71 jlong elapsed_time_since_input_change);
73 // KeyedService:
74 void Shutdown() override;
76 class Factory : public BrowserContextKeyedServiceFactory {
77 public:
78 static AutocompleteControllerAndroid* GetForProfile(Profile* profile,
79 JNIEnv* env,
80 jobject obj);
82 static Factory* GetInstance();
84 protected:
85 content::BrowserContext* GetBrowserContextToUse(
86 content::BrowserContext* context) const override;
88 private:
89 friend struct DefaultSingletonTraits<Factory>;
91 Factory();
92 ~Factory() override;
94 // BrowserContextKeyedServiceFactory
95 KeyedService* BuildServiceInstanceFor(
96 content::BrowserContext* profile) const override;
99 private:
100 ~AutocompleteControllerAndroid() override;
101 void InitJNI(JNIEnv* env, jobject obj);
103 // AutocompleteControllerDelegate implementation.
104 void OnResultChanged(bool default_match_changed) override;
106 // Notifies the Java AutocompleteController that suggestions were received
107 // based on the text the user typed in last.
108 void NotifySuggestionsReceived(
109 const AutocompleteResult& autocomplete_result);
111 // Classifies the type of page we are on.
112 metrics::OmniboxEventProto::PageClassification ClassifyPage(
113 const GURL& gurl,
114 bool is_query_in_omnibox,
115 bool focused_from_fakebox) const;
117 base::android::ScopedJavaLocalRef<jobject> BuildOmniboxSuggestion(
118 JNIEnv* env, const AutocompleteMatch& match);
120 // Converts destination_url (which is in its canonical form or punycode) to a
121 // user-friendly URL by looking up accept languages of the current profile.
122 // e.g. http://xn--6q8b.kr/ --> 한.kr
123 base::string16 FormatURLUsingAcceptLanguages(GURL url);
125 // A helper method for fetching the top synchronous autocomplete result.
126 // The |prevent_inline_autocomplete| flag is passed to the AutocompleteInput
127 // object, see documentation there for its description.
128 base::android::ScopedJavaLocalRef<jobject> GetTopSynchronousResult(
129 JNIEnv* env,
130 jobject obj,
131 jstring j_text,
132 bool prevent_inline_autocomplete);
134 scoped_ptr<AutocompleteController> autocomplete_controller_;
136 // Last input we sent to the autocomplete controller.
137 AutocompleteInput input_;
139 // Whether we're currently inside a call to Start() that's called
140 // from GetTopSynchronousResult().
141 bool inside_synchronous_start_;
143 JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_;
144 Profile* profile_;
146 DISALLOW_COPY_AND_ASSIGN(AutocompleteControllerAndroid);
149 // Registers the LocationBar native method.
150 bool RegisterAutocompleteControllerAndroid(JNIEnv* env);
152 #endif // CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_