Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / contextualsearch / contextual_search_manager.h
blobf9e76039d6d8cfc68e7418b4257ca3326c1c472b
1 // Copyright 2015 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_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_
6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_
8 #include "base/android/jni_android.h"
9 #include "base/task/cancelable_task_tracker.h"
10 #include "chrome/browser/android/contextualsearch/contextual_search_context.h"
11 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h"
13 // Manages the native extraction and request logic for Contextual Search,
14 // and interacts with the Java ContextualSearchManager for UX.
15 // Most of the work is done by the associated ContextualSearchDelegate.
16 class ContextualSearchManager {
17 public:
18 // Constructs a native manager associated with the Java manager.
19 ContextualSearchManager(JNIEnv* env, jobject obj);
20 virtual ~ContextualSearchManager();
22 // Called by the Java ContextualSearchManager when it is being destroyed.
23 void Destroy(JNIEnv* env, jobject obj);
25 // Starts the request to get the search terms to use for the given selection,
26 // by accessing our server with the content of the page (from the given
27 // content view core object).
28 // Any outstanding server requests are canceled.
29 // When the server responds with the search term, the Java object is notified
30 // by
31 // calling OnSearchTermResolutionResponse().
32 void StartSearchTermResolutionRequest(
33 JNIEnv* env,
34 jobject obj,
35 jstring j_selection,
36 jboolean j_use_resolved_search_term,
37 jobject j_base_content_view_core,
38 jboolean j_may_send_base_page_url);
40 // Gathers the surrounding text around the selection and saves it locally.
41 // Does not send a search term resolution request to the server.
42 void GatherSurroundingText(JNIEnv* env,
43 jobject obj,
44 jstring j_selection,
45 jboolean j_use_resolved_search_term,
46 jobject j_base_content_view_core,
47 jboolean j_may_send_base_page_url);
49 private:
50 // TODO(donnd): encapsulate these response parameters?
51 void OnSearchTermResolutionResponse(bool is_invalid,
52 int response_code,
53 const std::string& search_term,
54 const std::string& display_text,
55 const std::string& alternate_term,
56 bool prevent_preload,
57 int selection_start_adjust,
58 int selection_end_adjust);
60 // Calls back to Java with the surrounding text to be displayed.
61 void OnSurroundingTextAvailable(const std::string& before_text,
62 const std::string& after_text);
64 // Calls back to Java with notification for Icing selection.
65 void OnIcingSelectionAvailable(const std::string& encoding,
66 const base::string16& surrounding_text,
67 size_t start_offset,
68 size_t end_offset);
70 // Our global reference to the Java ContextualSearchManager.
71 base::android::ScopedJavaGlobalRef<jobject> java_manager_;
73 // The delegate we're using the do the real work.
74 scoped_ptr<ContextualSearchDelegate> delegate_;
76 DISALLOW_COPY_AND_ASSIGN(ContextualSearchManager);
79 bool RegisterContextualSearchManager(JNIEnv* env);
81 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_