Commit bc1a4e27 authored by johnme's avatar johnme Committed by Commit bot

Revert of Support server categories in NTPSnippetsService. (patchset #3...

Revert of Support server categories in NTPSnippetsService. (patchset #3 id:40001 of https://codereview.chromium.org/2279863002/ )

Reason for revert:
I'm afraid this failed again on
https://build.chromium.org/p/chromium.mac/builders/Mac10.9%20Tests/builds/27385/steps/components_unittests%20on%20Mac-10.9

Original issue's description:
> Support server categories in NTPSnippetsService.
>
> Reland of:
> https://crrev.com/330958ddcdcd0084d724571eddaa66f9c364115f
>
> Not clear why tests failed; they passed for me and in the CQ.
> Removed one synchronization bit that wasn't really part of the change.
>
> BUG=633613
>
> Committed: https://crrev.com/880bb766ee4985a8dd36be10098c5196c41f7509
> Cr-Commit-Position: refs/heads/master@{#414681}

TBR=treib@chromium.org,sfiera@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=633613

Review-Url: https://codereview.chromium.org/2283743002
Cr-Commit-Position: refs/heads/master@{#414686}
parent a5cd9c49
......@@ -651,7 +651,6 @@ void NTPSnippetsFetcher::FetchFinished(OptionalSnippets snippets,
static_cast<int>(result),
static_cast<int>(FetchResult::RESULT_MAX));
DVLOG(1) << "Fetch finished: " << last_status_;
if (!snippets_available_callback_.is_null())
snippets_available_callback_.Run(std::move(snippets));
}
......
......@@ -153,8 +153,8 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
static int GetMaxSnippetCountForTesting();
// Available snippets, only for unit tests.
const NTPSnippet::PtrVector& GetSnippetsForTesting(Category category) const {
return categories_.find(category)->second.snippets;
const NTPSnippet::PtrVector& GetSnippetsForTesting() const {
return snippets_;
}
private:
......@@ -222,7 +222,7 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets);
// Merges newly available snippets with the previously available list.
void MergeSnippets(Category category, NTPSnippet::PtrVector new_snippets);
void MergeSnippets(NTPSnippet::PtrVector new_snippets);
std::set<std::string> GetSnippetHostsFromPrefs() const;
void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
......@@ -239,18 +239,18 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
void FinishInitialization();
void OnSnippetImageFetchedFromDatabase(const ImageFetchedCallback& callback,
const std::string& suggestion_id,
const std::string& snippet_id,
std::string data);
void OnSnippetImageDecodedFromDatabase(const ImageFetchedCallback& callback,
const std::string& suggestion_id,
const std::string& snippet_id,
const gfx::Image& image);
void FetchSnippetImageFromNetwork(const std::string& suggestion_id,
void FetchSnippetImageFromNetwork(const std::string& snippet_id,
const ImageFetchedCallback& callback);
void OnSnippetImageDecodedFromNetwork(const ImageFetchedCallback& callback,
const std::string& suggestion_id,
const std::string& snippet_id,
const gfx::Image& image);
// Triggers a state transition depending on the provided reason to be
......@@ -261,7 +261,7 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
// Verifies state transitions (see |State|'s documentation) and applies them.
// Also updates the provider status. Does nothing except updating the provider
// status if called with the current state.
void EnterState(State state);
void EnterState(State state, CategoryStatus status);
// Enables the service and triggers a fetch if required. Do not call directly,
// use |EnterState| instead.
......@@ -278,42 +278,24 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
// the observers.
void NotifyNewSuggestions();
// Updates the internal status for |category| to |category_status_| and
// notifies the content suggestions observer if it changed.
void UpdateCategoryStatus(Category category, CategoryStatus status);
// Calls UpdateCategoryStatus() for all provided categories.
void UpdateAllCategoryStatus(CategoryStatus status);
// Updates the internal status |category_status_| and notifies the content
// suggestions observer if it changed.
void UpdateCategoryStatus(CategoryStatus status);
State state_;
CategoryStatus category_status_;
PrefService* pref_service_;
suggestions::SuggestionsService* suggestions_service_;
const Category articles_category_;
struct CategoryContent {
CategoryStatus status = CategoryStatus::INITIALIZING;
// True iff the server returned results in this category in the last fetch.
// We never remove categories that the server still provides, but if the
// server stops providing a category, we won't yet report it as NOT_PROVIDED
// while we still have non-expired snippets in it.
bool provided_by_server = true;
// All current suggestions (i.e. not dismissed ones).
NTPSnippet::PtrVector snippets;
// All current suggestions (i.e. not dismissed ones).
NTPSnippet::PtrVector snippets_;
// Suggestions that the user dismissed. We keep these around until they
// expire so we won't re-add them on the next fetch.
NTPSnippet::PtrVector dismissed;
CategoryContent(); // = default, in .cc
CategoryContent(CategoryContent&&); // = default, in .cc
~CategoryContent(); // = default, in .cc
CategoryContent& operator=(CategoryContent&&); // = default, in .cc
};
std::map<Category, CategoryContent, Category::CompareByID> categories_;
// Suggestions that the user dismissed. We keep these around until they expire
// so we won't re-add them on the next fetch.
NTPSnippet::PtrVector dismissed_snippets_;
// The ISO 639-1 code of the language used by the application.
const std::string application_language_code_;
......@@ -356,6 +338,8 @@ class NTPSnippetsService : public ContentSuggestionsProvider,
// loaded. The nuke will be executed after the database load finishes.
bool nuke_after_load_;
const Category provided_category_;
// Request throttler for limiting requests to thumbnail images.
RequestThrottler thumbnail_requests_throttler_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment