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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
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/features.h" | 28 #include "components/ntp_snippets/features.h" |
29 #include "components/ntp_snippets/pref_names.h" | 29 #include "components/ntp_snippets/pref_names.h" |
| 30 #include "components/ntp_snippets/remote/ntp_snippets_request_params.h" |
30 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 31 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
31 #include "components/ntp_snippets/switches.h" | 32 #include "components/ntp_snippets/switches.h" |
32 #include "components/ntp_snippets/user_classifier.h" | 33 #include "components/ntp_snippets/user_classifier.h" |
33 #include "components/prefs/pref_registry_simple.h" | 34 #include "components/prefs/pref_registry_simple.h" |
34 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
35 #include "components/variations/variations_associated_data.h" | 36 #include "components/variations/variations_associated_data.h" |
36 #include "grit/components_strings.h" | 37 #include "grit/components_strings.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
39 | 40 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 408 |
408 void RemoteSuggestionsProvider::FetchSnippets( | 409 void RemoteSuggestionsProvider::FetchSnippets( |
409 bool interactive_request) { | 410 bool interactive_request) { |
410 if (!ready()) { | 411 if (!ready()) { |
411 fetch_when_ready_ = true; | 412 fetch_when_ready_ = true; |
412 return; | 413 return; |
413 } | 414 } |
414 | 415 |
415 MarkEmptyCategoriesAsLoading(); | 416 MarkEmptyCategoriesAsLoading(); |
416 | 417 |
417 NTPSnippetsFetcher::Params params = BuildFetchParams(); | 418 NTPSnippetsRequestParams params = BuildFetchParams(); |
418 params.interactive_request = interactive_request; | 419 params.interactive_request = interactive_request; |
419 snippets_fetcher_->FetchSnippets( | 420 snippets_fetcher_->FetchSnippets( |
420 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, | 421 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, |
421 base::Unretained(this), interactive_request)); | 422 base::Unretained(this), interactive_request)); |
422 } | 423 } |
423 | 424 |
424 void RemoteSuggestionsProvider::Fetch( | 425 void RemoteSuggestionsProvider::Fetch( |
425 const Category& category, | 426 const Category& category, |
426 const std::set<std::string>& known_suggestion_ids, | 427 const std::set<std::string>& known_suggestion_ids, |
427 const FetchDoneCallback& callback) { | 428 const FetchDoneCallback& callback) { |
428 if (!ready()) { | 429 if (!ready()) { |
429 CallWithEmptyResults(callback, | 430 CallWithEmptyResults(callback, |
430 Status(StatusCode::TEMPORARY_ERROR, | 431 Status(StatusCode::TEMPORARY_ERROR, |
431 "RemoteSuggestionsProvider is not ready!")); | 432 "RemoteSuggestionsProvider is not ready!")); |
432 return; | 433 return; |
433 } | 434 } |
434 NTPSnippetsFetcher::Params params = BuildFetchParams(); | 435 NTPSnippetsRequestParams params = BuildFetchParams(); |
435 params.excluded_ids.insert(known_suggestion_ids.begin(), | 436 params.excluded_ids.insert(known_suggestion_ids.begin(), |
436 known_suggestion_ids.end()); | 437 known_suggestion_ids.end()); |
437 params.interactive_request = true; | 438 params.interactive_request = true; |
438 params.exclusive_category = category; | 439 params.exclusive_category = category; |
439 | 440 |
440 snippets_fetcher_->FetchSnippets( | 441 snippets_fetcher_->FetchSnippets( |
441 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished, | 442 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished, |
442 base::Unretained(this), callback)); | 443 base::Unretained(this), callback)); |
443 } | 444 } |
444 | 445 |
445 // Builds default fetcher params. | 446 // Builds default fetcher params. |
446 NTPSnippetsFetcher::Params RemoteSuggestionsProvider::BuildFetchParams() const { | 447 NTPSnippetsRequestParams RemoteSuggestionsProvider::BuildFetchParams() const { |
447 NTPSnippetsFetcher::Params result; | 448 NTPSnippetsRequestParams result; |
448 result.language_code = application_language_code_; | 449 result.language_code = application_language_code_; |
449 result.count_to_fetch = kMaxSnippetCount; | 450 result.count_to_fetch = kMaxSnippetCount; |
450 for (const auto& map_entry : category_contents_) { | 451 for (const auto& map_entry : category_contents_) { |
451 const CategoryContent& content = map_entry.second; | 452 const CategoryContent& content = map_entry.second; |
452 for (const auto& dismissed_snippet : content.dismissed) { | 453 for (const auto& dismissed_snippet : content.dismissed) { |
453 result.excluded_ids.insert(dismissed_snippet->id()); | 454 result.excluded_ids.insert(dismissed_snippet->id()); |
454 } | 455 } |
455 } | 456 } |
456 return result; | 457 return result; |
457 } | 458 } |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = | 1335 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = |
1335 default; | 1336 default; |
1336 | 1337 |
1337 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; | 1338 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; |
1338 | 1339 |
1339 RemoteSuggestionsProvider::CategoryContent& | 1340 RemoteSuggestionsProvider::CategoryContent& |
1340 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = | 1341 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = |
1341 default; | 1342 default; |
1342 | 1343 |
1343 } // namespace ntp_snippets | 1344 } // namespace ntp_snippets |
OLD | NEW |