OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_PROVIDER_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback_forward.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/time/time.h" | 11 #include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h" |
12 #include "base/timer/timer.h" | 12 #include "chrome/browser/ui/app_list/search/webstore/webstore_cache.h" |
13 #include "chrome/browser/ui/app_list/search/search_provider.h" | |
14 #include "chrome/browser/ui/app_list/search/webstore_cache.h" | |
15 | 13 |
16 class AppListControllerDelegate; | 14 class AppListControllerDelegate; |
17 class Profile; | |
18 | 15 |
19 namespace base { | 16 namespace base { |
20 class DictionaryValue; | 17 class DictionaryValue; |
21 } | 18 } |
22 | 19 |
23 namespace app_list { | 20 namespace app_list { |
24 | 21 |
25 namespace test { | 22 namespace test { |
26 class WebstoreProviderTest; | 23 class WebstoreProviderTest; |
27 } | 24 } |
28 | 25 |
29 class ChromeSearchResult; | 26 class ChromeSearchResult; |
30 class WebstoreSearchFetcher; | 27 class JSONResponseFetcher; |
31 | 28 |
32 // WebstoreProvider fetches search results from the web store server. | 29 // WebstoreProvider fetches search results from the web store server. |
33 // A "Search in web store" result will be returned if the server does not | 30 // A "Search in web store" result will be returned if the server does not |
34 // return any results. | 31 // return any results. |
35 class WebstoreProvider : public SearchProvider { | 32 class WebstoreProvider : public WebserviceSearchProvider{ |
36 public: | 33 public: |
37 WebstoreProvider(Profile* profile, AppListControllerDelegate* controller); | 34 WebstoreProvider(Profile* profile, AppListControllerDelegate* controller); |
38 virtual ~WebstoreProvider(); | 35 virtual ~WebstoreProvider(); |
39 | 36 |
40 // SearchProvider overrides: | 37 // SearchProvider overrides: |
41 virtual void Start(const base::string16& query) OVERRIDE; | 38 virtual void Start(const base::string16& query) OVERRIDE; |
42 virtual void Stop() OVERRIDE; | 39 virtual void Stop() OVERRIDE; |
43 | 40 |
44 private: | 41 private: |
45 friend class app_list::test::WebstoreProviderTest; | 42 friend class app_list::test::WebstoreProviderTest; |
46 | 43 |
47 // Start the search request with |query_|. | 44 // Start the search request with |query_|. |
48 void StartQuery(); | 45 void StartQuery(); |
49 | 46 |
50 void OnWebstoreSearchFetched(scoped_ptr<base::DictionaryValue> json); | 47 void OnWebstoreSearchFetched(scoped_ptr<base::DictionaryValue> json); |
51 void ProcessWebstoreSearchResults(const base::DictionaryValue* json); | 48 void ProcessWebstoreSearchResults(const base::DictionaryValue* json); |
52 scoped_ptr<ChromeSearchResult> CreateResult( | 49 scoped_ptr<ChromeSearchResult> CreateResult( |
53 const base::DictionaryValue& dict); | 50 const base::DictionaryValue& dict); |
54 | 51 |
55 void set_webstore_search_fetched_callback(const base::Closure& callback) { | 52 void set_webstore_search_fetched_callback(const base::Closure& callback) { |
56 webstore_search_fetched_callback_ = callback; | 53 webstore_search_fetched_callback_ = callback; |
57 } | 54 } |
58 | 55 |
59 void set_use_throttling(bool use) { use_throttling_ = use; } | |
60 | |
61 Profile* profile_; | |
62 AppListControllerDelegate* controller_; | 56 AppListControllerDelegate* controller_; |
63 scoped_ptr<WebstoreSearchFetcher> webstore_search_; | 57 scoped_ptr<JSONResponseFetcher> webstore_search_; |
64 base::Closure webstore_search_fetched_callback_; | 58 base::Closure webstore_search_fetched_callback_; |
65 | 59 |
66 // The cache of the search result which will be valid only in a single | 60 // The cache of the search result which will be valid only in a single |
67 // input session. | 61 // input session. |
68 WebstoreCache cache_; | 62 WebstoreCache cache_; |
69 | 63 |
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. | 64 // The current query. |
77 std::string query_; | 65 std::string query_; |
78 | 66 |
79 // The flag for tests. It prevents the throttling If set to false. | |
80 bool use_throttling_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(WebstoreProvider); | 67 DISALLOW_COPY_AND_ASSIGN(WebstoreProvider); |
83 }; | 68 }; |
84 | 69 |
85 } // namespace app_list | 70 } // namespace app_list |
86 | 71 |
87 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_PROVIDER_H_ | 72 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_PROVIDER_H_ |
OLD | NEW |