OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/suggestions/suggestions_service_impl.h" | 5 #include "components/suggestions/suggestions_service_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "components/data_use_measurement/core/data_use_user_data.h" | 20 #include "components/data_use_measurement/core/data_use_user_data.h" |
21 #include "components/google/core/browser/google_util.h" | 21 #include "components/google/core/browser/google_util.h" |
22 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
23 #include "components/signin/core/browser/signin_manager_base.h" | 23 #include "components/signin/core/browser/signin_manager_base.h" |
24 #include "components/suggestions/blacklist_store.h" | 24 #include "components/suggestions/blacklist_store.h" |
25 #include "components/suggestions/features.h" | |
25 #include "components/suggestions/image_manager.h" | 26 #include "components/suggestions/image_manager.h" |
26 #include "components/suggestions/suggestions_store.h" | 27 #include "components/suggestions/suggestions_store.h" |
27 #include "components/sync/driver/sync_service.h" | 28 #include "components/sync/driver/sync_service.h" |
28 #include "components/variations/net/variations_http_headers.h" | 29 #include "components/variations/net/variations_http_headers.h" |
29 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
30 #include "google_apis/gaia/oauth2_token_service.h" | 31 #include "google_apis/gaia/oauth2_token_service.h" |
31 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
32 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
34 #include "net/base/url_util.h" | 35 #include "net/base/url_util.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 GURL GetGoogleBaseURL() { | 107 GURL GetGoogleBaseURL() { |
107 GURL url(google_util::CommandLineGoogleBaseURL()); | 108 GURL url(google_util::CommandLineGoogleBaseURL()); |
108 if (url.is_valid()) | 109 if (url.is_valid()) |
109 return url; | 110 return url; |
110 return GURL(kDefaultGoogleBaseURL); | 111 return GURL(kDefaultGoogleBaseURL); |
111 } | 112 } |
112 | 113 |
113 // Format strings for the various suggestions URLs. They all have two string | 114 // Format strings for the various suggestions URLs. They all have two string |
114 // params: The Google base URL and the device type. | 115 // params: The Google base URL and the device type. |
115 // TODO(mathp): Put this in TemplateURL. | 116 // TODO(mathp): Put this in TemplateURL. |
116 const char kSuggestionsURLFormat[] = "%schromesuggestions?t=%s"; | 117 const char kSuggestionsURLFormat[] = "%schromesuggestions?%st=%s"; |
117 const char kSuggestionsBlacklistURLPrefixFormat[] = | 118 const char kSuggestionsBlacklistURLPrefixFormat[] = |
118 "%schromesuggestions/blacklist?t=%s&url="; | 119 "%schromesuggestions/blacklist?t=%s&url="; |
119 const char kSuggestionsBlacklistClearURLFormat[] = | 120 const char kSuggestionsBlacklistClearURLFormat[] = |
120 "%schromesuggestions/blacklist/clear?t=%s"; | 121 "%schromesuggestions/blacklist/clear?t=%s"; |
121 | 122 |
122 const char kSuggestionsBlacklistURLParam[] = "url"; | 123 const char kSuggestionsBlacklistURLParam[] = "url"; |
124 const char kSuggestionsUseAllParam[] = "all&"; | |
Marc Treib
2017/05/08 14:26:04
Hm, I'm not a fan of "hiding" the "&" in here. IMO
fhorschig
2017/05/10 09:51:16
Done.
| |
123 | 125 |
124 #if defined(OS_ANDROID) || defined(OS_IOS) | 126 #if defined(OS_ANDROID) || defined(OS_IOS) |
125 const char kDeviceType[] = "2"; | 127 const char kDeviceType[] = "2"; |
126 #else | 128 #else |
127 const char kDeviceType[] = "1"; | 129 const char kDeviceType[] = "1"; |
128 #endif | 130 #endif |
129 | 131 |
130 // Format string for OAuth2 authentication headers. | 132 // Format string for OAuth2 authentication headers. |
131 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 133 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
132 | 134 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 // static | 272 // static |
271 void SuggestionsServiceImpl::RegisterProfilePrefs( | 273 void SuggestionsServiceImpl::RegisterProfilePrefs( |
272 user_prefs::PrefRegistrySyncable* registry) { | 274 user_prefs::PrefRegistrySyncable* registry) { |
273 SuggestionsStore::RegisterProfilePrefs(registry); | 275 SuggestionsStore::RegisterProfilePrefs(registry); |
274 BlacklistStore::RegisterProfilePrefs(registry); | 276 BlacklistStore::RegisterProfilePrefs(registry); |
275 } | 277 } |
276 | 278 |
277 // static | 279 // static |
278 GURL SuggestionsServiceImpl::BuildSuggestionsURL() { | 280 GURL SuggestionsServiceImpl::BuildSuggestionsURL() { |
279 return GURL(base::StringPrintf( | 281 return GURL(base::StringPrintf( |
280 kSuggestionsURLFormat, GetGoogleBaseURL().spec().c_str(), kDeviceType)); | 282 kSuggestionsURLFormat, GetGoogleBaseURL().spec().c_str(), |
283 base::FeatureList::IsEnabled(kUseSuggestionsEvenIfFewFeature) | |
284 ? kSuggestionsUseAllParam | |
285 : "", | |
286 kDeviceType)); | |
281 } | 287 } |
282 | 288 |
283 // static | 289 // static |
284 std::string SuggestionsServiceImpl::BuildSuggestionsBlacklistURLPrefix() { | 290 std::string SuggestionsServiceImpl::BuildSuggestionsBlacklistURLPrefix() { |
285 return base::StringPrintf(kSuggestionsBlacklistURLPrefixFormat, | 291 return base::StringPrintf(kSuggestionsBlacklistURLPrefixFormat, |
286 GetGoogleBaseURL().spec().c_str(), kDeviceType); | 292 GetGoogleBaseURL().spec().c_str(), kDeviceType); |
287 } | 293 } |
288 | 294 |
289 // static | 295 // static |
290 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistURL( | 296 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistURL( |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); | 565 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); |
560 } else { | 566 } else { |
561 TimeDelta candidate_delay = | 567 TimeDelta candidate_delay = |
562 scheduling_delay_ * kSchedulingBackoffMultiplier; | 568 scheduling_delay_ * kSchedulingBackoffMultiplier; |
563 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) | 569 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) |
564 scheduling_delay_ = candidate_delay; | 570 scheduling_delay_ = candidate_delay; |
565 } | 571 } |
566 } | 572 } |
567 | 573 |
568 } // namespace suggestions | 574 } // namespace suggestions |
OLD | NEW |