1424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// found in the LICENSE file. 4424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 5424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_ 6424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_ 7424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/callback_forward.h" 9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/strings/string16.h" 10424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/time/time.h" 11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/timer/timer.h" 124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/app_list/search/common/webservice_cache.h" 13f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ui/app_list/search_provider.h" 14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class Profile; 1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 17424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace app_list { 18424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebserviceCache; 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Helper class for webservice based searches. 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class WebserviceSearchProvider : public SearchProvider { 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) public: 2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) explicit WebserviceSearchProvider(Profile* profile); 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual ~WebserviceSearchProvider(); 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Validate the query for privacy and size. 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool IsValidQuery(const base::string16& query); 2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Start a query with throttling enabled. 31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void StartThrottledQuery(const base::Closure& start_query); 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void set_use_throttling(bool use) { use_throttling_ = use; } 34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) protected: 3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Profile* profile_; 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WebserviceCache* cache_; // KeyedService, not owned. 384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) private: 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool IsSensitiveInput(const base::string16& query); 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // The timestamp when the last key event happened. 43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) base::Time last_keytyped_; 44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // The timer to throttle QPS. 46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) base::OneShotTimer<WebserviceSearchProvider> query_throttler_; 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // The flag for tests. It prevents the throttling If set to false. 49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool use_throttling_; 50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebserviceSearchProvider); 52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}; 53424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace app_list 55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_WEBSERVICE_SEARCH_PROVIDER_H_ 57