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/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 WebstoreSearchFetcher; | |
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 SearchProvider { | |
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 void set_use_throttling(bool use) { use_throttling_ = use; } | |
60 | |
61 Profile* profile_; | |
62 AppListControllerDelegate* controller_; | |
63 scoped_ptr<WebstoreSearchFetcher> webstore_search_; | |
64 base::Closure webstore_search_fetched_callback_; | |
65 | |
66 // The cache of the search result which will be valid only in a single | |
67 // input session. | |
68 WebstoreCache cache_; | |
69 | |
70 // The timestamp when the last key event happened. | |
71 base::Time last_keytyped_; | |
72 | |
73 // The timer to throttle QPS to the webstore search . | |
74 base::OneShotTimer<WebstoreProvider> query_throttler_; | |
75 | |
76 // The current query. | |
77 std::string query_; | |
78 | |
79 // The flag for tests. It prevents the throttling If set to false. | |
80 bool use_throttling_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(WebstoreProvider); | |
83 }; | |
84 | |
85 } // namespace app_list | |
86 | |
87 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | |
OLD | NEW |