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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_delegate.h

Issue 1205033005: Adds selection expansion support for Contextual Search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed java tests Created 5 years, 5 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 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 "base/callback.h" 8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/values.h"
12 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" 13 #include "chrome/browser/android/contextualsearch/contextual_search_context.h"
13 #include "content/public/browser/android/content_view_core.h" 14 #include "content/public/browser/android/content_view_core.h"
14 #include "net/url_request/url_fetcher_delegate.h" 15 #include "net/url_request/url_fetcher_delegate.h"
15 16
16 namespace net { 17 namespace net {
17 class URLRequestContextGetter; 18 class URLRequestContextGetter;
18 } // namespace net 19 } // namespace net
19 20
20 class Profile; 21 class Profile;
21 class TemplateURLService; 22 class TemplateURLService;
22 23
23 // Handles tasks for the ContextualSearchManager in a separable and testable 24 // Handles tasks for the ContextualSearchManager in a separable and testable
24 // way, without the complication of being connected to a Java object. 25 // way, without the complication of being connected to a Java object.
25 class ContextualSearchDelegate 26 class ContextualSearchDelegate
26 : public net::URLFetcherDelegate, 27 : public net::URLFetcherDelegate,
27 public base::SupportsWeakPtr<ContextualSearchDelegate> { 28 public base::SupportsWeakPtr<ContextualSearchDelegate> {
28 public: 29 public:
29 typedef base::Callback< 30 typedef base::Callback<void(bool,
30 void(bool, int, const std::string&, const std::string&, 31 int,
31 const std::string&, bool)> 32 const std::string&,
32 SearchTermResolutionCallback; 33 const std::string&,
34 const std::string&,
35 bool,
36 int,
37 int)> SearchTermResolutionCallback;
33 typedef base::Callback< 38 typedef base::Callback<
34 void(const std::string&, const std::string&)> SurroundingTextCallback; 39 void(const std::string&, const std::string&)> SurroundingTextCallback;
35 typedef base::Callback< 40 typedef base::Callback<
36 void(const base::string16&, int, int)> 41 void(const base::string16&, int, int)>
37 HandleSurroundingsCallback; 42 HandleSurroundingsCallback;
38 typedef base::Callback< 43 typedef base::Callback<
39 void(const std::string&, const base::string16&, size_t, size_t)> 44 void(const std::string&, const base::string16&, size_t, size_t)>
40 IcingCallback; 45 IcingCallback;
41 46
42 // ID used in creating URLFetcher for Contextual Search results. 47 // ID used in creating URLFetcher for Contextual Search results.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 83 }
79 84
80 private: 85 private:
81 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 86 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
82 SurroundingTextHighMaximum); 87 SurroundingTextHighMaximum);
83 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 88 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
84 SurroundingTextLowMaximum); 89 SurroundingTextLowMaximum);
85 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 90 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
86 SurroundingTextNoBeforeText); 91 SurroundingTextNoBeforeText);
87 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 92 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
93 ExtractMentionsStartEnd);
94 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
88 SurroundingTextForIcing); 95 SurroundingTextForIcing);
89 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 96 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
90 SurroundingTextForIcingNegativeLimit); 97 SurroundingTextForIcingNegativeLimit);
91 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, 98 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
92 DecodeSearchTermsFromJsonResponse); 99 DecodeSearchTermsFromJsonResponse);
93 100
94 // net::URLFetcherDelegate: 101 // net::URLFetcherDelegate:
95 void OnURLFetchComplete(const net::URLFetcher* source) override; 102 void OnURLFetchComplete(const net::URLFetcher* source) override;
96 103
97 // Builds the search term resolution request URL from the current context. 104 // Builds the search term resolution request URL from the current context.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // already sending their URL browsing activity to Google. 148 // already sending their URL browsing activity to Google.
142 bool CanSendPageURL(const GURL& current_page_url, 149 bool CanSendPageURL(const GURL& current_page_url,
143 Profile* profile, 150 Profile* profile,
144 TemplateURLService* template_url_service); 151 TemplateURLService* template_url_service);
145 152
146 // Decodes the given json response string and extracts parameters. 153 // Decodes the given json response string and extracts parameters.
147 void DecodeSearchTermsFromJsonResponse(const std::string& response, 154 void DecodeSearchTermsFromJsonResponse(const std::string& response,
148 std::string* search_term, 155 std::string* search_term,
149 std::string* display_text, 156 std::string* display_text,
150 std::string* alternate_term, 157 std::string* alternate_term,
151 std::string* prevent_preload); 158 std::string* prevent_preload,
159 int* mention_start,
160 int* mention_end);
161
162 void ExtractMentionsStartEnd(const base::ListValue& mentions_list,
163 int* startResult,
164 int* endResult);
152 165
153 // Returns the surrounding size to use for the search term resolution 166 // Returns the surrounding size to use for the search term resolution
154 // request. 167 // request.
155 int GetSearchTermSurroundingSize(); 168 int GetSearchTermSurroundingSize();
156 169
157 // Returns the size of the surroundings to be sent to Icing. 170 // Returns the size of the surroundings to be sent to Icing.
158 int GetIcingSurroundingSize(); 171 int GetIcingSurroundingSize();
159 172
160 // Generates a subset of the given surrounding_text string, for Icing 173 // Generates a subset of the given surrounding_text string, for Icing
161 // integration. 174 // integration.
(...skipping 30 matching lines...) Expand all
192 // The callback for notifications of Icing selection being available. 205 // The callback for notifications of Icing selection being available.
193 IcingCallback icing_callback_; 206 IcingCallback icing_callback_;
194 207
195 // Used to hold the context until an upcoming search term request is started. 208 // Used to hold the context until an upcoming search term request is started.
196 scoped_ptr<ContextualSearchContext> context_; 209 scoped_ptr<ContextualSearchContext> context_;
197 210
198 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate); 211 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate);
199 }; 212 };
200 213
201 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ 214 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698