| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // for requests triggered by the user. | 102 // for requests triggered by the user. |
| 103 void FetchSnippets(bool force_request); | 103 void FetchSnippets(bool force_request); |
| 104 | 104 |
| 105 // Fetches snippets from the server for specified hosts (overriding | 105 // Fetches snippets from the server for specified hosts (overriding |
| 106 // suggestions from the suggestion service) and adds them to the current ones. | 106 // suggestions from the suggestion service) and adds them to the current ones. |
| 107 // Only called from chrome://snippets-internals, DO NOT USE otherwise! | 107 // Only called from chrome://snippets-internals, DO NOT USE otherwise! |
| 108 // Ignored while |loaded()| is false. | 108 // Ignored while |loaded()| is false. |
| 109 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, | 109 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, |
| 110 bool force_request); | 110 bool force_request); |
| 111 | 111 |
| 112 // Available snippets. | |
| 113 const NTPSnippet::PtrVector& snippets() const { return snippets_; } | |
| 114 | |
| 115 // Returns the list of snippets previously dismissed by the user (that are | |
| 116 // not expired yet). | |
| 117 const NTPSnippet::PtrVector& dismissed_snippets() const { | |
| 118 return dismissed_snippets_; | |
| 119 } | |
| 120 | |
| 121 const NTPSnippetsFetcher* snippets_fetcher() const { | 112 const NTPSnippetsFetcher* snippets_fetcher() const { |
| 122 return snippets_fetcher_.get(); | 113 return snippets_fetcher_.get(); |
| 123 } | 114 } |
| 124 | 115 |
| 125 // Returns a reason why the service is disabled, or DisabledReason::NONE | 116 // Returns a reason why the service is disabled, or DisabledReason::NONE |
| 126 // if it's not. | 117 // if it's not. |
| 127 DisabledReason disabled_reason() const { | 118 DisabledReason disabled_reason() const { |
| 128 return snippets_status_service_->disabled_reason(); | 119 return snippets_status_service_->disabled_reason(); |
| 129 } | 120 } |
| 130 | 121 |
| 131 // (Re)schedules the periodic fetching of snippets. This is necessary because | 122 // (Re)schedules the periodic fetching of snippets. This is necessary because |
| 132 // the schedule depends on the time of day. | 123 // the schedule depends on the time of day. |
| 133 void RescheduleFetching(); | 124 void RescheduleFetching(); |
| 134 | 125 |
| 135 // ContentSuggestionsProvider implementation | 126 // ContentSuggestionsProvider implementation |
| 136 // TODO(pke): At some point reorder the implementations in the .cc file | |
| 137 // accordingly. | |
| 138 std::vector<Category> GetProvidedCategories() override; | 127 std::vector<Category> GetProvidedCategories() override; |
| 139 CategoryStatus GetCategoryStatus(Category category) override; | 128 CategoryStatus GetCategoryStatus(Category category) override; |
| 140 void DismissSuggestion(const std::string& suggestion_id) override; | 129 void DismissSuggestion(const std::string& suggestion_id) override; |
| 141 void FetchSuggestionImage(const std::string& suggestion_id, | 130 void FetchSuggestionImage(const std::string& suggestion_id, |
| 142 const ImageFetchedCallback& callback) override; | 131 const ImageFetchedCallback& callback) override; |
| 143 void ClearCachedSuggestionsForDebugging() override; | 132 void ClearCachedSuggestionsForDebugging(Category category) override; |
| 144 void ClearDismissedSuggestionsForDebugging() override; | 133 std::vector<ContentSuggestion> GetDismissedSuggestionsForDebugging( |
| 134 Category category) override; |
| 135 void ClearDismissedSuggestionsForDebugging(Category category) override; |
| 145 | 136 |
| 146 // Returns the lists of suggestion hosts the snippets are restricted to. | 137 // Returns the lists of suggestion hosts the snippets are restricted to. |
| 147 std::set<std::string> GetSuggestionsHosts() const; | 138 std::set<std::string> GetSuggestionsHosts() const; |
| 148 | 139 |
| 149 // Returns the maximum number of snippets that will be shown at once. | 140 // Returns the maximum number of snippets that will be shown at once. |
| 150 static int GetMaxSnippetCountForTesting(); | 141 static int GetMaxSnippetCountForTesting(); |
| 151 | 142 |
| 143 // Available snippets, only for unit tests. |
| 144 const NTPSnippet::PtrVector& GetSnippetsForTesting() const { |
| 145 return snippets_; |
| 146 } |
| 147 |
| 152 private: | 148 private: |
| 153 friend class NTPSnippetsServiceTest; | 149 friend class NTPSnippetsServiceTest; |
| 154 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, StatusChanges); | 150 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, StatusChanges); |
| 155 | 151 |
| 156 // Possible state transitions: | 152 // Possible state transitions: |
| 157 // NOT_INITED --------+ | 153 // NOT_INITED --------+ |
| 158 // / \ | | 154 // / \ | |
| 159 // v v | | 155 // v v | |
| 160 // READY <--> DISABLED | | 156 // READY <--> DISABLED | |
| 161 // \ / | | 157 // \ / | |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 bool fetch_after_load_; | 302 bool fetch_after_load_; |
| 307 | 303 |
| 308 const Category provided_category_; | 304 const Category provided_category_; |
| 309 | 305 |
| 310 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); | 306 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
| 311 }; | 307 }; |
| 312 | 308 |
| 313 } // namespace ntp_snippets | 309 } // namespace ntp_snippets |
| 314 | 310 |
| 315 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 311 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| OLD | NEW |