| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include "components/ntp_snippets/breaking_news/subscription_json_request.h" | 8 #include "components/ntp_snippets/breaking_news/subscription_json_request.h" |
| 9 #include "components/prefs/pref_registry_simple.h" | 9 #include "components/prefs/pref_registry_simple.h" |
| 10 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 class PrefRegistrySimple; | 13 class PrefRegistrySimple; |
| 14 | 14 |
| 15 namespace ntp_snippets { | 15 namespace ntp_snippets { |
| 16 | 16 |
| 17 // Class that wraps around the functionality of SubscriptionJsonRequest. It uses |
| 18 // the SubscriptionJsonRequest to send subscription and unsubscription requests |
| 19 // to the content suggestions server and does the bookkeeping for the data used |
| 20 // for subscription. Bookkeeping is required to detect any change (e.g. the |
| 21 // token render invalid), and resubscribe accordingly. |
| 17 class SubscriptionManager { | 22 class SubscriptionManager { |
| 18 public: | 23 public: |
| 19 SubscriptionManager( | 24 SubscriptionManager( |
| 20 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 25 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 21 PrefService* pref_service, | 26 PrefService* pref_service, |
| 22 const GURL& subscribe_url); | 27 const GURL& subscribe_url, |
| 28 const GURL& unsubscribe_url); |
| 23 | 29 |
| 24 ~SubscriptionManager(); | 30 ~SubscriptionManager(); |
| 25 | 31 |
| 26 void Subscribe(const std::string& token); | 32 void Subscribe(const std::string& token); |
| 33 bool CanSubscribeNow(); |
| 27 void Unsubscribe(const std::string& token); | 34 void Unsubscribe(const std::string& token); |
| 35 bool CanUnsubscribeNow(); |
| 36 bool IsSubscribed(); |
| 28 | 37 |
| 29 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 38 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 30 | 39 |
| 31 private: | 40 private: |
| 32 std::string subscription_token_; | 41 std::string subscription_token_; |
| 42 std::string unsubscription_token_; |
| 33 | 43 |
| 34 // Holds the URL request context. | 44 // Holds the URL request context. |
| 35 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 45 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 36 | 46 |
| 37 std::unique_ptr<internal::SubscriptionJsonRequest> subscription_request_; | 47 std::unique_ptr<internal::SubscriptionJsonRequest> subscription_request_; |
| 48 std::unique_ptr<internal::SubscriptionJsonRequest> unsubscription_request_; |
| 38 | 49 |
| 39 PrefService* pref_service_; | 50 PrefService* pref_service_; |
| 40 | 51 |
| 41 // API endpoint for subscribing. | 52 // API endpoint for subscribing and unsubscribing. |
| 42 const GURL subscribe_url_; | 53 const GURL subscribe_url_; |
| 54 const GURL unsubscribe_url_; |
| 43 | 55 |
| 44 void DidSubscribe(const ntp_snippets::Status& status); | 56 void DidSubscribe(const ntp_snippets::Status& status); |
| 57 void DidUnsubscribe(const ntp_snippets::Status& status); |
| 45 | 58 |
| 46 DISALLOW_COPY_AND_ASSIGN(SubscriptionManager); | 59 DISALLOW_COPY_AND_ASSIGN(SubscriptionManager); |
| 47 }; | 60 }; |
| 48 } | 61 } |
| 49 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ | 62 #endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_SUBSCRIPTION_MANAGER_H_ |
| OLD | NEW |