Chromium Code Reviews| Index: components/suggestions/suggestions_service.cc |
| diff --git a/components/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc |
| index 2cac4249b42293d899fea378c0d72a4693226a6e..f43aacb61a6660965368c176b581b415cc65e1a2 100644 |
| --- a/components/suggestions/suggestions_service.cc |
| +++ b/components/suggestions/suggestions_service.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/single_thread_task_runner.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| @@ -84,13 +85,24 @@ const int kSchedulingMaxDelaySec = 5 * 60; |
| } // namespace |
| // TODO(mathp): Put this in TemplateURL. |
| +// TODO(mathp): Add logic to decide the device type of the request. |
|
Mathieu
2015/07/28 13:09:29
nice one ;) mathp -> fserb
Seriously though, can
fserb
2015/07/28 15:31:33
I mean, there's going to be an IFDEF somewhere, bu
|
| +#if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) |
|
Mathieu
2015/07/28 13:09:29
ChromeOS can be lumped in the desktop case.
fserb
2015/07/28 15:31:33
Done.
|
| const char kSuggestionsURL[] = "https://www.google.com/chromesuggestions?t=2"; |
| const char kSuggestionsBlacklistURLPrefix[] = |
| "https://www.google.com/chromesuggestions/blacklist?t=2&url="; |
| +const char kSuggestionsBlacklistClearURL[] = |
| + "https://www.google.com/chromesuggestions/blacklist/clear?t=2"; |
| +#else |
| +const char kSuggestionsURL[] = "https://www.google.com/chromesuggestions?t=1"; |
| +const char kSuggestionsBlacklistURLPrefix[] = |
| + "https://www.google.com/chromesuggestions/blacklist?t=1&url="; |
| +const char kSuggestionsBlacklistClearURL[] = |
| + "https://www.google.com/chromesuggestions/blacklist/clear?t=1"; |
| +#endif |
| const char kSuggestionsBlacklistURLParam[] = "url"; |
| -// The default expiry timeout is 72 hours. |
| -const int64 kDefaultExpiryUsec = 72 * base::Time::kMicrosecondsPerHour; |
| +// The default expiry timeout is 168 hours. |
| +const int64 kDefaultExpiryUsec = 168 * base::Time::kMicrosecondsPerHour; |
| SuggestionsService::SuggestionsService( |
| net::URLRequestContextGetter* url_request_context, |
| @@ -175,6 +187,14 @@ void SuggestionsService::UndoBlacklistURL( |
| fail_callback.Run(); |
| } |
| +void SuggestionsService::ClearBlacklist(const ResponseCallback& callback) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + blacklist_store_->ClearBlacklist(); |
| + IssueRequestIfNoneOngoing(GURL(kSuggestionsBlacklistClearURL)); |
| + waiting_requestors_.push_back(callback); |
| + ServeFromCache(); |
| +} |
| + |
| // static |
| bool SuggestionsService::GetBlacklistedUrl(const net::URLFetcher& request, |
| GURL* url) { |
| @@ -296,6 +316,7 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) |
| .ToInternalValue(); |
| SetDefaultExpiryTimestamp(&suggestions, now_usec + kDefaultExpiryUsec); |
| + PopulateFavicons(suggestions); |
| suggestions_store_->StoreSuggestions(suggestions); |
| } else { |
| LogResponseState(RESPONSE_INVALID); |
| @@ -305,6 +326,16 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| ScheduleBlacklistUpload(); |
| } |
| +void SuggestionsService::PopulateFavicons(SuggestionsProfile* suggestions) { |
| + for (int i = 0; i < suggestions.suggestions_size(); ++i) { |
| + suggestions::ChromeSuggestion* s = suggestions.mutable_suggestions(i); |
| + s->set_favicon_url( |
| + base::StringPrintf("https://s2.googleusercontent.com/s2/" |
|
Mathieu
2015/07/28 13:09:29
bring into a constant at the top
fserb
2015/07/28 15:31:33
Done.
|
| + "favicons?domain_url=%s&alt=s&sz=32", |
| + s->url().c_str())); |
| + } |
| +} |
| + |
| void SuggestionsService::Shutdown() { |
| // Cancel pending request, then serve existing requestors from cache. |
| pending_request_.reset(NULL); |