This source file includes following definitions.
- use_throttling_
- StartThrottledQuery
- IsValidQuery
- IsSensitiveInput
#include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h"
#include <string>
#include "base/callback.h"
#include "base/strings/string_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/app_list/search/common/webservice_cache.h"
#include "chrome/browser/ui/app_list/search/common/webservice_cache_factory.h"
#include "chrome/common/url_constants.h"
#include "url/gurl.h"
namespace app_list {
namespace {
const int kWebserviceQueryThrottleIntrevalInMs = 100;
const size_t kMinimumQueryLength = 3u;
}
WebserviceSearchProvider::WebserviceSearchProvider(Profile* profile)
: profile_(profile),
cache_(WebserviceCacheFactory::GetForBrowserContext(profile)),
use_throttling_(true) {}
WebserviceSearchProvider::~WebserviceSearchProvider() {}
void WebserviceSearchProvider::StartThrottledQuery(
const base::Closure& start_query) {
base::TimeDelta interval =
base::TimeDelta::FromMilliseconds(kWebserviceQueryThrottleIntrevalInMs);
if (!use_throttling_ || base::Time::Now() - last_keytyped_ > interval) {
query_throttler_.Stop();
start_query.Run();
} else {
query_throttler_.Start(FROM_HERE, interval, start_query);
}
last_keytyped_ = base::Time::Now();
}
bool WebserviceSearchProvider::IsValidQuery(const base::string16& query) {
if (IsSensitiveInput(query) ||
(query.size() < kMinimumQueryLength) ||
!chrome::IsSuggestPrefEnabled(profile_)) {
return false;
}
return true;
}
bool WebserviceSearchProvider::IsSensitiveInput(const base::string16& query) {
const GURL query_as_url(query);
if (!query_as_url.is_valid())
return false;
if (LowerCaseEqualsASCII(query_as_url.scheme(), content::kFileScheme))
return true;
if (!query_as_url.username().empty() ||
!query_as_url.port().empty() ||
!query_as_url.query().empty() ||
!query_as_url.ref().empty()) {
return true;
}
if (LowerCaseEqualsASCII(query_as_url.scheme(), content::kHttpsScheme) &&
!query_as_url.path().empty() && query_as_url.path() != "/") {
return true;
}
return false;
}
}