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

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: 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
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 ScheduleExpiryTimer();
115
116 void RemoveExpiredSnippets();
117
113 PrefService* pref_service_; 118 PrefService* pref_service_;
114 119
115 // True if the suggestions are loaded. 120 // True if the suggestions are loaded.
116 bool loaded_; 121 bool loaded_;
117 122
118 // The SequencedTaskRunner on which file system operations will be run. 123 // The SequencedTaskRunner on which file system operations will be run.
119 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 124 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
120 125
121 // All the suggestions. 126 // All the suggestions.
122 NTPSnippetStorage snippets_; 127 NTPSnippetStorage snippets_;
123 128
124 // The ISO 639-1 code of the language used by the application. 129 // The ISO 639-1 code of the language used by the application.
125 const std::string application_language_code_; 130 const std::string application_language_code_;
126 131
127 // The observers. 132 // The observers.
128 base::ObserverList<NTPSnippetsServiceObserver> observers_; 133 base::ObserverList<NTPSnippetsServiceObserver> observers_;
129 134
130 // Scheduler for fetching snippets. Not owned. 135 // Scheduler for fetching snippets. Not owned.
131 NTPSnippetsScheduler* scheduler_; 136 NTPSnippetsScheduler* scheduler_;
132 137
133 // The snippets fetcher 138 // The snippets fetcher.
134 scoped_ptr<NTPSnippetsFetcher> snippets_fetcher_; 139 scoped_ptr<NTPSnippetsFetcher> snippets_fetcher_;
135 140
136 // The callback from the snippets fetcher 141 // The subscription to the snippets fetcher.
137 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription> 142 scoped_ptr<NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription>
138 snippets_fetcher_callback_; 143 snippets_fetcher_callback_;
139 144
145 // Timer that calls us back when the next snippet expires.
146 base::OneShotTimer expiry_timer_;
147
140 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_; 148 base::WeakPtrFactory<NTPSnippetsService> weak_ptr_factory_;
141 149
142 friend class NTPSnippetsServiceTest; 150 friend class NTPSnippetsServiceTest;
143 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Loop); 151 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Loop);
144 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Full); 152 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, Full);
145 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverLoaded); 153 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverLoaded);
146 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverNotLoaded); 154 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, ObserverNotLoaded);
147 155
148 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 156 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
149 }; 157 };
150 158
151 class NTPSnippetsServiceObserver { 159 class NTPSnippetsServiceObserver {
152 public: 160 public:
153 // Send everytime the service loads a new set of data. 161 // Send everytime the service loads a new set of data.
154 virtual void NTPSnippetsServiceLoaded(NTPSnippetsService* service) = 0; 162 virtual void NTPSnippetsServiceLoaded(NTPSnippetsService* service) = 0;
155 // Send when the service is shutting down. 163 // Send when the service is shutting down.
156 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0; 164 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0;
157 165
158 protected: 166 protected:
159 virtual ~NTPSnippetsServiceObserver() {} 167 virtual ~NTPSnippetsServiceObserver() {}
160 }; 168 };
161 169
162 } // namespace ntp_snippets 170 } // namespace ntp_snippets
163 171
164 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 172 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698