Chromium Code Reviews| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 // Handle a successful blacklisting. | 297 // Handle a successful blacklisting. |
| 298 GURL blacklisted_url; | 298 GURL blacklisted_url; |
| 299 if (GetBlacklistedUrl(*source, &blacklisted_url)) { | 299 if (GetBlacklistedUrl(*source, &blacklisted_url)) { |
| 300 blacklist_store_->RemoveUrl(blacklisted_url); | 300 blacklist_store_->RemoveUrl(blacklisted_url); |
| 301 } | 301 } |
| 302 | 302 |
| 303 std::string suggestions_data; | 303 std::string suggestions_data; |
| 304 bool success = request->GetResponseAsString(&suggestions_data); | 304 bool success = request->GetResponseAsString(&suggestions_data); |
| 305 DCHECK(success); | 305 DCHECK(success); |
| 306 | 306 |
| 307 // Compute suggestions, and dispatch then to requestors. On error still | 307 // Compute suggestions, and dispatch them to requestors. On error still |
| 308 // dispatch empty suggestions. | 308 // dispatch empty suggestions. |
| 309 SuggestionsProfile suggestions; | 309 SuggestionsProfile suggestions; |
| 310 if (suggestions_data.empty()) { | 310 if (suggestions_data.empty()) { |
| 311 LogResponseState(RESPONSE_EMPTY); | 311 LogResponseState(RESPONSE_EMPTY); |
| 312 suggestions_store_->ClearSuggestions(); | 312 suggestions_store_->ClearSuggestions(); |
| 313 } else if (suggestions.ParseFromString(suggestions_data)) { | 313 } else if (suggestions.ParseFromString(suggestions_data)) { |
| 314 LogResponseState(RESPONSE_VALID); | 314 LogResponseState(RESPONSE_VALID); |
| 315 thumbnail_manager_->Initialize(suggestions); | 315 thumbnail_manager_->Initialize(suggestions); |
| 316 | |
| 317 int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
| 318 .ToInternalValue(); | |
| 319 int64 timestamp_usec = now_usec + default_expiry_usec; | |
| 320 SetDefaultExpiryTimestamps(&suggestions, timestamp_usec); | |
| 316 suggestions_store_->StoreSuggestions(suggestions); | 321 suggestions_store_->StoreSuggestions(suggestions); |
| 317 } else { | 322 } else { |
| 318 LogResponseState(RESPONSE_INVALID); | 323 LogResponseState(RESPONSE_INVALID); |
| 319 suggestions_store_->LoadSuggestions(&suggestions); | 324 suggestions_store_->LoadSuggestions(&suggestions); |
| 320 } | 325 } |
| 321 | 326 |
| 322 FilterAndServe(&suggestions); | 327 FilterAndServe(&suggestions); |
| 323 ScheduleBlacklistUpload(true); | 328 ScheduleBlacklistUpload(true); |
| 324 } | 329 } |
| 325 | 330 |
|
Mathieu
2014/08/04 14:39:10
remove extra new line
gayane -on leave until 09-2017
2014/08/04 16:34:57
Done.
| |
| 331 | |
| 332 void SuggestionsService::SetDefaultExpiryTimestamps( | |
| 333 SuggestionsProfile* suggestions, int64 default_timestamp_usec) { | |
| 334 | |
|
Mathieu
2014/08/04 14:39:10
remove extra line
gayane -on leave until 09-2017
2014/08/04 16:34:57
Done.
| |
| 335 for (int i = 0; i < suggestions->suggestions_size(); ++i) { | |
| 336 ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); | |
| 337 if (!suggestion->has_expiry_ts()){ | |
| 338 suggestion->set_expiry_ts(default_timestamp_usec); | |
|
Mathieu
2014/08/04 14:39:10
indent 2 less
gayane -on leave until 09-2017
2014/08/04 16:34:57
Done.
| |
| 339 } | |
| 340 } | |
| 341 } | |
| 342 | |
| 326 void SuggestionsService::Shutdown() { | 343 void SuggestionsService::Shutdown() { |
| 327 // Cancel pending request and timeout closure, then serve existing requestors | 344 // Cancel pending request and timeout closure, then serve existing requestors |
| 328 // from cache. | 345 // from cache. |
| 329 pending_request_.reset(NULL); | 346 pending_request_.reset(NULL); |
| 330 pending_timeout_closure_.reset(NULL); | 347 pending_timeout_closure_.reset(NULL); |
| 331 ServeFromCache(); | 348 ServeFromCache(); |
| 332 } | 349 } |
| 333 | 350 |
| 334 void SuggestionsService::ServeFromCache() { | 351 void SuggestionsService::ServeFromCache() { |
| 335 SuggestionsProfile suggestions; | 352 SuggestionsProfile suggestions; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 if (last_request_successful) { | 396 if (last_request_successful) { |
| 380 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; | 397 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |
| 381 } else { | 398 } else { |
| 382 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; | 399 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; |
| 383 if (candidate_delay < kBlacklistMaxDelaySec) | 400 if (candidate_delay < kBlacklistMaxDelaySec) |
| 384 blacklist_delay_sec_ = candidate_delay; | 401 blacklist_delay_sec_ = candidate_delay; |
| 385 } | 402 } |
| 386 } | 403 } |
| 387 | 404 |
| 388 } // namespace suggestions | 405 } // namespace suggestions |
| OLD | NEW |