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

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

Issue 1883523002: chrome://snippets-internals page for debugging NTP snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit tests Created 4 years, 8 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 <set> 10 #include <set>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 69 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
70 70
71 void Init(bool enabled); 71 void Init(bool enabled);
72 72
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 // Fetches snippets from the server for specified hosts (overriding
79 // suggestions from the suggestion service) and adds them to the current ones.
80 void FetchSnippetsFromHosts(const std::set<std::string>& hosts);
81 // Deletes all currently stored snippets.
82 void ClearSnippets();
78 83
79 // Discards the snippet with the given |url|, if it exists. Returns true iff 84 // Discards the snippet with the given |url|, if it exists. Returns true iff
80 // a snippet was discarded. 85 // a snippet was discarded.
81 bool DiscardSnippet(const GURL& url); 86 bool DiscardSnippet(const GURL& url);
82 87
88 // Returns the lists of snippets previously discarded by the user (that are
89 // not expired yet).
90 const NTPSnippetStorage& GetDiscardedSnippets();
Marc Treib 2016/04/13 08:45:52 Should be const (add "const" just before the semic
jkrcal 2016/04/14 15:27:00 Done.
91
92 // Clears the lists of snippets previously discarded by the user.
93 void ClearDiscardedSnippets();
94
95 // Returns the lists of suggestion hosts the snippets are restricted to.
96 std::set<std::string> GetSuggestionsHosts();
Marc Treib 2016/04/13 08:45:52 Also const please
jkrcal 2016/04/14 15:27:01 Done.
97
83 // Observer accessors. 98 // Observer accessors.
84 void AddObserver(NTPSnippetsServiceObserver* observer); 99 void AddObserver(NTPSnippetsServiceObserver* observer);
85 void RemoveObserver(NTPSnippetsServiceObserver* observer); 100 void RemoveObserver(NTPSnippetsServiceObserver* observer);
86 101
87 // Number of snippets available. 102 // Number of snippets available.
88 size_t size() const { return snippets_.size(); } 103 size_t size() const { return snippets_.size(); }
89 104
90 // The snippets can be iterated upon only via a const_iterator. Recommended 105 // The snippets can be iterated upon only via a const_iterator. Recommended
91 // way to iterate is as follows: 106 // way to iterate is as follows:
92 // 107 //
93 // NTPSnippetsService* service; // Assume is set. 108 // NTPSnippetsService* service; // Assume is set.
94 // for (auto& snippet : *service) { 109 // for (auto& snippet : *service) {
95 // // |snippet| here is a const object. 110 // // |snippet| here is a const object.
96 // } 111 // }
97 const_iterator begin() const { return const_iterator(snippets_.begin()); } 112 const_iterator begin() const { return const_iterator(snippets_.begin()); }
98 const_iterator end() const { return const_iterator(snippets_.end()); } 113 const_iterator end() const { return const_iterator(snippets_.end()); }
99 114
100 private: 115 private:
101 friend class NTPSnippetsServiceTest; 116 friend class NTPSnippetsServiceTest;
102 117
103 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); 118 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions);
104 void OnSnippetsDownloaded(const std::string& snippets_json); 119 void OnSnippetsDownloaded(const std::string& snippets_json);
105 120
106 void OnJsonParsed(const std::string& snippets_json, 121 void OnJsonParsed(const std::string& snippets_json,
107 scoped_ptr<base::Value> parsed); 122 scoped_ptr<base::Value> parsed);
108 void OnJsonError(const std::string& snippets_json, const std::string& error); 123 void OnJsonError(const std::string& snippets_json, const std::string& error);
109 124
110 void FetchSnippetsImpl(const std::set<std::string>& hosts);
111
112 // Expects a top-level dictionary containing a "recos" list, which will be 125 // Expects a top-level dictionary containing a "recos" list, which will be
113 // passed to LoadFromListValue(). 126 // passed to LoadFromListValue().
114 bool LoadFromValue(const base::Value& value); 127 bool LoadFromValue(const base::Value& value);
115 128
116 // Expects a list of dictionaries each containing a "contentInfo" dictionary 129 // Expects a list of dictionaries each containing a "contentInfo" dictionary
117 // with keys matching the properties of a snippet (url, title, site_title, 130 // with keys matching the properties of a snippet (url, title, site_title,
118 // etc...). The URL is the only mandatory value. 131 // etc...). The URL is the only mandatory value.
119 bool LoadFromListValue(const base::ListValue& list); 132 bool LoadFromListValue(const base::ListValue& list);
120 133
121 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite? 134 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite?
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Sent when the service is shutting down. 199 // Sent when the service is shutting down.
187 virtual void NTPSnippetsServiceShutdown() = 0; 200 virtual void NTPSnippetsServiceShutdown() = 0;
188 201
189 protected: 202 protected:
190 virtual ~NTPSnippetsServiceObserver() {} 203 virtual ~NTPSnippetsServiceObserver() {}
191 }; 204 };
192 205
193 } // namespace ntp_snippets 206 } // namespace ntp_snippets
194 207
195 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 208 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698