| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_list.h" | 14 #include "base/callback_list.h" |
| 15 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/optional.h" | 19 #include "base/optional.h" |
| 19 #include "base/scoped_observer.h" | 20 #include "base/scoped_observer.h" |
| 20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "components/signin/core/browser/access_token_fetcher.h" | 23 #include "components/signin/core/browser/access_token_fetcher.h" |
| 23 #include "components/suggestions/proto/suggestions.pb.h" | 24 #include "components/suggestions/proto/suggestions.pb.h" |
| 24 #include "components/suggestions/suggestions_service.h" | 25 #include "components/suggestions/suggestions_service.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 // Register SuggestionsService related prefs in the Profile prefs. | 85 // Register SuggestionsService related prefs in the Profile prefs. |
| 85 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 86 | 87 |
| 87 private: | 88 private: |
| 88 friend class SuggestionsServiceTest; | 89 friend class SuggestionsServiceTest; |
| 89 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); | 90 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); |
| 90 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, IgnoresNoopSyncChange); | 91 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, IgnoresNoopSyncChange); |
| 91 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 92 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 92 IgnoresUninterestingSyncChange); | 93 IgnoresUninterestingSyncChange); |
| 94 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, DoesNotFetchOnStartup); |
| 93 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 95 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 94 FetchSuggestionsDataSyncNotInitializedEnabled); | 96 FetchSuggestionsDataSyncNotInitializedEnabled); |
| 95 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 97 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 96 FetchSuggestionsDataSyncDisabled); | 98 FetchSuggestionsDataSyncDisabled); |
| 97 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 99 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 98 FetchSuggestionsDataNoAccessToken); | 100 FetchSuggestionsDataNoAccessToken); |
| 99 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 101 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 100 IssueRequestIfNoneOngoingError); | 102 IssueRequestIfNoneOngoingError); |
| 101 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, | 103 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, |
| 102 IssueRequestIfNoneOngoingResponseNotOK); | 104 IssueRequestIfNoneOngoingResponseNotOK); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 125 // enabled. | 127 // enabled. |
| 126 // Behavior: Update suggestions from the server on FetchSuggestionsData(). | 128 // Behavior: Update suggestions from the server on FetchSuggestionsData(). |
| 127 INITIALIZED_ENABLED_HISTORY, | 129 INITIALIZED_ENABLED_HISTORY, |
| 128 | 130 |
| 129 // State: Sync service is disabled or history sync is disabled. | 131 // State: Sync service is disabled or history sync is disabled. |
| 130 // Behavior: Do not issue server requests. Clear the cache. Serve empty | 132 // Behavior: Do not issue server requests. Clear the cache. Serve empty |
| 131 // suggestions. | 133 // suggestions. |
| 132 SYNC_OR_HISTORY_SYNC_DISABLED, | 134 SYNC_OR_HISTORY_SYNC_DISABLED, |
| 133 }; | 135 }; |
| 134 | 136 |
| 137 // The action that should be taken as the result of a RefreshSyncState call. |
| 138 enum RefreshAction { NO_ACTION, FETCH_SUGGESTIONS, CLEAR_SUGGESTIONS }; |
| 139 |
| 135 // Helpers to build the various suggestions URLs. These are static members | 140 // Helpers to build the various suggestions URLs. These are static members |
| 136 // rather than local functions in the .cc file to make them accessible to | 141 // rather than local functions in the .cc file to make them accessible to |
| 137 // tests. | 142 // tests. |
| 138 static GURL BuildSuggestionsURL(); | 143 static GURL BuildSuggestionsURL(); |
| 139 static std::string BuildSuggestionsBlacklistURLPrefix(); | 144 static std::string BuildSuggestionsBlacklistURLPrefix(); |
| 140 static GURL BuildSuggestionsBlacklistURL(const GURL& candidate_url); | 145 static GURL BuildSuggestionsBlacklistURL(const GURL& candidate_url); |
| 141 static GURL BuildSuggestionsBlacklistClearURL(); | 146 static GURL BuildSuggestionsBlacklistClearURL(); |
| 142 | 147 |
| 143 // Computes the appropriate SyncState from |sync_service_|. | 148 // Computes the appropriate SyncState from |sync_service_|. |
| 144 SyncState ComputeSyncState() const; | 149 SyncState ComputeSyncState() const; |
| 145 | 150 |
| 146 // Re-computes |sync_state_| from the sync service. Returns whether | 151 // Re-computes |sync_state_| from the sync service. Returns the action that |
| 147 // |sync_state_| was changed. | 152 // should be taken in response. |
| 148 bool RefreshSyncState(); | 153 RefreshAction RefreshSyncState() WARN_UNUSED_RESULT; |
| 149 | 154 |
| 150 // syncer::SyncServiceObserver implementation. | 155 // syncer::SyncServiceObserver implementation. |
| 151 void OnStateChanged(syncer::SyncService* sync) override; | 156 void OnStateChanged(syncer::SyncService* sync) override; |
| 152 | 157 |
| 153 // Sets default timestamp for suggestions which do not have expiry timestamp. | 158 // Sets default timestamp for suggestions which do not have expiry timestamp. |
| 154 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, | 159 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, |
| 155 int64_t timestamp_usec); | 160 int64_t timestamp_usec); |
| 156 | 161 |
| 157 // Issues a network request if there isn't already one happening. | 162 // Issues a network request if there isn't already one happening. |
| 158 void IssueRequestIfNoneOngoing(const GURL& url); | 163 void IssueRequestIfNoneOngoing(const GURL& url); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 246 |
| 242 // For callbacks may be run after destruction. | 247 // For callbacks may be run after destruction. |
| 243 base::WeakPtrFactory<SuggestionsServiceImpl> weak_ptr_factory_; | 248 base::WeakPtrFactory<SuggestionsServiceImpl> weak_ptr_factory_; |
| 244 | 249 |
| 245 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceImpl); | 250 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceImpl); |
| 246 }; | 251 }; |
| 247 | 252 |
| 248 } // namespace suggestions | 253 } // namespace suggestions |
| 249 | 254 |
| 250 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ | 255 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_IMPL_H_ |
| OLD | NEW |