OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 5 #ifndef COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/thread_checker.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/browser/search/suggestions/image_manager.h" | |
19 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" | |
20 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "components/suggestions/image_manager.h" |
| 21 #include "components/suggestions/proto/suggestions.pb.h" |
21 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
| 26 namespace base { |
| 27 class SingleThreadTaskRunner; |
| 28 } // namespace base |
| 29 |
25 namespace net { | 30 namespace net { |
26 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
27 } // namespace net | 32 } // namespace net |
28 | 33 |
29 namespace user_prefs { | 34 namespace user_prefs { |
30 class PrefRegistrySyncable; | 35 class PrefRegistrySyncable; |
31 } // namespace user_prefs | 36 } // namespace user_prefs |
32 | 37 |
33 namespace suggestions { | 38 namespace suggestions { |
34 | 39 |
35 class BlacklistStore; | 40 class BlacklistStore; |
36 class SuggestionsStore; | 41 class SuggestionsStore; |
37 | 42 |
38 extern const char kSuggestionsFieldTrialName[]; | 43 extern const char kSuggestionsFieldTrialName[]; |
39 extern const char kSuggestionsFieldTrialURLParam[]; | 44 extern const char kSuggestionsFieldTrialURLParam[]; |
40 extern const char kSuggestionsFieldTrialCommonParamsParam[]; | 45 extern const char kSuggestionsFieldTrialCommonParamsParam[]; |
41 extern const char kSuggestionsFieldTrialBlacklistPathParam[]; | 46 extern const char kSuggestionsFieldTrialBlacklistPathParam[]; |
42 extern const char kSuggestionsFieldTrialBlacklistUrlParam[]; | 47 extern const char kSuggestionsFieldTrialBlacklistUrlParam[]; |
43 extern const char kSuggestionsFieldTrialStateParam[]; | 48 extern const char kSuggestionsFieldTrialStateParam[]; |
44 extern const char kSuggestionsFieldTrialControlParam[]; | 49 extern const char kSuggestionsFieldTrialControlParam[]; |
45 extern const char kSuggestionsFieldTrialStateEnabled[]; | 50 extern const char kSuggestionsFieldTrialStateEnabled[]; |
46 | 51 |
47 // An interface to fetch server suggestions asynchronously. | 52 // An interface to fetch server suggestions asynchronously. |
48 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { | 53 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
49 public: | 54 public: |
50 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; | 55 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; |
51 | 56 |
52 SuggestionsService(net::URLRequestContextGetter* url_request_context, | 57 SuggestionsService( |
53 scoped_ptr<SuggestionsStore> suggestions_store, | 58 net::URLRequestContextGetter* url_request_context, |
54 scoped_ptr<ImageManager> thumbnail_manager, | 59 scoped_ptr<SuggestionsStore> suggestions_store, |
55 scoped_ptr<BlacklistStore> blacklist_store); | 60 scoped_ptr<ImageManager> thumbnail_manager, |
| 61 scoped_ptr<BlacklistStore> blacklist_store, |
| 62 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
56 virtual ~SuggestionsService(); | 63 virtual ~SuggestionsService(); |
57 | 64 |
58 // Whether this service is enabled. | 65 // Whether this service is enabled. |
59 static bool IsEnabled(); | 66 static bool IsEnabled(); |
60 | 67 |
61 // Whether the user is part of a control group. | 68 // Whether the user is part of a control group. |
62 static bool IsControlGroup(); | 69 static bool IsControlGroup(); |
63 | 70 |
64 // Request suggestions data, which will be passed to |callback|. Initiates a | 71 // Request suggestions data, which will be passed to |callback|. Initiates a |
65 // fetch request unless a pending one exists. To prevent multiple requests, | 72 // fetch request unless a pending one exists. To prevent multiple requests, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // blacklist request for it. | 135 // blacklist request for it. |
129 void UploadOneFromBlacklist(); | 136 void UploadOneFromBlacklist(); |
130 | 137 |
131 // Updates |blacklist_delay_sec_| based on the success of the last request. | 138 // Updates |blacklist_delay_sec_| based on the success of the last request. |
132 void UpdateBlacklistDelay(bool last_request_successful); | 139 void UpdateBlacklistDelay(bool last_request_successful); |
133 | 140 |
134 // Test seams. | 141 // Test seams. |
135 int blacklist_delay() const { return blacklist_delay_sec_; } | 142 int blacklist_delay() const { return blacklist_delay_sec_; } |
136 void set_blacklist_delay(int delay) { blacklist_delay_sec_ = delay; } | 143 void set_blacklist_delay(int delay) { blacklist_delay_sec_ = delay; } |
137 | 144 |
| 145 base::ThreadChecker thread_checker_; |
| 146 |
| 147 // Task runner on which callback tasks are posted. |
| 148 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 149 |
138 // The cache for the suggestions. | 150 // The cache for the suggestions. |
139 scoped_ptr<SuggestionsStore> suggestions_store_; | 151 scoped_ptr<SuggestionsStore> suggestions_store_; |
140 | 152 |
141 // The local cache for temporary blacklist, until uploaded to the server. | 153 // The local cache for temporary blacklist, until uploaded to the server. |
142 scoped_ptr<BlacklistStore> blacklist_store_; | 154 scoped_ptr<BlacklistStore> blacklist_store_; |
143 | 155 |
144 // Contains the current suggestions fetch request. Will only have a value | 156 // Contains the current suggestions fetch request. Will only have a value |
145 // while a request is pending, and will be reset by |OnURLFetchComplete|. | 157 // while a request is pending, and will be reset by |OnURLFetchComplete|. |
146 scoped_ptr<net::URLFetcher> pending_request_; | 158 scoped_ptr<net::URLFetcher> pending_request_; |
147 | 159 |
(...skipping 27 matching lines...) Expand all Loading... |
175 | 187 |
176 // Timeout (in ms) before serving requestors after a fetch suggestions request | 188 // Timeout (in ms) before serving requestors after a fetch suggestions request |
177 // has been issued. | 189 // has been issued. |
178 int request_timeout_ms_; | 190 int request_timeout_ms_; |
179 | 191 |
180 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); | 192 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); |
181 }; | 193 }; |
182 | 194 |
183 } // namespace suggestions | 195 } // namespace suggestions |
184 | 196 |
185 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 197 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |