Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 1743333002: [NTP Snippets] Implement snippets expiry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_persist
Patch Set: review Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/timer/timer.h"
17 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
18 #include "components/ntp_snippets/inner_iterator.h" 19 #include "components/ntp_snippets/inner_iterator.h"
19 #include "components/ntp_snippets/ntp_snippet.h" 20 #include "components/ntp_snippets/ntp_snippet.h"
20 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 21 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
21 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 22 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
22 23
23 class PrefService; 24 class PrefService;
24 25
25 namespace base { 26 namespace base {
26 class FilePath; 27 class FilePath;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 104
104 // Expects a list of dictionaries each containing a "contentInfo" dictionary 105 // Expects a list of dictionaries each containing a "contentInfo" dictionary
105 // with keys matching the properties of a snippet (url, title, site_title, 106 // with keys matching the properties of a snippet (url, title, site_title,
106 // etc...). The url is the only mandatory value. 107 // etc...). The url is the only mandatory value.
107 bool LoadFromJSONList(const base::ListValue& list); 108 bool LoadFromJSONList(const base::ListValue& list);
108 109
109 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite? 110 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite?
110 void LoadFromPrefs(); 111 void LoadFromPrefs();
111 void StoreToPrefs(); 112 void StoreToPrefs();
112 113
114 void RemoveExpiredSnippets();
115
113 PrefService* pref_service_; 116 PrefService* pref_service_;
114 117
115 // True if the suggestions are loaded. 118 // True if the suggestions are loaded.
116 bool loaded_; 119 bool loaded_;
117 120
118 // The SequencedTaskRunner on which file system operations will be run. 121 // The SequencedTaskRunner on which file system operations will be run.
119 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 122 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
120 123
121 // All the suggestions. 124 // All the suggestions.
122 NTPSnippetStorage snippets_; 125 NTPSnippetStorage snippets_;
123 126
124 // The ISO 639-1 code of the language used by the application. 127 // The ISO 639-1 code of the language used by the application.
125 const std::string application_language_code_; 128 const std::string application_language_code_;
126 129
127 // The observers. 130 // The observers.
128 base::ObserverList<NTPSnippetsServiceObserver> observers_; 131 base::ObserverList<NTPSnippetsServiceObserver> observers_;
129 132
130 // Scheduler for fetching snippets. Not owned. 133 // Scheduler for fetching snippets. Not owned.
131 NTPSnippetsScheduler* scheduler_; 134 NTPSnippetsScheduler* scheduler_;
132 135
133 // The snippets fetcher 136 // The snippets fetcher.
134 scoped_ptr<NTPSnippetsFetcher> snippets_fetcher_; 137 scoped_ptr<NTPSnippetsFetcher> snippets_fetcher_;
135 138
136 // The callback from the snippets fetcher 139 // The subscription to the snippets fetcher.
137 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription> 140 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription>
138 snippets_fetcher_callback_; 141 snippets_fetcher_callback_;
139 142
143 // Timer that calls us back when the next snippet expires.
144 base::OneShotTimer expiry_timer_;
145
140 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_; 146 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_;
141 147
142 friend class NTPSnippetsServiceTest; 148 friend class NTPSnippetsServiceTest;
143 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Loop); 149 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Loop);
144 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Full); 150 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Full);
145 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverLoaded); 151 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverLoaded);
146 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverNotLoaded); 152 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverNotLoaded);
147 153
148 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 154 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
149 }; 155 };
150 156
151 class NTPSnippetsServiceObserver { 157 class NTPSnippetsServiceObserver {
152 public: 158 public:
153 // Send everytime the service loads a new set of data. 159 // Send everytime the service loads a new set of data.
154 virtual void NTPSnippetsServiceLoaded(NTPSnippetsService* service) = 0; 160 virtual void NTPSnippetsServiceLoaded(NTPSnippetsService* service) = 0;
155 // Send when the service is shutting down. 161 // Send when the service is shutting down.
156 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0; 162 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0;
157 163
158 protected: 164 protected:
159 virtual ~NTPSnippetsServiceObserver() {} 165 virtual ~NTPSnippetsServiceObserver() {}
160 }; 166 };
161 167
162 } // namespace ntp_snippets 168 } // namespace ntp_snippets
163 169
164 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 170 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698