OLD | NEW |
| (Empty) |
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_WEBSTORE_PROVIDER_H_ | |
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/callback.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/time/time.h" | |
12 #include "base/timer/timer.h" | |
13 #include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h" | |
14 #include "chrome/browser/ui/app_list/search/webstore_cache.h" | |
15 | |
16 class AppListControllerDelegate; | |
17 class Profile; | |
18 | |
19 namespace base { | |
20 class DictionaryValue; | |
21 } | |
22 | |
23 namespace app_list { | |
24 | |
25 namespace test { | |
26 class WebstoreProviderTest; | |
27 } | |
28 | |
29 class ChromeSearchResult; | |
30 class JSONResponseFetcher; | |
31 | |
32 // WebstoreProvider fetches search results from the web store server. | |
33 // A "Search in web store" result will be returned if the server does not | |
34 // return any results. | |
35 class WebstoreProvider : public WebserviceSearchProvider{ | |
36 public: | |
37 WebstoreProvider(Profile* profile, AppListControllerDelegate* controller); | |
38 virtual ~WebstoreProvider(); | |
39 | |
40 // SearchProvider overrides: | |
41 virtual void Start(const base::string16& query) OVERRIDE; | |
42 virtual void Stop() OVERRIDE; | |
43 | |
44 private: | |
45 friend class app_list::test::WebstoreProviderTest; | |
46 | |
47 // Start the search request with |query_|. | |
48 void StartQuery(); | |
49 | |
50 void OnWebstoreSearchFetched(scoped_ptr<base::DictionaryValue> json); | |
51 void ProcessWebstoreSearchResults(const base::DictionaryValue* json); | |
52 scoped_ptr<ChromeSearchResult> CreateResult( | |
53 const base::DictionaryValue& dict); | |
54 | |
55 void set_webstore_search_fetched_callback(const base::Closure& callback) { | |
56 webstore_search_fetched_callback_ = callback; | |
57 } | |
58 | |
59 Profile* profile_; | |
60 AppListControllerDelegate* controller_; | |
61 scoped_ptr<JSONResponseFetcher> webstore_search_; | |
62 base::Closure webstore_search_fetched_callback_; | |
63 | |
64 // The cache of the search result which will be valid only in a single | |
65 // input session. | |
66 WebstoreCache cache_; | |
67 | |
68 // The timestamp when the last key event happened. | |
69 base::Time last_keytyped_; | |
70 | |
71 // The timer to throttle QPS to the webstore search . | |
72 base::OneShotTimer<WebstoreProvider> query_throttler_; | |
73 | |
74 // The current query. | |
75 std::string query_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(WebstoreProvider); | |
78 }; | |
79 | |
80 } // namespace app_list | |
81 | |
82 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | |
OLD | NEW |