| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 void FetchSnippets(); | 78 void FetchSnippets(); |
| 79 // Fetches snippets from the server for specified hosts (overriding | 79 // Fetches snippets from the server for specified hosts (overriding |
| 80 // suggestions from the suggestion service) and adds them to the current ones. | 80 // suggestions from the suggestion service) and adds them to the current ones. |
| 81 void FetchSnippetsFromHosts(const std::set<std::string>& hosts); | 81 void FetchSnippetsFromHosts(const std::set<std::string>& hosts); |
| 82 | 82 |
| 83 // Returns the last status message from the snippets fetcher. | 83 // Returns the last status message from the snippets fetcher. |
| 84 const std::string& last_status() const { | 84 const std::string& last_status() const { |
| 85 return last_fetch_status_; | 85 return last_fetch_status_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Returns the last json from the snippets fetcher. |
| 89 const std::string& last_json() const { |
| 90 return last_fetch_json_; |
| 91 } |
| 92 |
| 88 // (Re)schedules the periodic fetching of snippets. This is necessary because | 93 // (Re)schedules the periodic fetching of snippets. This is necessary because |
| 89 // the schedule depends on the time of day | 94 // the schedule depends on the time of day |
| 90 void RescheduleFetching(); | 95 void RescheduleFetching(); |
| 91 | 96 |
| 92 // Deletes all currently stored snippets. | 97 // Deletes all currently stored snippets. |
| 93 void ClearSnippets(); | 98 void ClearSnippets(); |
| 94 | 99 |
| 95 // Discards the snippet with the given |url|, if it exists. Returns true iff | 100 // Discards the snippet with the given |url|, if it exists. Returns true iff |
| 96 // a snippet was discarded. | 101 // a snippet was discarded. |
| 97 bool DiscardSnippet(const GURL& url); | 102 bool DiscardSnippet(const GURL& url); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // The snippets fetcher. | 200 // The snippets fetcher. |
| 196 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; | 201 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; |
| 197 | 202 |
| 198 // The subscription to the snippets fetcher. | 203 // The subscription to the snippets fetcher. |
| 199 std::unique_ptr< | 204 std::unique_ptr< |
| 200 NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription> | 205 NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription> |
| 201 snippets_fetcher_subscription_; | 206 snippets_fetcher_subscription_; |
| 202 | 207 |
| 203 std::string last_fetch_status_; | 208 std::string last_fetch_status_; |
| 204 | 209 |
| 210 std::string last_fetch_json_; |
| 211 |
| 205 // Timer that calls us back when the next snippet expires. | 212 // Timer that calls us back when the next snippet expires. |
| 206 base::OneShotTimer expiry_timer_; | 213 base::OneShotTimer expiry_timer_; |
| 207 | 214 |
| 208 ParseJSONCallback parse_json_callback_; | 215 ParseJSONCallback parse_json_callback_; |
| 209 | 216 |
| 210 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_; | 217 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_; |
| 211 | 218 |
| 212 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); | 219 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
| 213 }; | 220 }; |
| 214 | 221 |
| 215 class NTPSnippetsServiceObserver { | 222 class NTPSnippetsServiceObserver { |
| 216 public: | 223 public: |
| 217 // Sent every time the service loads a new set of data. | 224 // Sent every time the service loads a new set of data. |
| 218 virtual void NTPSnippetsServiceLoaded() = 0; | 225 virtual void NTPSnippetsServiceLoaded() = 0; |
| 219 // Sent when the service is shutting down. | 226 // Sent when the service is shutting down. |
| 220 virtual void NTPSnippetsServiceShutdown() = 0; | 227 virtual void NTPSnippetsServiceShutdown() = 0; |
| 221 | 228 |
| 222 protected: | 229 protected: |
| 223 virtual ~NTPSnippetsServiceObserver() {} | 230 virtual ~NTPSnippetsServiceObserver() {} |
| 224 }; | 231 }; |
| 225 | 232 |
| 226 } // namespace ntp_snippets | 233 } // namespace ntp_snippets |
| 227 | 234 |
| 228 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 235 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| OLD | NEW |