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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_
8 #include "base/callback_forward.h"
9 #include "base/strings/string16.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "chrome/browser/ui/app_list/search/common/webservice_cache.h"
13 #include "ui/app_list/search_provider.h"
19 class WebserviceCache;
21 // Helper class for webservice based searches.
22 class WebserviceSearchProvider : public SearchProvider {
24 explicit WebserviceSearchProvider(Profile* profile);
25 ~WebserviceSearchProvider() override;
27 // Validate the query for privacy and size.
28 bool IsValidQuery(const base::string16& query);
30 // Start a query with throttling enabled.
31 void StartThrottledQuery(const base::Closure& start_query);
33 void set_use_throttling(bool use) { use_throttling_ = use; }
37 WebserviceCache* cache_; // KeyedService, not owned.
40 bool IsSensitiveInput(const base::string16& query);
42 // The timestamp when the last key event happened.
43 base::Time last_keytyped_;
45 // The timer to throttle QPS.
46 base::OneShotTimer<WebserviceSearchProvider> query_throttler_;
48 // The flag for tests. It prevents the throttling If set to false.
51 DISALLOW_COPY_AND_ASSIGN(WebserviceSearchProvider);
54 } // namespace app_list
56 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_