| 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 |
| 25 namespace net { | 26 namespace net { |
| 26 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 27 } // namespace net | 28 } // namespace net |
| 28 | 29 |
| 29 namespace user_prefs { | 30 namespace user_prefs { |
| 30 class PrefRegistrySyncable; | 31 class PrefRegistrySyncable; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 extern const char kSuggestionsFieldTrialBlacklistUrlParam[]; | 43 extern const char kSuggestionsFieldTrialBlacklistUrlParam[]; |
| 43 extern const char kSuggestionsFieldTrialStateParam[]; | 44 extern const char kSuggestionsFieldTrialStateParam[]; |
| 44 extern const char kSuggestionsFieldTrialControlParam[]; | 45 extern const char kSuggestionsFieldTrialControlParam[]; |
| 45 extern const char kSuggestionsFieldTrialStateEnabled[]; | 46 extern const char kSuggestionsFieldTrialStateEnabled[]; |
| 46 | 47 |
| 47 // An interface to fetch server suggestions asynchronously. | 48 // An interface to fetch server suggestions asynchronously. |
| 48 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { | 49 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| 49 public: | 50 public: |
| 50 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; | 51 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; |
| 51 | 52 |
| 52 SuggestionsService(net::URLRequestContextGetter* url_request_context, | 53 SuggestionsService( |
| 53 scoped_ptr<SuggestionsStore> suggestions_store, | 54 net::URLRequestContextGetter* url_request_context, |
| 54 scoped_ptr<ImageManager> thumbnail_manager, | 55 scoped_ptr<SuggestionsStore> suggestions_store, |
| 55 scoped_ptr<BlacklistStore> blacklist_store); | 56 scoped_ptr<ImageManager> thumbnail_manager, |
| 57 scoped_ptr<BlacklistStore> blacklist_store); |
| 56 virtual ~SuggestionsService(); | 58 virtual ~SuggestionsService(); |
| 57 | 59 |
| 58 // Whether this service is enabled. | 60 // Whether this service is enabled. |
| 59 static bool IsEnabled(); | 61 static bool IsEnabled(); |
| 60 | 62 |
| 61 // Whether the user is part of a control group. | 63 // Whether the user is part of a control group. |
| 62 static bool IsControlGroup(); | 64 static bool IsControlGroup(); |
| 63 | 65 |
| 64 // Request suggestions data, which will be passed to |callback|. Initiates a | 66 // Request suggestions data, which will be passed to |callback|. Initiates a |
| 65 // fetch request unless a pending one exists. To prevent multiple requests, | 67 // 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. | 130 // blacklist request for it. |
| 129 void UploadOneFromBlacklist(); | 131 void UploadOneFromBlacklist(); |
| 130 | 132 |
| 131 // Updates |blacklist_delay_sec_| based on the success of the last request. | 133 // Updates |blacklist_delay_sec_| based on the success of the last request. |
| 132 void UpdateBlacklistDelay(bool last_request_successful); | 134 void UpdateBlacklistDelay(bool last_request_successful); |
| 133 | 135 |
| 134 // Test seams. | 136 // Test seams. |
| 135 int blacklist_delay() const { return blacklist_delay_sec_; } | 137 int blacklist_delay() const { return blacklist_delay_sec_; } |
| 136 void set_blacklist_delay(int delay) { blacklist_delay_sec_ = delay; } | 138 void set_blacklist_delay(int delay) { blacklist_delay_sec_ = delay; } |
| 137 | 139 |
| 140 base::ThreadChecker thread_checker_; |
| 141 |
| 138 // The cache for the suggestions. | 142 // The cache for the suggestions. |
| 139 scoped_ptr<SuggestionsStore> suggestions_store_; | 143 scoped_ptr<SuggestionsStore> suggestions_store_; |
| 140 | 144 |
| 141 // The local cache for temporary blacklist, until uploaded to the server. | 145 // The local cache for temporary blacklist, until uploaded to the server. |
| 142 scoped_ptr<BlacklistStore> blacklist_store_; | 146 scoped_ptr<BlacklistStore> blacklist_store_; |
| 143 | 147 |
| 144 // Contains the current suggestions fetch request. Will only have a value | 148 // Contains the current suggestions fetch request. Will only have a value |
| 145 // while a request is pending, and will be reset by |OnURLFetchComplete|. | 149 // while a request is pending, and will be reset by |OnURLFetchComplete|. |
| 146 scoped_ptr<net::URLFetcher> pending_request_; | 150 scoped_ptr<net::URLFetcher> pending_request_; |
| 147 | 151 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 175 | 179 |
| 176 // Timeout (in ms) before serving requestors after a fetch suggestions request | 180 // Timeout (in ms) before serving requestors after a fetch suggestions request |
| 177 // has been issued. | 181 // has been issued. |
| 178 int request_timeout_ms_; | 182 int request_timeout_ms_; |
| 179 | 183 |
| 180 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); | 184 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); |
| 181 }; | 185 }; |
| 182 | 186 |
| 183 } // namespace suggestions | 187 } // namespace suggestions |
| 184 | 188 |
| 185 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 189 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |