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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 GURL GetGoogleBaseURL() { | 76 GURL GetGoogleBaseURL() { |
76 GURL url(google_util::CommandLineGoogleBaseURL()); | 77 GURL url(google_util::CommandLineGoogleBaseURL()); |
77 if (url.is_valid()) | 78 if (url.is_valid()) |
78 return url; | 79 return url; |
79 return GURL(kDefaultGoogleBaseURL); | 80 return GURL(kDefaultGoogleBaseURL); |
80 } | 81 } |
81 | 82 |
82 // Format strings for the various suggestions URLs. They all have two string | 83 // Format strings for the various suggestions URLs. They all have two string |
83 // params: The Google base URL and the device type. | 84 // params: The Google base URL and the device type. |
84 // TODO(mathp): Put this in TemplateURL. | 85 // TODO(mathp): Put this in TemplateURL. |
85 const char kSuggestionsURLFormat[] = "%schromesuggestions?t=%s"; | 86 const char kSuggestionsURLFormat[] = "%schromesuggestions?%s"; |
86 const char kSuggestionsBlacklistURLPrefixFormat[] = | 87 const char kSuggestionsBlacklistURLPrefixFormat[] = |
87 "%schromesuggestions/blacklist?t=%s&url="; | 88 "%schromesuggestions/blacklist?t=%s&url="; |
88 const char kSuggestionsBlacklistClearURLFormat[] = | 89 const char kSuggestionsBlacklistClearURLFormat[] = |
89 "%schromesuggestions/blacklist/clear?t=%s"; | 90 "%schromesuggestions/blacklist/clear?t=%s"; |
90 | 91 |
91 const char kSuggestionsBlacklistURLParam[] = "url"; | 92 const char kSuggestionsBlacklistURLParam[] = "url"; |
93 const char kSuggestionsDeviceParam[] = "t=%s"; | |
94 const char kSuggestionsUseAllParam[] = "min=0"; | |
Marc Treib
2017/05/10 10:08:02
The "0" should probably be configurable via a vari
fhorschig
2017/05/10 12:25:30
Hmm, okay. I currently see no application, though.
Marc Treib
2017/05/10 12:32:24
You never do, until you need it :D
Seriously thoug
fhorschig
2017/05/10 12:45:34
It has direct a direct effect on the server-side.
| |
92 | 95 |
93 #if defined(OS_ANDROID) || defined(OS_IOS) | 96 #if defined(OS_ANDROID) || defined(OS_IOS) |
94 const char kDeviceType[] = "2"; | 97 const char kDeviceType[] = "2"; |
95 #else | 98 #else |
96 const char kDeviceType[] = "1"; | 99 const char kDeviceType[] = "1"; |
97 #endif | 100 #endif |
98 | 101 |
99 // Format string for OAuth2 authentication headers. | 102 // Format string for OAuth2 authentication headers. |
100 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; | 103 const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
101 | 104 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 244 |
242 // static | 245 // static |
243 void SuggestionsServiceImpl::RegisterProfilePrefs( | 246 void SuggestionsServiceImpl::RegisterProfilePrefs( |
244 user_prefs::PrefRegistrySyncable* registry) { | 247 user_prefs::PrefRegistrySyncable* registry) { |
245 SuggestionsStore::RegisterProfilePrefs(registry); | 248 SuggestionsStore::RegisterProfilePrefs(registry); |
246 BlacklistStore::RegisterProfilePrefs(registry); | 249 BlacklistStore::RegisterProfilePrefs(registry); |
247 } | 250 } |
248 | 251 |
249 // static | 252 // static |
250 GURL SuggestionsServiceImpl::BuildSuggestionsURL() { | 253 GURL SuggestionsServiceImpl::BuildSuggestionsURL() { |
254 std::string query = base::StringPrintf(kSuggestionsDeviceParam, kDeviceType); | |
255 if (base::FeatureList::IsEnabled(kUseSuggestionsEvenIfFewFeature)) { | |
256 query = base::StringPrintf("%s&%s", query.c_str(), kSuggestionsUseAllParam); | |
Marc Treib
2017/05/10 10:08:02
nit: I find this a bit confusing. Maybe don't reus
fhorschig
2017/05/10 12:25:30
Done.
| |
257 } | |
251 return GURL(base::StringPrintf( | 258 return GURL(base::StringPrintf( |
252 kSuggestionsURLFormat, GetGoogleBaseURL().spec().c_str(), kDeviceType)); | 259 kSuggestionsURLFormat, GetGoogleBaseURL().spec().c_str(), query.c_str())); |
253 } | 260 } |
254 | 261 |
255 // static | 262 // static |
256 std::string SuggestionsServiceImpl::BuildSuggestionsBlacklistURLPrefix() { | 263 std::string SuggestionsServiceImpl::BuildSuggestionsBlacklistURLPrefix() { |
257 return base::StringPrintf(kSuggestionsBlacklistURLPrefixFormat, | 264 return base::StringPrintf(kSuggestionsBlacklistURLPrefixFormat, |
258 GetGoogleBaseURL().spec().c_str(), kDeviceType); | 265 GetGoogleBaseURL().spec().c_str(), kDeviceType); |
259 } | 266 } |
260 | 267 |
261 // static | 268 // static |
262 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistURL( | 269 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistURL( |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); | 568 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); |
562 } else { | 569 } else { |
563 TimeDelta candidate_delay = | 570 TimeDelta candidate_delay = |
564 scheduling_delay_ * kSchedulingBackoffMultiplier; | 571 scheduling_delay_ * kSchedulingBackoffMultiplier; |
565 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) | 572 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) |
566 scheduling_delay_ = candidate_delay; | 573 scheduling_delay_ = candidate_delay; |
567 } | 574 } |
568 } | 575 } |
569 | 576 |
570 } // namespace suggestions | 577 } // namespace suggestions |
OLD | NEW |