Commit c1fc3547 authored by Kristi Park's avatar Kristi Park Committed by Commit Bot

[NTP] Undoing the first custom link action will uninitialize custom links

Undoing the first custom link action (i.e. the action that initializes
custom links) will now uninitialize custom links.
Screencast: https://screencast.googleplex.com/cast/NTM5NDQzOTE1MzM4NTQ3Mnw3MDNkZTY0Yy1hZQ

Bug: 881256
Change-Id: I8d77fef71b581d5b6b81ce369d21afd8eb717c31
Reviewed-on: https://chromium-review.googlesource.com/c/1272137
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599394}
parent efbd9084
......@@ -309,11 +309,8 @@ void InstantService::UndoAllMostVisitedDeletions() {
}
bool InstantService::AddCustomLink(const GURL& url, const std::string& title) {
if (most_visited_sites_) {
// Initializes custom links if they have not been initialized yet.
most_visited_sites_->InitializeCustomLinks();
if (most_visited_sites_)
return most_visited_sites_->AddCustomLink(url, base::UTF8ToUTF16(title));
}
return false;
}
......@@ -321,8 +318,6 @@ bool InstantService::UpdateCustomLink(const GURL& url,
const GURL& new_url,
const std::string& new_title) {
if (most_visited_sites_) {
// Initializes custom links if they have not been initialized yet.
most_visited_sites_->InitializeCustomLinks();
return most_visited_sites_->UpdateCustomLink(url, new_url,
base::UTF8ToUTF16(new_title));
}
......@@ -330,11 +325,8 @@ bool InstantService::UpdateCustomLink(const GURL& url,
}
bool InstantService::DeleteCustomLink(const GURL& url) {
if (most_visited_sites_) {
// Initializes custom links if they have not been initialized yet.
most_visited_sites_->InitializeCustomLinks();
if (most_visited_sites_)
return most_visited_sites_->DeleteCustomLink(url);
}
return false;
}
......
......@@ -252,14 +252,17 @@ void MostVisitedSites::InitializeCustomLinks() {
if (!custom_links_ || !current_tiles_.has_value() || !custom_links_enabled_)
return;
if (custom_links_->Initialize(current_tiles_.value()))
if (custom_links_->Initialize(current_tiles_.value())) {
custom_links_action_count_ = 0;
BuildCurrentTiles();
}
}
void MostVisitedSites::UninitializeCustomLinks() {
if (!custom_links_ || !custom_links_enabled_)
return;
custom_links_action_count_ = -1;
custom_links_->Uninitialize();
BuildCurrentTiles();
Refresh();
......@@ -284,9 +287,15 @@ bool MostVisitedSites::AddCustomLink(const GURL& url,
if (!custom_links_ || !custom_links_enabled_)
return false;
// Initialize custom links if they have not been initialized yet.
InitializeCustomLinks();
bool success = custom_links_->AddLink(url, title);
if (success)
if (success) {
if (custom_links_action_count_ != -1)
custom_links_action_count_++;
BuildCurrentTiles();
}
return success;
}
......@@ -296,9 +305,15 @@ bool MostVisitedSites::UpdateCustomLink(const GURL& url,
if (!custom_links_ || !custom_links_enabled_)
return false;
// Initialize custom links if they have not been initialized yet.
InitializeCustomLinks();
bool success = custom_links_->UpdateLink(url, new_url, new_title);
if (success)
if (success) {
if (custom_links_action_count_ != -1)
custom_links_action_count_++;
BuildCurrentTiles();
}
return success;
}
......@@ -306,9 +321,15 @@ bool MostVisitedSites::DeleteCustomLink(const GURL& url) {
if (!custom_links_ || !custom_links_enabled_)
return false;
// Initialize custom links if they have not been initialized yet.
InitializeCustomLinks();
bool success = custom_links_->DeleteLink(url);
if (success)
if (success) {
if (custom_links_action_count_ != -1)
custom_links_action_count_++;
BuildCurrentTiles();
}
return success;
}
......@@ -316,7 +337,11 @@ void MostVisitedSites::UndoCustomLinkAction() {
if (!custom_links_ || !custom_links_enabled_)
return;
if (custom_links_->UndoAction())
// If this is undoing the first action after initialization, uninitialize
// custom links.
if (custom_links_action_count_-- == 1)
UninitializeCustomLinks();
else if (custom_links_->UndoAction())
BuildCurrentTiles();
}
......
......@@ -174,21 +174,25 @@ class MostVisitedSites : public history::TopSitesObserver,
// when a third-party NTP is being used.
void EnableCustomLinks(bool enable);
// Adds a custom link. If the number of current links is maxed, returns false
// and does nothing. Custom links must be enabled.
// and does nothing. Will initialize custom links if they have not been
// initialized yet. Custom links must be enabled.
bool AddCustomLink(const GURL& url, const base::string16& title);
// Updates the URL and/or title of the custom link specified by |url|. If
// |url| does not exist or |new_url| already exists in the custom link list,
// returns false and does nothing. Custom links must be enabled.
// returns false and does nothing. Will initialize custom links if they have
// not been initialized yet. Custom links must be enabled.
bool UpdateCustomLink(const GURL& url,
const GURL& new_url,
const base::string16& new_title);
// Deletes the custom link with the specified |url|. If |url| does not exist
// in the custom link list, returns false and does nothing. Custom links must
// be enabled.
// in the custom link list, returns false and does nothing. Will initialize
// custom links if they have not been initialized yet. Custom links must be
// enabled.
bool DeleteCustomLink(const GURL& url);
// Restores the previous state of custom links before the last action that
// modified them. If there was no action, does nothing. Custom links must be
// enabled.
// modified them. If there was no action, does nothing. If this is undoing the
// first action after initialization, uninitializes the links. Custom links
// must be enabled.
void UndoCustomLinkAction();
void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
......@@ -327,6 +331,9 @@ class MostVisitedSites : public history::TopSitesObserver,
// False if custom links is disabled and Most Visited sites should be returned
// instead.
bool custom_links_enabled_ = true;
// Number of actions after custom link initialization. Set to -1 and not
// incremented if custom links was not initialized during this session.
int custom_links_action_count_ = -1;
std::unique_ptr<
suggestions::SuggestionsService::ResponseCallbackList::Subscription>
......
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