| 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.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/time/default_clock.h" | 21 #include "base/time/default_clock.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "components/data_use_measurement/core/data_use_user_data.h" | 24 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 25 #include "components/history/core/browser/history_service.h" | 25 #include "components/history/core/browser/history_service.h" |
| 26 #include "components/image_fetcher/image_decoder.h" | 26 #include "components/image_fetcher/image_decoder.h" |
| 27 #include "components/image_fetcher/image_fetcher.h" | 27 #include "components/image_fetcher/image_fetcher.h" |
| 28 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 28 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 29 #include "components/ntp_snippets/features.h" | 29 #include "components/ntp_snippets/features.h" |
| 30 #include "components/ntp_snippets/pref_names.h" | 30 #include "components/ntp_snippets/pref_names.h" |
| 31 #include "components/ntp_snippets/remote/ntp_snippets_request_params.h" |
| 31 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 32 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 32 #include "components/ntp_snippets/switches.h" | 33 #include "components/ntp_snippets/switches.h" |
| 33 #include "components/ntp_snippets/user_classifier.h" | 34 #include "components/ntp_snippets/user_classifier.h" |
| 34 #include "components/prefs/pref_registry_simple.h" | 35 #include "components/prefs/pref_registry_simple.h" |
| 35 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 36 #include "components/variations/variations_associated_data.h" | 37 #include "components/variations/variations_associated_data.h" |
| 37 #include "grit/components_strings.h" | 38 #include "grit/components_strings.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/gfx/image/image.h" | 40 #include "ui/gfx/image/image.h" |
| 40 | 41 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 410 |
| 410 void RemoteSuggestionsProvider::FetchSnippets( | 411 void RemoteSuggestionsProvider::FetchSnippets( |
| 411 bool interactive_request) { | 412 bool interactive_request) { |
| 412 if (!ready()) { | 413 if (!ready()) { |
| 413 fetch_when_ready_ = true; | 414 fetch_when_ready_ = true; |
| 414 return; | 415 return; |
| 415 } | 416 } |
| 416 | 417 |
| 417 MarkEmptyCategoriesAsLoading(); | 418 MarkEmptyCategoriesAsLoading(); |
| 418 | 419 |
| 419 NTPSnippetsFetcher::Params params = BuildFetchParams(); | 420 NTPSnippetsRequestParams params = BuildFetchParams(); |
| 420 params.interactive_request = interactive_request; | 421 params.interactive_request = interactive_request; |
| 421 snippets_fetcher_->FetchSnippets( | 422 snippets_fetcher_->FetchSnippets( |
| 422 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, | 423 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, |
| 423 base::Unretained(this), interactive_request)); | 424 base::Unretained(this), interactive_request)); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void RemoteSuggestionsProvider::Fetch( | 427 void RemoteSuggestionsProvider::Fetch( |
| 427 const Category& category, | 428 const Category& category, |
| 428 const std::set<std::string>& known_suggestion_ids, | 429 const std::set<std::string>& known_suggestion_ids, |
| 429 const FetchDoneCallback& callback) { | 430 const FetchDoneCallback& callback) { |
| 430 if (!ready()) { | 431 if (!ready()) { |
| 431 CallWithEmptyResults(callback, | 432 CallWithEmptyResults(callback, |
| 432 Status(StatusCode::TEMPORARY_ERROR, | 433 Status(StatusCode::TEMPORARY_ERROR, |
| 433 "RemoteSuggestionsProvider is not ready!")); | 434 "RemoteSuggestionsProvider is not ready!")); |
| 434 return; | 435 return; |
| 435 } | 436 } |
| 436 NTPSnippetsFetcher::Params params = BuildFetchParams(); | 437 NTPSnippetsRequestParams params = BuildFetchParams(); |
| 437 params.excluded_ids.insert(known_suggestion_ids.begin(), | 438 params.excluded_ids.insert(known_suggestion_ids.begin(), |
| 438 known_suggestion_ids.end()); | 439 known_suggestion_ids.end()); |
| 439 params.interactive_request = true; | 440 params.interactive_request = true; |
| 440 params.exclusive_category = category; | 441 params.exclusive_category = category; |
| 441 | 442 |
| 442 snippets_fetcher_->FetchSnippets( | 443 snippets_fetcher_->FetchSnippets( |
| 443 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished, | 444 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished, |
| 444 base::Unretained(this), callback)); | 445 base::Unretained(this), callback)); |
| 445 } | 446 } |
| 446 | 447 |
| 447 // Builds default fetcher params. | 448 // Builds default fetcher params. |
| 448 NTPSnippetsFetcher::Params RemoteSuggestionsProvider::BuildFetchParams() const { | 449 NTPSnippetsRequestParams RemoteSuggestionsProvider::BuildFetchParams() const { |
| 449 NTPSnippetsFetcher::Params result; | 450 NTPSnippetsRequestParams result; |
| 450 result.language_code = application_language_code_; | 451 result.language_code = application_language_code_; |
| 451 result.count_to_fetch = kMaxSnippetCount; | 452 result.count_to_fetch = kMaxSnippetCount; |
| 452 for (const auto& map_entry : category_contents_) { | 453 for (const auto& map_entry : category_contents_) { |
| 453 const CategoryContent& content = map_entry.second; | 454 const CategoryContent& content = map_entry.second; |
| 454 for (const auto& dismissed_snippet : content.dismissed) { | 455 for (const auto& dismissed_snippet : content.dismissed) { |
| 455 result.excluded_ids.insert(dismissed_snippet->id()); | 456 result.excluded_ids.insert(dismissed_snippet->id()); |
| 456 } | 457 } |
| 457 } | 458 } |
| 458 return result; | 459 return result; |
| 459 } | 460 } |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = | 1339 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = |
| 1339 default; | 1340 default; |
| 1340 | 1341 |
| 1341 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; | 1342 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; |
| 1342 | 1343 |
| 1343 RemoteSuggestionsProvider::CategoryContent& | 1344 RemoteSuggestionsProvider::CategoryContent& |
| 1344 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = | 1345 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = |
| 1345 default; | 1346 default; |
| 1346 | 1347 |
| 1347 } // namespace ntp_snippets | 1348 } // namespace ntp_snippets |
| OLD | NEW |