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.h" | 5 #include "components/suggestions/suggestions_service.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; | 94 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; |
95 const char kSuggestionsFieldTrialURLParam[] = "url"; | 95 const char kSuggestionsFieldTrialURLParam[] = "url"; |
96 const char kSuggestionsFieldTrialCommonParamsParam[] = "common_params"; | 96 const char kSuggestionsFieldTrialCommonParamsParam[] = "common_params"; |
97 const char kSuggestionsFieldTrialBlacklistPathParam[] = "blacklist_path"; | 97 const char kSuggestionsFieldTrialBlacklistPathParam[] = "blacklist_path"; |
98 const char kSuggestionsFieldTrialBlacklistUrlParam[] = "blacklist_url_param"; | 98 const char kSuggestionsFieldTrialBlacklistUrlParam[] = "blacklist_url_param"; |
99 const char kSuggestionsFieldTrialStateParam[] = "state"; | 99 const char kSuggestionsFieldTrialStateParam[] = "state"; |
100 const char kSuggestionsFieldTrialControlParam[] = "control"; | 100 const char kSuggestionsFieldTrialControlParam[] = "control"; |
101 const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; | 101 const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; |
102 const char kSuggestionsFieldTrialTimeoutMs[] = "timeout_ms"; | 102 const char kSuggestionsFieldTrialTimeoutMs[] = "timeout_ms"; |
103 | 103 |
104 const int64 kDefaultExpiryUsec = 72 * base::Time::kMicrosecondsPerHour; | |
Mathieu
2014/08/04 18:29:21
new line after this.
gayane -on leave until 09-2017
2014/08/04 19:26:44
Done.
| |
104 namespace { | 105 namespace { |
105 | 106 |
106 std::string GetBlacklistUrlPrefix() { | 107 std::string GetBlacklistUrlPrefix() { |
107 std::stringstream blacklist_url_prefix_stream; | 108 std::stringstream blacklist_url_prefix_stream; |
108 blacklist_url_prefix_stream | 109 blacklist_url_prefix_stream |
109 << GetExperimentParam(kSuggestionsFieldTrialURLParam) | 110 << GetExperimentParam(kSuggestionsFieldTrialURLParam) |
110 << GetExperimentParam(kSuggestionsFieldTrialBlacklistPathParam) << "?" | 111 << GetExperimentParam(kSuggestionsFieldTrialBlacklistPathParam) << "?" |
111 << GetExperimentParam(kSuggestionsFieldTrialCommonParamsParam) << "&" | 112 << GetExperimentParam(kSuggestionsFieldTrialCommonParamsParam) << "&" |
112 << GetExperimentParam(kSuggestionsFieldTrialBlacklistUrlParam) << "="; | 113 << GetExperimentParam(kSuggestionsFieldTrialBlacklistUrlParam) << "="; |
113 return blacklist_url_prefix_stream.str(); | 114 return blacklist_url_prefix_stream.str(); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 // Handle a successful blacklisting. | 298 // Handle a successful blacklisting. |
298 GURL blacklisted_url; | 299 GURL blacklisted_url; |
299 if (GetBlacklistedUrl(*source, &blacklisted_url)) { | 300 if (GetBlacklistedUrl(*source, &blacklisted_url)) { |
300 blacklist_store_->RemoveUrl(blacklisted_url); | 301 blacklist_store_->RemoveUrl(blacklisted_url); |
301 } | 302 } |
302 | 303 |
303 std::string suggestions_data; | 304 std::string suggestions_data; |
304 bool success = request->GetResponseAsString(&suggestions_data); | 305 bool success = request->GetResponseAsString(&suggestions_data); |
305 DCHECK(success); | 306 DCHECK(success); |
306 | 307 |
307 // Compute suggestions, and dispatch then to requestors. On error still | 308 // Compute suggestions, and dispatch them to requestors. On error still |
308 // dispatch empty suggestions. | 309 // dispatch empty suggestions. |
309 SuggestionsProfile suggestions; | 310 SuggestionsProfile suggestions; |
310 if (suggestions_data.empty()) { | 311 if (suggestions_data.empty()) { |
311 LogResponseState(RESPONSE_EMPTY); | 312 LogResponseState(RESPONSE_EMPTY); |
312 suggestions_store_->ClearSuggestions(); | 313 suggestions_store_->ClearSuggestions(); |
313 } else if (suggestions.ParseFromString(suggestions_data)) { | 314 } else if (suggestions.ParseFromString(suggestions_data)) { |
314 LogResponseState(RESPONSE_VALID); | 315 LogResponseState(RESPONSE_VALID); |
315 thumbnail_manager_->Initialize(suggestions); | 316 thumbnail_manager_->Initialize(suggestions); |
317 | |
318 int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
319 .ToInternalValue(); | |
320 int64 timestamp_usec = now_usec + kDefaultExpiryUsec; | |
321 SetDefaultExpiryTimestamps(&suggestions, timestamp_usec); | |
Mathieu
2014/08/04 18:29:21
inline now_usec + kDefaultExpiryUsec here
gayane -on leave until 09-2017
2014/08/04 19:26:44
Done.
| |
316 suggestions_store_->StoreSuggestions(suggestions); | 322 suggestions_store_->StoreSuggestions(suggestions); |
317 } else { | 323 } else { |
318 LogResponseState(RESPONSE_INVALID); | 324 LogResponseState(RESPONSE_INVALID); |
319 suggestions_store_->LoadSuggestions(&suggestions); | 325 suggestions_store_->LoadSuggestions(&suggestions); |
320 } | 326 } |
321 | 327 |
322 FilterAndServe(&suggestions); | 328 FilterAndServe(&suggestions); |
323 ScheduleBlacklistUpload(true); | 329 ScheduleBlacklistUpload(true); |
324 } | 330 } |
325 | 331 |
332 void SuggestionsService::SetDefaultExpiryTimestamps( | |
333 SuggestionsProfile* suggestions, int64 default_timestamp_usec) { | |
334 for (int i = 0; i < suggestions->suggestions_size(); ++i) { | |
335 ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); | |
336 if (!suggestion->has_expiry_ts()){ | |
Mathieu
2014/08/04 18:29:21
add a comment above this line:
// Do not set expi
gayane -on leave until 09-2017
2014/08/04 19:26:44
Done.
| |
337 suggestion->set_expiry_ts(default_timestamp_usec); | |
338 } | |
339 } | |
340 } | |
341 | |
326 void SuggestionsService::Shutdown() { | 342 void SuggestionsService::Shutdown() { |
327 // Cancel pending request and timeout closure, then serve existing requestors | 343 // Cancel pending request and timeout closure, then serve existing requestors |
328 // from cache. | 344 // from cache. |
329 pending_request_.reset(NULL); | 345 pending_request_.reset(NULL); |
330 pending_timeout_closure_.reset(NULL); | 346 pending_timeout_closure_.reset(NULL); |
331 ServeFromCache(); | 347 ServeFromCache(); |
332 } | 348 } |
333 | 349 |
334 void SuggestionsService::ServeFromCache() { | 350 void SuggestionsService::ServeFromCache() { |
335 SuggestionsProfile suggestions; | 351 SuggestionsProfile suggestions; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 if (last_request_successful) { | 395 if (last_request_successful) { |
380 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; | 396 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |
381 } else { | 397 } else { |
382 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; | 398 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; |
383 if (candidate_delay < kBlacklistMaxDelaySec) | 399 if (candidate_delay < kBlacklistMaxDelaySec) |
384 blacklist_delay_sec_ = candidate_delay; | 400 blacklist_delay_sec_ = candidate_delay; |
385 } | 401 } |
386 } | 402 } |
387 | 403 |
388 } // namespace suggestions | 404 } // namespace suggestions |
OLD | NEW |