OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/search/common/webservice_search_provider.h" | 5 #include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "chrome/browser/search/search.h" |
11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 namespace app_list { | 15 namespace app_list { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const int kWebserviceQueryThrottleIntrevalInMs = 100; | 19 const int kWebserviceQueryThrottleIntrevalInMs = 100; |
| 20 const size_t kMinimumQueryLength = 3u; |
19 | 21 |
20 } // namespace | 22 } // namespace |
21 | 23 |
22 WebserviceSearchProvider::WebserviceSearchProvider() : use_throttling_(true) {} | 24 WebserviceSearchProvider::WebserviceSearchProvider(Profile* profile) |
| 25 : profile_(profile), use_throttling_(true) {} |
23 | 26 |
24 WebserviceSearchProvider::~WebserviceSearchProvider() {} | 27 WebserviceSearchProvider::~WebserviceSearchProvider() {} |
25 | 28 |
26 void WebserviceSearchProvider::StartThrottledQuery( | 29 void WebserviceSearchProvider::StartThrottledQuery( |
27 const base::Closure& start_query) { | 30 const base::Closure& start_query) { |
28 base::TimeDelta interval = | 31 base::TimeDelta interval = |
29 base::TimeDelta::FromMilliseconds(kWebserviceQueryThrottleIntrevalInMs); | 32 base::TimeDelta::FromMilliseconds(kWebserviceQueryThrottleIntrevalInMs); |
30 if (!use_throttling_ || base::Time::Now() - last_keytyped_ > interval) { | 33 if (!use_throttling_ || base::Time::Now() - last_keytyped_ > interval) { |
31 query_throttler_.Stop(); | 34 query_throttler_.Stop(); |
32 start_query.Run(); | 35 start_query.Run(); |
33 } else { | 36 } else { |
34 query_throttler_.Start(FROM_HERE, interval, start_query); | 37 query_throttler_.Start(FROM_HERE, interval, start_query); |
35 } | 38 } |
36 last_keytyped_ = base::Time::Now(); | 39 last_keytyped_ = base::Time::Now(); |
37 } | 40 } |
38 | 41 |
| 42 bool WebserviceSearchProvider::IsValidQuery(const string16& query) { |
| 43 // If |query| contains sensitive data, bail out and do not create the place |
| 44 // holder "search-web-store" result. |
| 45 if (IsSensitiveInput(query) || |
| 46 (query.size() < kMinimumQueryLength) || |
| 47 !chrome::IsSuggestPrefEnabled(profile_)) { |
| 48 return false; |
| 49 } |
| 50 |
| 51 return true; |
| 52 } |
| 53 |
39 // Returns whether or not the user's input string, |query|, might contain any | 54 // Returns whether or not the user's input string, |query|, might contain any |
40 // sensitive information, based purely on its value and not where it came from. | 55 // sensitive information, based purely on its value and not where it came from. |
41 bool WebserviceSearchProvider::IsSensitiveInput(const string16& query) { | 56 bool WebserviceSearchProvider::IsSensitiveInput(const string16& query) { |
42 const GURL query_as_url(query); | 57 const GURL query_as_url(query); |
43 if (!query_as_url.is_valid()) | 58 if (!query_as_url.is_valid()) |
44 return false; | 59 return false; |
45 | 60 |
46 // The input can be interpreted as a URL. Check to see if it is potentially | 61 // The input can be interpreted as a URL. Check to see if it is potentially |
47 // sensitive. (Code shamelessly copied from search_provider.cc's | 62 // sensitive. (Code shamelessly copied from search_provider.cc's |
48 // IsQuerySuitableForSuggest function.) | 63 // IsQuerySuitableForSuggest function.) |
(...skipping 23 matching lines...) Expand all Loading... |
72 // specific path may reveal private information. | 87 // specific path may reveal private information. |
73 if (LowerCaseEqualsASCII(query_as_url.scheme(), content::kHttpsScheme) && | 88 if (LowerCaseEqualsASCII(query_as_url.scheme(), content::kHttpsScheme) && |
74 !query_as_url.path().empty() && query_as_url.path() != "/") { | 89 !query_as_url.path().empty() && query_as_url.path() != "/") { |
75 return true; | 90 return true; |
76 } | 91 } |
77 | 92 |
78 return false; | 93 return false; |
79 } | 94 } |
80 | 95 |
81 } // namespace app_list | 96 } // namespace app_list |
OLD | NEW |