Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ | 5 #ifndef COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ |
| 6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ | 6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 const ResponseCallback& callback) override WARN_UNUSED_RESULT; | 71 const ResponseCallback& callback) override WARN_UNUSED_RESULT; |
| 72 void GetPageThumbnail(const GURL& url, | 72 void GetPageThumbnail(const GURL& url, |
| 73 const BitmapCallback& callback) override; | 73 const BitmapCallback& callback) override; |
| 74 void GetPageThumbnailWithURL(const GURL& url, | 74 void GetPageThumbnailWithURL(const GURL& url, |
| 75 const GURL& thumbnail_url, | 75 const GURL& thumbnail_url, |
| 76 const BitmapCallback& callback) override; | 76 const BitmapCallback& callback) override; |
| 77 bool BlacklistURL(const GURL& candidate_url) override; | 77 bool BlacklistURL(const GURL& candidate_url) override; |
| 78 bool UndoBlacklistURL(const GURL& url) override; | 78 bool UndoBlacklistURL(const GURL& url) override; |
| 79 void ClearBlacklist() override; | 79 void ClearBlacklist() override; |
| 80 | 80 |
| 81 base::TimeDelta blacklist_delay_for_testing() const { | |
|
Marc Treib
2017/05/10 09:53:44
Out of curiosity: Do you feel that "for_testing" m
fhorschig
2017/05/10 11:54:44
In this case, I am (obviously) absolutely for for_
| |
| 82 return scheduling_delay_; | |
| 83 } | |
| 84 void set_blacklist_delay_for_testing(base::TimeDelta delay) { | |
| 85 scheduling_delay_ = delay; | |
| 86 } | |
| 87 bool has_pending_request_for_testing() const { | |
| 88 return !!pending_request_.get(); | |
| 89 } | |
| 90 | |
| 81 // Determines which URL a blacklist request was for, irrespective of the | 91 // Determines which URL a blacklist request was for, irrespective of the |
| 82 // request's status. Returns false if |request| is not a blacklist request. | 92 // request's status. Returns false if |request| is not a blacklist request. |
| 83 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); | 93 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); |
| 84 | 94 |
| 85 // Register SuggestionsService related prefs in the Profile prefs. | 95 // Register SuggestionsService related prefs in the Profile prefs. |
| 86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 96 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 87 | 97 |
| 88 private: | 98 private: |
| 89 friend class SuggestionsServiceTest; | |
| 90 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); | |
| 91 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, IgnoresNoopSyncChange); | |
| 92 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 93 IgnoresUninterestingSyncChange); | |
| 94 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, DoesNotFetchOnStartup); | |
| 95 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 96 FetchSuggestionsDataSyncNotInitializedEnabled); | |
| 97 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 98 FetchSuggestionsDataSyncDisabled); | |
| 99 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 100 FetchSuggestionsDataNoAccessToken); | |
| 101 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 102 IssueRequestIfNoneOngoingError); | |
| 103 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 104 IssueRequestIfNoneOngoingResponseNotOK); | |
| 105 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURL); | |
| 106 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLRequestFails); | |
| 107 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, ClearBlacklist); | |
| 108 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURL); | |
| 109 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 110 UndoBlacklistURLFailsIfNotInBlacklist); | |
| 111 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 112 UndoBlacklistURLFailsIfAlreadyCandidate); | |
| 113 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | |
| 114 GetBlacklistedUrlBlacklistRequest); | |
| 115 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); | |
| 116 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, CheckDefaultTimeStamps); | |
| 117 | |
| 118 // Establishes the different sync states that matter to SuggestionsService. | 99 // Establishes the different sync states that matter to SuggestionsService. |
| 119 enum SyncState { | 100 enum SyncState { |
| 120 // State: Sync service is not initialized, yet not disabled. History sync | 101 // State: Sync service is not initialized, yet not disabled. History sync |
| 121 // state is unknown (since not initialized). | 102 // state is unknown (since not initialized). |
| 122 // Behavior: Do not issue server requests, but serve from cache if | 103 // Behavior: Do not issue server requests, but serve from cache if |
| 123 // available. | 104 // available. |
| 124 NOT_INITIALIZED_ENABLED, | 105 NOT_INITIALIZED_ENABLED, |
| 125 | 106 |
| 126 // State: Sync service is initialized, sync is enabled and history sync is | 107 // State: Sync service is initialized, sync is enabled and history sync is |
| 127 // enabled. | 108 // enabled. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 // If the local blacklist isn't empty, picks a URL from it and issues a | 174 // If the local blacklist isn't empty, picks a URL from it and issues a |
| 194 // blacklist request for it. | 175 // blacklist request for it. |
| 195 void UploadOneFromBlacklist(); | 176 void UploadOneFromBlacklist(); |
| 196 | 177 |
| 197 // Updates |scheduling_delay_| based on the success of the last request. | 178 // Updates |scheduling_delay_| based on the success of the last request. |
| 198 void UpdateBlacklistDelay(bool last_request_successful); | 179 void UpdateBlacklistDelay(bool last_request_successful); |
| 199 | 180 |
| 200 // Adds extra data to suggestions profile. | 181 // Adds extra data to suggestions profile. |
| 201 void PopulateExtraData(SuggestionsProfile* suggestions); | 182 void PopulateExtraData(SuggestionsProfile* suggestions); |
| 202 | 183 |
| 203 // Test seams. | |
| 204 base::TimeDelta blacklist_delay() const { return scheduling_delay_; } | |
| 205 void set_blacklist_delay(base::TimeDelta delay) { scheduling_delay_ = delay; } | |
| 206 | |
| 207 base::ThreadChecker thread_checker_; | 184 base::ThreadChecker thread_checker_; |
| 208 | 185 |
| 209 SigninManagerBase* signin_manager_; | 186 SigninManagerBase* signin_manager_; |
| 210 OAuth2TokenService* token_service_; | 187 OAuth2TokenService* token_service_; |
| 211 | 188 |
| 212 syncer::SyncService* sync_service_; | 189 syncer::SyncService* sync_service_; |
| 213 ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> | 190 ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> |
| 214 sync_service_observer_; | 191 sync_service_observer_; |
| 215 | 192 |
| 216 SyncState sync_state_; | 193 SyncState sync_state_; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 246 | 223 |
| 247 // For callbacks may be run after destruction. | 224 // For callbacks may be run after destruction. |
| 248 base::WeakPtrFactory<SuggestionsServiceImpl> weak_ptr_factory_; | 225 base::WeakPtrFactory<SuggestionsServiceImpl> weak_ptr_factory_; |
| 249 | 226 |
| 250 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceImpl); | 227 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceImpl); |
| 251 }; | 228 }; |
| 252 | 229 |
| 253 } // namespace suggestions | 230 } // namespace suggestions |
| 254 | 231 |
| 255 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ | 232 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ |
| OLD | NEW |