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 <set> | 10 #include <set> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // Inherited from KeyedService. | 73 // Inherited from KeyedService. |
74 void Shutdown() override; | 74 void Shutdown() override; |
75 | 75 |
76 // Fetches snippets from the server and adds them to the current ones. | 76 // Fetches snippets from the server and adds them to the current ones. |
77 void FetchSnippets(); | 77 void FetchSnippets(); |
78 | 78 |
79 // Discards the snippet with the given |url|, if it exists. Returns true iff | 79 // Discards the snippet with the given |url|, if it exists. Returns true iff |
80 // a snippet was discarded. | 80 // a snippet was discarded. |
81 bool DiscardSnippet(const GURL& url); | 81 bool DiscardSnippet(const GURL& url); |
82 | 82 |
| 83 // (Re)schedules the periodic fetching of snippets. This is necessary because |
| 84 // the schedule depends on the time of day |
| 85 void RescheduleFetching(); |
| 86 |
83 // Observer accessors. | 87 // Observer accessors. |
84 void AddObserver(NTPSnippetsServiceObserver* observer); | 88 void AddObserver(NTPSnippetsServiceObserver* observer); |
85 void RemoveObserver(NTPSnippetsServiceObserver* observer); | 89 void RemoveObserver(NTPSnippetsServiceObserver* observer); |
86 | 90 |
87 // Number of snippets available. | 91 // Number of snippets available. |
88 size_t size() const { return snippets_.size(); } | 92 size_t size() const { return snippets_.size(); } |
89 | 93 |
90 // The snippets can be iterated upon only via a const_iterator. Recommended | 94 // The snippets can be iterated upon only via a const_iterator. Recommended |
91 // way to iterate is as follows: | 95 // way to iterate is as follows: |
92 // | 96 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 void LoadDiscardedSnippetsFromPrefs(); | 129 void LoadDiscardedSnippetsFromPrefs(); |
126 void StoreDiscardedSnippetsToPrefs(); | 130 void StoreDiscardedSnippetsToPrefs(); |
127 | 131 |
128 std::set<std::string> GetSnippetHostsFromPrefs() const; | 132 std::set<std::string> GetSnippetHostsFromPrefs() const; |
129 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); | 133 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); |
130 | 134 |
131 bool HasDiscardedSnippet(const GURL& url) const; | 135 bool HasDiscardedSnippet(const GURL& url) const; |
132 | 136 |
133 void RemoveExpiredSnippets(); | 137 void RemoveExpiredSnippets(); |
134 | 138 |
| 139 bool enabled_; |
| 140 |
135 PrefService* pref_service_; | 141 PrefService* pref_service_; |
136 | 142 |
137 suggestions::SuggestionsService* suggestions_service_; | 143 suggestions::SuggestionsService* suggestions_service_; |
138 | 144 |
139 // The SequencedTaskRunner on which file system operations will be run. | 145 // The SequencedTaskRunner on which file system operations will be run. |
140 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 146 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
141 | 147 |
142 // All current suggestions (i.e. not discarded ones). | 148 // All current suggestions (i.e. not discarded ones). |
143 NTPSnippetStorage snippets_; | 149 NTPSnippetStorage snippets_; |
144 | 150 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // Sent when the service is shutting down. | 192 // Sent when the service is shutting down. |
187 virtual void NTPSnippetsServiceShutdown() = 0; | 193 virtual void NTPSnippetsServiceShutdown() = 0; |
188 | 194 |
189 protected: | 195 protected: |
190 virtual ~NTPSnippetsServiceObserver() {} | 196 virtual ~NTPSnippetsServiceObserver() {} |
191 }; | 197 }; |
192 | 198 |
193 } // namespace ntp_snippets | 199 } // namespace ntp_snippets |
194 | 200 |
195 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 201 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
OLD | NEW |