OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 Category exclusive = params_.exclusive_category.value(); | 767 Category exclusive = params_.exclusive_category.value(); |
768 auto category_it = | 768 auto category_it = |
769 std::find_if(categories->begin(), categories->end(), | 769 std::find_if(categories->begin(), categories->end(), |
770 [&exclusive](const FetchedCategory& c) -> bool { | 770 [&exclusive](const FetchedCategory& c) -> bool { |
771 return c.category == exclusive; | 771 return c.category == exclusive; |
772 }); | 772 }); |
773 if (category_it == categories->end()) { | 773 if (category_it == categories->end()) { |
774 categories->clear(); | 774 categories->clear(); |
775 return; | 775 return; |
776 } | 776 } |
777 categories->erase(categories->begin(), category_it); | 777 FetchedCategory category = std::move(*category_it); |
778 categories->erase(category_it + 1, categories->end()); | 778 categories->clear(); |
| 779 categories->emplace_back(std::move(category)); |
779 } | 780 } |
780 | 781 |
781 void NTPSnippetsFetcher::FetchFinished( | 782 void NTPSnippetsFetcher::FetchFinished( |
782 OptionalFetchedCategories fetched_categories, | 783 OptionalFetchedCategories fetched_categories, |
783 FetchResult result, | 784 FetchResult result, |
784 const std::string& extra_message) { | 785 const std::string& extra_message) { |
785 DCHECK(result == FetchResult::SUCCESS || !fetched_categories); | 786 DCHECK(result == FetchResult::SUCCESS || !fetched_categories); |
786 last_status_ = FetchResultToString(result) + extra_message; | 787 last_status_ = FetchResultToString(result) + extra_message; |
787 | 788 |
788 // TODO(fhorschig): Filter (un)wanted categories by modifying fetch request. | 789 // Filter out unwanted categories if necessary. |
789 // As soon as backends support the parameter, there is no reason to overfetch | 790 // TODO(fhorschig): As soon as the server supports filtering by |
790 // and filter here. | 791 // that instead of over-fetching and filtering here. |
791 if (fetched_categories.has_value()) | 792 if (fetched_categories.has_value()) |
792 FilterCategories(&fetched_categories.value()); | 793 FilterCategories(&fetched_categories.value()); |
793 | 794 |
794 // Don't record FetchTimes if the result indicates that a precondition | 795 // Don't record FetchTimes if the result indicates that a precondition |
795 // failed and we never actually sent a network request | 796 // failed and we never actually sent a network request |
796 if (!IsFetchPreconditionFailed(result)) { | 797 if (!IsFetchPreconditionFailed(result)) { |
797 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime", | 798 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime", |
798 tick_clock_->NowTicks() - fetch_start_time_); | 799 tick_clock_->NowTicks() - fetch_start_time_); |
799 } | 800 } |
800 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 801 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
(...skipping 15 matching lines...) Expand all Loading... |
816 interactive_request); | 817 interactive_request); |
817 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: | 818 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: |
818 return request_throttler_active_suggestions_consumer_ | 819 return request_throttler_active_suggestions_consumer_ |
819 .DemandQuotaForRequest(interactive_request); | 820 .DemandQuotaForRequest(interactive_request); |
820 } | 821 } |
821 NOTREACHED(); | 822 NOTREACHED(); |
822 return false; | 823 return false; |
823 } | 824 } |
824 | 825 |
825 } // namespace ntp_snippets | 826 } // namespace ntp_snippets |
OLD | NEW |