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. 4 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_ 7 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 "chrome/browser/ui/app_list/search/search_provider.h" 14 15 class Profile; 16 17 namespace app_list { 18 19 class WebserviceCache; 20 21 // Helper class for webservice based searches. 22 class WebserviceSearchProvider : public SearchProvider { 23 public: 24 explicit WebserviceSearchProvider(Profile* profile); 25 virtual ~WebserviceSearchProvider(); 26 27 // Validate the query for privacy and size. 28 bool IsValidQuery(const base::string16& query); 29 30 // Start a query with throttling enabled. 31 void StartThrottledQuery(const base::Closure& start_query); 32 33 void set_use_throttling(bool use) { use_throttling_ = use; } 34 35 protected: 36 Profile* profile_; 37 WebserviceCache* cache_; // BrowserContextKeyedService, not owned. 38 39 private: 40 bool IsSensitiveInput(const base::string16& query); 41 42 // The timestamp when the last key event happened. 43 base::Time last_keytyped_; 44 45 // The timer to throttle QPS. 46 base::OneShotTimer<WebserviceSearchProvider> query_throttler_; 47 48 // The flag for tests. It prevents the throttling If set to false. 49 bool use_throttling_; 50 51 DISALLOW_COPY_AND_ASSIGN(WebserviceSearchProvider); 52 }; 53 54 } // namespace app_list 55 56 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_ 57