Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 } | 317 } |
| 318 | 318 |
| 319 void RemoteSuggestionsProviderImpl::SetRemoteSuggestionsScheduler( | 319 void RemoteSuggestionsProviderImpl::SetRemoteSuggestionsScheduler( |
| 320 RemoteSuggestionsScheduler* scheduler) { | 320 RemoteSuggestionsScheduler* scheduler) { |
| 321 remote_suggestions_scheduler_ = scheduler; | 321 remote_suggestions_scheduler_ = scheduler; |
| 322 // Call the observer right away if we've reached any final state. | 322 // Call the observer right away if we've reached any final state. |
| 323 NotifyStateChanged(); | 323 NotifyStateChanged(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void RemoteSuggestionsProviderImpl::ReloadSuggestions() { | 326 void RemoteSuggestionsProviderImpl::ReloadSuggestions() { |
| 327 if (remote_suggestions_scheduler_ && | |
| 328 !remote_suggestions_scheduler_->AcquireQuotaForInteractiveFetch()) { | |
|
Marc Treib
2017/03/23 16:41:15
Hm. So if there's no scheduler, we don't bother wi
tschumann
2017/03/23 17:38:27
+1, let's return early if we don't have a schedule
jkrcal
2017/03/27 10:03:02
Done. I cannot make it part of ready() because the
| |
| 329 return; | |
| 330 } | |
| 327 FetchSuggestions(/*interactive_request=*/true, | 331 FetchSuggestions(/*interactive_request=*/true, |
| 328 /*callback=*/nullptr); | 332 /*callback=*/nullptr); |
| 329 } | 333 } |
| 330 | 334 |
| 331 void RemoteSuggestionsProviderImpl::RefetchInTheBackground( | 335 void RemoteSuggestionsProviderImpl::RefetchInTheBackground( |
| 332 std::unique_ptr<FetchStatusCallback> callback) { | 336 std::unique_ptr<FetchStatusCallback> callback) { |
| 333 FetchSuggestions(/*interactive_request=*/false, std::move(callback)); | 337 FetchSuggestions(/*interactive_request=*/false, std::move(callback)); |
| 334 } | 338 } |
| 335 | 339 |
| 336 const RemoteSuggestionsFetcher* | 340 const RemoteSuggestionsFetcher* |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 361 void RemoteSuggestionsProviderImpl::Fetch( | 365 void RemoteSuggestionsProviderImpl::Fetch( |
| 362 const Category& category, | 366 const Category& category, |
| 363 const std::set<std::string>& known_suggestion_ids, | 367 const std::set<std::string>& known_suggestion_ids, |
| 364 const FetchDoneCallback& callback) { | 368 const FetchDoneCallback& callback) { |
| 365 if (!ready()) { | 369 if (!ready()) { |
| 366 CallWithEmptyResults(callback, | 370 CallWithEmptyResults(callback, |
| 367 Status(StatusCode::TEMPORARY_ERROR, | 371 Status(StatusCode::TEMPORARY_ERROR, |
| 368 "RemoteSuggestionsProvider is not ready!")); | 372 "RemoteSuggestionsProvider is not ready!")); |
| 369 return; | 373 return; |
| 370 } | 374 } |
| 375 if (remote_suggestions_scheduler_ && | |
| 376 !remote_suggestions_scheduler_->AcquireQuotaForInteractiveFetch()) { | |
| 377 CallWithEmptyResults(callback, Status(StatusCode::TEMPORARY_ERROR, | |
| 378 "Interactive quota exceeded!")); | |
| 379 return; | |
| 380 } | |
| 371 RequestParams params = BuildFetchParams(); | 381 RequestParams params = BuildFetchParams(); |
| 372 params.excluded_ids.insert(known_suggestion_ids.begin(), | 382 params.excluded_ids.insert(known_suggestion_ids.begin(), |
| 373 known_suggestion_ids.end()); | 383 known_suggestion_ids.end()); |
| 374 params.interactive_request = true; | 384 params.interactive_request = true; |
| 375 params.exclusive_category = category; | 385 params.exclusive_category = category; |
| 376 | 386 |
| 377 suggestions_fetcher_->FetchSnippets( | 387 suggestions_fetcher_->FetchSnippets( |
| 378 params, | 388 params, |
| 379 base::BindOnce(&RemoteSuggestionsProviderImpl::OnFetchMoreFinished, | 389 base::BindOnce(&RemoteSuggestionsProviderImpl::OnFetchMoreFinished, |
| 380 base::Unretained(this), callback)); | 390 base::Unretained(this), callback)); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 | 646 |
| 637 IntegrateSuggestions(existing_content, | 647 IntegrateSuggestions(existing_content, |
| 638 std::move(fetched_category.suggestions)); | 648 std::move(fetched_category.suggestions)); |
| 639 | 649 |
| 640 // TODO(tschumann): We should properly honor the existing category state, | 650 // TODO(tschumann): We should properly honor the existing category state, |
| 641 // e.g. to make sure we don't serve results after the sign-out. Revisit this: | 651 // e.g. to make sure we don't serve results after the sign-out. Revisit this: |
| 642 // Should Nuke also cancel outstanding requests, or do we want to check the | 652 // Should Nuke also cancel outstanding requests, or do we want to check the |
| 643 // status? | 653 // status? |
| 644 UpdateCategoryStatus(category, CategoryStatus::AVAILABLE); | 654 UpdateCategoryStatus(category, CategoryStatus::AVAILABLE); |
| 645 // Notify callers and observers. | 655 // Notify callers and observers. |
| 656 if (remote_suggestions_scheduler_) { | |
|
tschumann
2017/03/23 17:38:27
this should never be nullptr, right? remove the if
jkrcal
2017/03/27 10:03:02
Correct, removed the ifs here and below.
I am not
Marc Treib
2017/03/27 11:31:00
Not sure I understand the proposal... who would wr
jkrcal
2017/03/27 14:09:31
I am not sure either :D
The only solution I can i
Marc Treib
2017/03/27 14:27:20
Alright, then let's leave it as is for now, and le
tschumann
2017/03/27 15:40:45
OnFetchMoreFinished is already doing a lot of thin
jkrcal
2017/03/27 16:02:22
Tim, in the current state of the CL, the scheduler
jkrcal
2017/03/29 10:55:57
Okay, done.
| |
| 657 remote_suggestions_scheduler_->OnInteractiveFetchFinished(status); | |
| 658 } | |
| 646 fetching_callback.Run(Status::Success(), std::move(result)); | 659 fetching_callback.Run(Status::Success(), std::move(result)); |
| 647 NotifyNewSuggestions(category, *existing_content); | 660 NotifyNewSuggestions(category, *existing_content); |
| 648 } | 661 } |
| 649 | 662 |
| 650 void RemoteSuggestionsProviderImpl::OnFetchFinished( | 663 void RemoteSuggestionsProviderImpl::OnFetchFinished( |
| 651 std::unique_ptr<FetchStatusCallback> callback, | 664 std::unique_ptr<FetchStatusCallback> callback, |
| 652 bool interactive_request, | 665 bool interactive_request, |
| 653 Status status, | 666 Status status, |
| 654 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories) { | 667 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories) { |
| 655 if (!ready()) { | 668 if (!ready()) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 auto content_it = category_contents_.find(articles_category_); | 733 auto content_it = category_contents_.find(articles_category_); |
| 721 DCHECK(content_it != category_contents_.end()); | 734 DCHECK(content_it != category_contents_.end()); |
| 722 const CategoryContent& content = content_it->second; | 735 const CategoryContent& content = content_it->second; |
| 723 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticles", | 736 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticles", |
| 724 content.suggestions.size()); | 737 content.suggestions.size()); |
| 725 if (content.suggestions.empty() && !content.dismissed.empty()) { | 738 if (content.suggestions.empty() && !content.dismissed.empty()) { |
| 726 UMA_HISTOGRAM_COUNTS("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded", | 739 UMA_HISTOGRAM_COUNTS("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded", |
| 727 content.dismissed.size()); | 740 content.dismissed.size()); |
| 728 } | 741 } |
| 729 | 742 |
| 743 if (interactive_request && remote_suggestions_scheduler_) { | |
| 744 remote_suggestions_scheduler_->OnInteractiveFetchFinished(status); | |
| 745 } | |
| 746 | |
| 730 if (callback) { | 747 if (callback) { |
| 731 callback->Run(status); | 748 callback->Run(status); |
| 732 } | 749 } |
| 733 } | 750 } |
| 734 | 751 |
| 735 void RemoteSuggestionsProviderImpl::ArchiveSuggestions( | 752 void RemoteSuggestionsProviderImpl::ArchiveSuggestions( |
| 736 CategoryContent* content, | 753 CategoryContent* content, |
| 737 RemoteSuggestion::PtrVector* to_archive) { | 754 RemoteSuggestion::PtrVector* to_archive) { |
| 738 // Archive previous suggestions - move them at the beginning of the list. | 755 // Archive previous suggestions - move them at the beginning of the list. |
| 739 content->archived.insert(content->archived.begin(), | 756 content->archived.insert(content->archived.begin(), |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( | 1288 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( |
| 1272 CategoryContent&&) = default; | 1289 CategoryContent&&) = default; |
| 1273 | 1290 |
| 1274 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; | 1291 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; |
| 1275 | 1292 |
| 1276 RemoteSuggestionsProviderImpl::CategoryContent& | 1293 RemoteSuggestionsProviderImpl::CategoryContent& |
| 1277 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = | 1294 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = |
| 1278 default; | 1295 default; |
| 1279 | 1296 |
| 1280 } // namespace ntp_snippets | 1297 } // namespace ntp_snippets |
| OLD | NEW |