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

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: Adding the chrome://snippets-internals page in the auto-suggest list. 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.
Bernhard Bauer 2016/04/14 16:50:24 Empty line before comment.
jkrcal 2016/04/15 14:11:50 Done.
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& discarded_snippets() const {
Bernhard Bauer 2016/04/14 16:50:24 Somewhat unrelated yak-shaving: Now that we have a
Marc Treib 2016/04/15 09:00:30 +1, but IMO this can wait for another CL.
jkrcal 2016/04/15 14:11:50 I agree, I really did not like the asymmetry when
91 return discarded_snippets_;
92 }
93
94 // Clears the lists of snippets previously discarded by the user.
95 void ClearDiscardedSnippets();
96
97 // Returns the lists of suggestion hosts the snippets are restricted to.
98 std::set<std::string> GetSuggestionsHosts() const;
99
83 // Observer accessors. 100 // Observer accessors.
84 void AddObserver(NTPSnippetsServiceObserver* observer); 101 void AddObserver(NTPSnippetsServiceObserver* observer);
85 void RemoveObserver(NTPSnippetsServiceObserver* observer); 102 void RemoveObserver(NTPSnippetsServiceObserver* observer);
86 103
87 // Number of snippets available. 104 // Number of snippets available.
88 size_t size() const { return snippets_.size(); } 105 size_t size() const { return snippets_.size(); }
89 106
90 // The snippets can be iterated upon only via a const_iterator. Recommended 107 // The snippets can be iterated upon only via a const_iterator. Recommended
91 // way to iterate is as follows: 108 // way to iterate is as follows:
92 // 109 //
93 // NTPSnippetsService* service; // Assume is set. 110 // NTPSnippetsService* service; // Assume is set.
94 // for (auto& snippet : *service) { 111 // for (auto& snippet : *service) {
95 // // |snippet| here is a const object. 112 // // |snippet| here is a const object.
96 // } 113 // }
97 const_iterator begin() const { return const_iterator(snippets_.begin()); } 114 const_iterator begin() const { return const_iterator(snippets_.begin()); }
98 const_iterator end() const { return const_iterator(snippets_.end()); } 115 const_iterator end() const { return const_iterator(snippets_.end()); }
99 116
100 private: 117 private:
101 friend class NTPSnippetsServiceTest; 118 friend class NTPSnippetsServiceTest;
102 119
103 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); 120 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions);
104 void OnSnippetsDownloaded(const std::string& snippets_json); 121 void OnSnippetsDownloaded(const std::string& snippets_json);
105 122
106 void OnJsonParsed(const std::string& snippets_json, 123 void OnJsonParsed(const std::string& snippets_json,
107 scoped_ptr<base::Value> parsed); 124 scoped_ptr<base::Value> parsed);
108 void OnJsonError(const std::string& snippets_json, const std::string& error); 125 void OnJsonError(const std::string& snippets_json, const std::string& error);
109 126
110 void FetchSnippetsImpl(const std::set<std::string>& hosts);
111
112 // Expects a top-level dictionary containing a "recos" list, which will be 127 // Expects a top-level dictionary containing a "recos" list, which will be
113 // passed to LoadFromListValue(). 128 // passed to LoadFromListValue().
114 bool LoadFromValue(const base::Value& value); 129 bool LoadFromValue(const base::Value& value);
115 130
116 // Expects a list of dictionaries each containing a "contentInfo" dictionary 131 // Expects a list of dictionaries each containing a "contentInfo" dictionary
117 // with keys matching the properties of a snippet (url, title, site_title, 132 // with keys matching the properties of a snippet (url, title, site_title,
118 // etc...). The URL is the only mandatory value. 133 // etc...). The URL is the only mandatory value.
119 bool LoadFromListValue(const base::ListValue& list); 134 bool LoadFromListValue(const base::ListValue& list);
120 135
121 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite? 136 // 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. 201 // Sent when the service is shutting down.
187 virtual void NTPSnippetsServiceShutdown() = 0; 202 virtual void NTPSnippetsServiceShutdown() = 0;
188 203
189 protected: 204 protected:
190 virtual ~NTPSnippetsServiceObserver() {} 205 virtual ~NTPSnippetsServiceObserver() {}
191 }; 206 };
192 207
193 } // namespace ntp_snippets 208 } // namespace ntp_snippets
194 209
195 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 210 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698