| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ | 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // ID used in creating URLFetcher for Contextual Search results. | 55 // ID used in creating URLFetcher for Contextual Search results. |
| 56 static const int kContextualSearchURLFetcherID; | 56 static const int kContextualSearchURLFetcherID; |
| 57 | 57 |
| 58 // Constructs a delegate that will always call back to the given callbacks | 58 // Constructs a delegate that will always call back to the given callbacks |
| 59 // when search term resolution or surrounding text responses are available. | 59 // when search term resolution or surrounding text responses are available. |
| 60 ContextualSearchDelegate( | 60 ContextualSearchDelegate( |
| 61 net::URLRequestContextGetter* url_request_context, | 61 net::URLRequestContextGetter* url_request_context, |
| 62 TemplateURLService* template_url_service, | 62 TemplateURLService* template_url_service, |
| 63 const SearchTermResolutionCallback& search_term_callback, | 63 const SearchTermResolutionCallback& search_term_callback, |
| 64 const SurroundingTextCallback& surrounding_callback, | 64 const SurroundingTextCallback& surrounding_callback, |
| 65 const IcingCallback& icing_callback); | 65 const IcingCallback& icing_callback, |
| 66 std::unique_ptr<ContextualSearchFieldTrial> field_trial); |
| 66 ~ContextualSearchDelegate() override; | 67 ~ContextualSearchDelegate() override; |
| 67 | 68 |
| 68 // Gathers surrounding text and starts an asynchronous search term resolution | 69 // Gathers surrounding text and starts an asynchronous search term resolution |
| 69 // request. The "search term" is the best query to issue for a section of text | 70 // request. The "search term" is the best query to issue for a section of text |
| 70 // in the context of a web page. When the response is available the callback | 71 // in the context of a web page. When the response is available the callback |
| 71 // specified in the constructor is run. | 72 // specified in the constructor is run. |
| 72 void StartSearchTermResolutionRequest( | 73 void StartSearchTermResolutionRequest( |
| 73 const std::string& selection, | 74 const std::string& selection, |
| 74 bool use_resolved_search_term, | 75 bool use_resolved_search_term, |
| 75 content::WebContents* web_contents, | 76 content::WebContents* web_contents, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 SurroundingTextNoAfterText); | 108 SurroundingTextNoAfterText); |
| 108 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, | 109 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, |
| 109 ExtractMentionsStartEnd); | 110 ExtractMentionsStartEnd); |
| 110 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, | 111 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, |
| 111 SurroundingTextForIcing); | 112 SurroundingTextForIcing); |
| 112 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, | 113 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, |
| 113 SurroundingTextForIcingNegativeLimit); | 114 SurroundingTextForIcingNegativeLimit); |
| 114 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, | 115 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, |
| 115 DecodeSearchTermFromJsonResponse); | 116 DecodeSearchTermFromJsonResponse); |
| 116 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, DecodeStringMentions); | 117 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, DecodeStringMentions); |
| 118 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, |
| 119 ResponseWithNowOnTapData); |
| 117 | 120 |
| 118 // net::URLFetcherDelegate: | 121 // net::URLFetcherDelegate: |
| 119 void OnURLFetchComplete(const net::URLFetcher* source) override; | 122 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 120 | 123 |
| 121 // Builds the ContextualSearchContext in the current context from | 124 // Builds the ContextualSearchContext in the current context from |
| 122 // the given parameters. | 125 // the given parameters. |
| 123 void BuildContext(const std::string& selection, | 126 void BuildContext(const std::string& selection, |
| 124 bool use_resolved_search_term, | 127 bool use_resolved_search_term, |
| 125 content::WebContents* web_contents, | 128 content::WebContents* web_contents, |
| 126 bool may_send_base_page_url); | 129 bool may_send_base_page_url); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 std::string* context_language, | 198 std::string* context_language, |
| 196 std::string* thumbnail_url, | 199 std::string* thumbnail_url, |
| 197 std::string* caption); | 200 std::string* caption); |
| 198 | 201 |
| 199 // Extracts the start and end location from a mentions list, and sets the | 202 // Extracts the start and end location from a mentions list, and sets the |
| 200 // integers referenced by |startResult| and |endResult|. | 203 // integers referenced by |startResult| and |endResult|. |
| 201 void ExtractMentionsStartEnd(const base::ListValue& mentions_list, | 204 void ExtractMentionsStartEnd(const base::ListValue& mentions_list, |
| 202 int* startResult, | 205 int* startResult, |
| 203 int* endResult); | 206 int* endResult); |
| 204 | 207 |
| 208 // Decodes the Now on Tap response from the given dictionary, and returns |
| 209 // whether both the subtitle and thumbnail were present. |
| 210 void DecodeNowOnTapResponse(const base::DictionaryValue& dict, |
| 211 std::string* subtitle, |
| 212 std::string* thumbnail); |
| 213 |
| 205 // Generates a subset of the given surrounding_text string, for Icing | 214 // Generates a subset of the given surrounding_text string, for Icing |
| 206 // integration. | 215 // integration. |
| 207 // |surrounding_text| the entire text context that contains the selection. | 216 // |surrounding_text| the entire text context that contains the selection. |
| 208 // |padding_each_side| the number of characters of padding desired on each | 217 // |padding_each_side| the number of characters of padding desired on each |
| 209 // side of the selection (negative values treated as 0). | 218 // side of the selection (negative values treated as 0). |
| 210 // |start| the start offset of the selection, updated to reflect the new | 219 // |start| the start offset of the selection, updated to reflect the new |
| 211 // position | 220 // position |
| 212 // of the selection in the function result. | 221 // of the selection in the function result. |
| 213 // |end| the end offset of the selection, updated to reflect the new position | 222 // |end| the end offset of the selection, updated to reflect the new position |
| 214 // of the selection in the function result. | 223 // of the selection in the function result. |
| 215 // |return| the trimmed surrounding text with selection at the | 224 // |return| the trimmed surrounding text with selection at the |
| 216 // updated start/end offsets. | 225 // updated start/end offsets. |
| 217 base::string16 SurroundingTextForIcing(const base::string16& surrounding_text, | 226 base::string16 SurroundingTextForIcing(const base::string16& surrounding_text, |
| 218 int padding_each_side, | 227 int padding_each_side, |
| 219 size_t* start, | 228 size_t* start, |
| 220 size_t* end); | 229 size_t* end); |
| 221 | 230 |
| 222 // The current request in progress, or NULL. | 231 // The current request in progress, or NULL. |
| 223 std::unique_ptr<net::URLFetcher> search_term_fetcher_; | 232 std::unique_ptr<net::URLFetcher> search_term_fetcher_; |
| 224 | 233 |
| 225 // Holds the URL request context. Not owned. | 234 // Holds the URL request context. Not owned. |
| 226 net::URLRequestContextGetter* url_request_context_; | 235 net::URLRequestContextGetter* url_request_context_; |
| 227 | 236 |
| 228 // Holds the TemplateURLService. Not owned. | 237 // Holds the TemplateURLService. Not owned. |
| 229 TemplateURLService* template_url_service_; | 238 TemplateURLService* template_url_service_; |
| 230 | 239 |
| 231 // The field trial helper instance, always set up by the constructor. | |
| 232 std::unique_ptr<ContextualSearchFieldTrial> field_trial_; | |
| 233 | |
| 234 // The callback for notifications of completed URL fetches. | 240 // The callback for notifications of completed URL fetches. |
| 235 SearchTermResolutionCallback search_term_callback_; | 241 SearchTermResolutionCallback search_term_callback_; |
| 236 | 242 |
| 237 // The callback for notifications of surrounding text being available. | 243 // The callback for notifications of surrounding text being available. |
| 238 SurroundingTextCallback surrounding_callback_; | 244 SurroundingTextCallback surrounding_callback_; |
| 239 | 245 |
| 240 // The callback for notifications of Icing selection being available. | 246 // The callback for notifications of Icing selection being available. |
| 241 IcingCallback icing_callback_; | 247 IcingCallback icing_callback_; |
| 242 | 248 |
| 249 // The field trial helper instance, always set up by the constructor. |
| 250 std::unique_ptr<ContextualSearchFieldTrial> field_trial_; |
| 251 |
| 243 // Used to hold the context until an upcoming search term request is started. | 252 // Used to hold the context until an upcoming search term request is started. |
| 244 std::unique_ptr<ContextualSearchContext> context_; | 253 std::unique_ptr<ContextualSearchContext> context_; |
| 245 | 254 |
| 246 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate); | 255 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate); |
| 247 }; | 256 }; |
| 248 | 257 |
| 249 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ | 258 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| OLD | NEW |