Chromium Code Reviews| Index: components/ntp_snippets/breaking_news/subscription_manager.cc |
| diff --git a/components/ntp_snippets/breaking_news/subscription_manager.cc b/components/ntp_snippets/breaking_news/subscription_manager.cc |
| index 8f7dbc9a5b3f6f399f4fa12af234b4ab7530c5f3..01570be2ddee0274479c51c5cc5162a0bc0d146b 100644 |
| --- a/components/ntp_snippets/breaking_news/subscription_manager.cc |
| +++ b/components/ntp_snippets/breaking_news/subscription_manager.cc |
| @@ -15,10 +15,12 @@ using internal::SubscriptionJsonRequest; |
| SubscriptionManager::SubscriptionManager( |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| PrefService* pref_service, |
| - const GURL& subscribe_url) |
| + const GURL& subscribe_url, |
| + const GURL& unsubscribe_url) |
| : url_request_context_getter_(std::move(url_request_context_getter)), |
| pref_service_(pref_service), |
| - subscribe_url_(subscribe_url) {} |
| + subscribe_url_(subscribe_url), |
| + unsubscribe_url_(unsubscribe_url) {} |
| SubscriptionManager::~SubscriptionManager() = default; |
| @@ -55,7 +57,32 @@ void SubscriptionManager::DidSubscribe(const ntp_snippets::Status& status) { |
| } |
| void SubscriptionManager::Unsubscribe(const std::string& token) { |
| - // TODO(mamir): Implement. |
| + DCHECK(!unsubscription_request_); |
|
jkrcal
2017/06/09 09:10:10
I find this (and above) a bit subtle to use:
It is
mamir
2017/06/09 13:52:58
As discussed off-review, I have added 3 methods Ca
|
| + unsubscription_token_ = token; |
| + SubscriptionJsonRequest::Builder builder; |
| + builder.SetToken(token) |
| + .SetUrlRequestContextGetter(url_request_context_getter_) |
| + .SetUrl(unsubscribe_url_); |
| + |
| + unsubscription_request_ = builder.Build(); |
| + unsubscription_request_->Start(base::BindOnce( |
| + &SubscriptionManager::DidUnsubscribe, base::Unretained(this))); |
| +} |
| + |
| +void SubscriptionManager::DidUnsubscribe(const ntp_snippets::Status& status) { |
| + unsubscription_request_.reset(); |
| + |
| + switch (status.code) { |
| + case ntp_snippets::StatusCode::SUCCESS: |
| + // In case of successful unsubscription, clear the previously stored data. |
| + // TODO(mamir): clear stored region and language. |
| + pref_service_->ClearPref( |
| + ntp_snippets::prefs::kContentSuggestionsSubscriptionDataToken); |
| + break; |
| + default: |
| + // TODO(mamir): handle failure. |
| + break; |
| + } |
| } |
| void SubscriptionManager::RegisterProfilePrefs(PrefRegistrySimple* registry) { |