Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_service.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc |
| index 38c98f199319b6398624718deb225e539524eac1..c5f321c3a6bbaf088cf96218d643979029b50fa1 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service.cc |
| +++ b/components/ntp_snippets/ntp_snippets_service.cc |
| @@ -4,9 +4,6 @@ |
| #include "components/ntp_snippets/ntp_snippets_service.h" |
| -#include <algorithm> |
| -#include <utility> |
|
Marc Treib
2016/04/13 08:45:52
I think these two should stay, for std::find_if an
jkrcal
2016/04/14 15:27:00
Done.
|
| - |
| #include "base/command_line.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| @@ -68,7 +65,7 @@ base::TimeDelta GetFetchingIntervalFallback() { |
| } |
| // Extracts the hosts from |suggestions| and returns them in a set. |
| -std::set<std::string> GetSuggestionsHosts( |
| +std::set<std::string> GetSuggestionsHostsImpl( |
| const SuggestionsProfile& suggestions) { |
| std::set<std::string> hosts; |
| for (int i = 0; i < suggestions.suggestions_size(); ++i) { |
| @@ -186,8 +183,32 @@ void NTPSnippetsService::FetchSnippets() { |
| if (!suggestions_service_) |
| return; |
| - FetchSnippetsImpl(GetSuggestionsHosts( |
| - suggestions_service_->GetSuggestionsDataFromCache())); |
| + FetchSnippetsFromHosts(GetSuggestionsHosts()); |
| +} |
| + |
| +void NTPSnippetsService::FetchSnippetsFromHosts( |
| + const std::set<std::string>& hosts) { |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDontRestrict)) { |
| + snippets_fetcher_->FetchSnippets(std::set<std::string>()); |
| + return; |
| + } |
| + if (!hosts.empty()) |
| + snippets_fetcher_->FetchSnippets(hosts); |
| +} |
| + |
| +void NTPSnippetsService::ClearSnippets() { |
| + snippets_.clear(); |
| + |
| + StoreSnippetsToPrefs(); |
| + |
| + FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| + NTPSnippetsServiceLoaded()); |
| +} |
| + |
| +std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() { |
| + return GetSuggestionsHostsImpl( |
| + suggestions_service_->GetSuggestionsDataFromCache()); |
|
Marc Treib
2016/04/13 08:45:52
Can you please add a "TODO(treib)" saying that thi
jkrcal
2016/04/14 15:27:00
Done.
|
| } |
| bool NTPSnippetsService::DiscardSnippet(const GURL& url) { |
| @@ -201,9 +222,22 @@ bool NTPSnippetsService::DiscardSnippet(const GURL& url) { |
| snippets_.erase(it); |
| StoreDiscardedSnippetsToPrefs(); |
| StoreSnippetsToPrefs(); |
| + FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| + NTPSnippetsServiceLoaded()); |
|
Marc Treib
2016/04/13 08:45:52
misaligned
jkrcal
2016/04/14 15:27:00
Done.
|
| return true; |
| } |
| +const NTPSnippetsService::NTPSnippetStorage& |
| +NTPSnippetsService::GetDiscardedSnippets() { |
| + return discarded_snippets_; |
| +} |
| + |
| +void NTPSnippetsService::ClearDiscardedSnippets() { |
| + discarded_snippets_.clear(); |
| + StoreDiscardedSnippetsToPrefs(); |
| + FetchSnippets(); |
| +} |
| + |
| void NTPSnippetsService::AddObserver(NTPSnippetsServiceObserver* observer) { |
| observers_.AddObserver(observer); |
| observer->NTPSnippetsServiceLoaded(); |
| @@ -215,7 +249,7 @@ void NTPSnippetsService::RemoveObserver(NTPSnippetsServiceObserver* observer) { |
| void NTPSnippetsService::OnSuggestionsChanged( |
| const SuggestionsProfile& suggestions) { |
| - std::set<std::string> hosts = GetSuggestionsHosts(suggestions); |
| + std::set<std::string> hosts = GetSuggestionsHostsImpl(suggestions); |
| if (hosts == GetSnippetHostsFromPrefs()) |
| return; |
| @@ -233,7 +267,7 @@ void NTPSnippetsService::OnSuggestionsChanged( |
| FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_, |
| NTPSnippetsServiceLoaded()); |
| - FetchSnippetsImpl(hosts); |
| + FetchSnippetsFromHosts(hosts); |
| } |
| void NTPSnippetsService::OnSnippetsDownloaded( |
| @@ -256,17 +290,6 @@ void NTPSnippetsService::OnJsonError(const std::string& snippets_json, |
| LOG(WARNING) << "Received invalid JSON (" << error << "): " << snippets_json; |
| } |
| -void NTPSnippetsService::FetchSnippetsImpl( |
| - const std::set<std::string>& hosts) { |
| - if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kDontRestrict)) { |
| - snippets_fetcher_->FetchSnippets(std::set<std::string>()); |
| - return; |
| - } |
| - if (!hosts.empty()) |
| - snippets_fetcher_->FetchSnippets(hosts); |
| -} |
| - |
| bool NTPSnippetsService::LoadFromValue(const base::Value& value) { |
| const base::DictionaryValue* top_dict = nullptr; |
| if (!value.GetAsDictionary(&top_dict)) |