Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: components/ntp_snippets/breaking_news/subscription_manager.cc

Issue 2925053003: [NTP::Push] Adding BreakingNewsSuggestionsProvider (Closed)
Patch Set: sfiera@ comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/ntp_snippets/breaking_news/subscription_manager.h" 5 #include "components/ntp_snippets/breaking_news/subscription_manager.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "components/ntp_snippets/breaking_news/subscription_json_request.h" 7 #include "components/ntp_snippets/breaking_news/subscription_json_request.h"
8 #include "components/ntp_snippets/features.h"
9 #include "components/ntp_snippets/ntp_snippets_constants.h"
8 #include "components/ntp_snippets/pref_names.h" 10 #include "components/ntp_snippets/pref_names.h"
9 #include "components/prefs/pref_service.h" 11 #include "components/prefs/pref_service.h"
12 #include "components/variations/variations_associated_data.h"
jkrcal 2017/06/09 11:32:59 please use the new api, instead: base/metrics/fie
mamir 2017/06/09 14:41:01 Done.
10 13
11 namespace ntp_snippets { 14 namespace ntp_snippets {
12 15
13 using internal::SubscriptionJsonRequest; 16 using internal::SubscriptionJsonRequest;
14 17
18 namespace {
19
20 // Variation parameter for chrome-push-subscription backend.
21 const char kPushSubscriptionBackend[] = "push_subscription_backend";
jkrcal 2017/06/09 11:32:59 consistency nit: Can you name it kPushSubscription
mamir 2017/06/09 14:41:01 Done.
22
23 // Variation parameter for chrome-push-unsubscription backend.
24 const char kPushUnsubscriptionBackend[] = "push_unsubscription_backend";
jkrcal 2017/06/09 11:32:59 ditto
mamir 2017/06/09 14:41:01 Done.
25 }
26
15 SubscriptionManager::SubscriptionManager( 27 SubscriptionManager::SubscriptionManager(
16 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 28 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
17 PrefService* pref_service, 29 PrefService* pref_service,
18 const GURL& subscribe_url, 30 const GURL& subscribe_url,
19 const GURL& unsubscribe_url) 31 const GURL& unsubscribe_url)
20 : url_request_context_getter_(std::move(url_request_context_getter)), 32 : url_request_context_getter_(std::move(url_request_context_getter)),
21 pref_service_(pref_service), 33 pref_service_(pref_service),
22 subscribe_url_(subscribe_url), 34 subscribe_url_(subscribe_url),
23 unsubscribe_url_(unsubscribe_url) {} 35 unsubscribe_url_(unsubscribe_url) {}
24 36
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 default: 94 default:
83 // TODO(mamir): handle failure. 95 // TODO(mamir): handle failure.
84 break; 96 break;
85 } 97 }
86 } 98 }
87 99
88 void SubscriptionManager::RegisterProfilePrefs(PrefRegistrySimple* registry) { 100 void SubscriptionManager::RegisterProfilePrefs(PrefRegistrySimple* registry) {
89 registry->RegisterStringPref(prefs::kContentSuggestionsSubscriptionDataToken, 101 registry->RegisterStringPref(prefs::kContentSuggestionsSubscriptionDataToken,
90 std::string()); 102 std::string());
91 } 103 }
104
105 GURL GetPushUpdatesSubscriptionEndpoint(version_info::Channel channel) {
106 std::string endpoint = variations::GetVariationParamValueByFeature(
jkrcal 2017/06/09 11:32:59 Please use the new API with the same parameters: b
mamir 2017/06/09 14:41:01 Done.
107 ntp_snippets::kContentSuggestionsPushFeature, kPushSubscriptionBackend);
108 if (!endpoint.empty()) {
109 return GURL{endpoint};
110 }
111
112 switch (channel) {
113 case version_info::Channel::STABLE:
114 case version_info::Channel::BETA:
115 return GURL{kPushUpdatesSubscriptionServer};
116
117 case version_info::Channel::DEV:
118 case version_info::Channel::CANARY:
119 case version_info::Channel::UNKNOWN:
120 return GURL{kPushUpdatesSubscriptionStagingServer};
121 }
122 NOTREACHED();
123 return GURL{kPushUpdatesSubscriptionStagingServer};
124 }
125
126 GURL GetPushUpdatesUnsubscriptionEndpoint(version_info::Channel channel) {
127 std::string endpoint = variations::GetVariationParamValueByFeature(
jkrcal 2017/06/09 11:32:59 ditto
mamir 2017/06/09 14:41:01 Done.
128 ntp_snippets::kContentSuggestionsPushFeature, kPushUnsubscriptionBackend);
129 if (!endpoint.empty()) {
130 return GURL{endpoint};
131 }
132
133 switch (channel) {
134 case version_info::Channel::STABLE:
135 case version_info::Channel::BETA:
136 return GURL{kPushUpdatesUnsubscriptionServer};
137
138 case version_info::Channel::DEV:
139 case version_info::Channel::CANARY:
140 case version_info::Channel::UNKNOWN:
141 return GURL{kPushUpdatesUnsubscriptionStagingServer};
142 }
143 NOTREACHED();
144 return GURL{kPushUpdatesUnsubscriptionStagingServer};
145 }
92 } // namespace ntp_snippets 146 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698