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/content_suggestions_service.h" | 5 #include "components/ntp_snippets/content_suggestions_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.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/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/time/default_clock.h" | 18 #include "base/time/default_clock.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "components/favicon/core/large_icon_service.h" | 20 #include "components/favicon/core/large_icon_service.h" |
21 #include "components/favicon_base/fallback_icon_style.h" | 21 #include "components/favicon_base/fallback_icon_style.h" |
22 #include "components/favicon_base/favicon_types.h" | 22 #include "components/favicon_base/favicon_types.h" |
| 23 #include "components/ntp_snippets/content_suggestions_metrics.h" |
23 #include "components/ntp_snippets/pref_names.h" | 24 #include "components/ntp_snippets/pref_names.h" |
24 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 25 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
25 #include "components/prefs/pref_registry_simple.h" | 26 #include "components/prefs/pref_registry_simple.h" |
26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
27 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
28 | 29 |
29 namespace ntp_snippets { | 30 namespace ntp_snippets { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 318 } |
318 } | 319 } |
319 | 320 |
320 void ContentSuggestionsService::DismissSuggestion( | 321 void ContentSuggestionsService::DismissSuggestion( |
321 const ContentSuggestion::ID& suggestion_id) { | 322 const ContentSuggestion::ID& suggestion_id) { |
322 if (!providers_by_category_.count(suggestion_id.category())) { | 323 if (!providers_by_category_.count(suggestion_id.category())) { |
323 LOG(WARNING) << "Dismissed suggestion " << suggestion_id | 324 LOG(WARNING) << "Dismissed suggestion " << suggestion_id |
324 << " for unavailable category " << suggestion_id.category(); | 325 << " for unavailable category " << suggestion_id.category(); |
325 return; | 326 return; |
326 } | 327 } |
| 328 |
| 329 metrics::RecordContentSuggestionDismissed(); |
| 330 |
327 providers_by_category_[suggestion_id.category()]->DismissSuggestion( | 331 providers_by_category_[suggestion_id.category()]->DismissSuggestion( |
328 suggestion_id); | 332 suggestion_id); |
329 | 333 |
330 // Remove the suggestion locally if it is present. A suggestion may be missing | 334 // Remove the suggestion locally if it is present. A suggestion may be missing |
331 // localy e.g. if it was sent to UI through |Fetch| or it has been dismissed | 335 // localy e.g. if it was sent to UI through |Fetch| or it has been dismissed |
332 // from a different NTP. | 336 // from a different NTP. |
333 RemoveSuggestionByID(suggestion_id); | 337 RemoveSuggestionByID(suggestion_id); |
334 } | 338 } |
335 | 339 |
336 void ContentSuggestionsService::DismissCategory(Category category) { | 340 void ContentSuggestionsService::DismissCategory(Category category) { |
337 auto providers_it = providers_by_category_.find(category); | 341 auto providers_it = providers_by_category_.find(category); |
338 if (providers_it == providers_by_category_.end()) { | 342 if (providers_it == providers_by_category_.end()) { |
339 return; | 343 return; |
340 } | 344 } |
341 | 345 |
| 346 metrics::RecordCategoryDismissed(); |
| 347 |
342 ContentSuggestionsProvider* provider = providers_it->second; | 348 ContentSuggestionsProvider* provider = providers_it->second; |
343 UnregisterCategory(category, provider); | 349 UnregisterCategory(category, provider); |
344 | 350 |
345 dismissed_providers_by_category_[category] = provider; | 351 dismissed_providers_by_category_[category] = provider; |
346 StoreDismissedCategoriesToPrefs(); | 352 StoreDismissedCategoriesToPrefs(); |
347 | 353 |
348 category_ranker_->OnCategoryDismissed(category); | 354 category_ranker_->OnCategoryDismissed(category); |
349 } | 355 } |
350 | 356 |
351 void ContentSuggestionsService::RestoreDismissedCategories() { | 357 void ContentSuggestionsService::RestoreDismissedCategories() { |
(...skipping 23 matching lines...) Expand all Loading... |
375 | 381 |
376 void ContentSuggestionsService::Fetch( | 382 void ContentSuggestionsService::Fetch( |
377 const Category& category, | 383 const Category& category, |
378 const std::set<std::string>& known_suggestion_ids, | 384 const std::set<std::string>& known_suggestion_ids, |
379 const FetchDoneCallback& callback) { | 385 const FetchDoneCallback& callback) { |
380 auto providers_it = providers_by_category_.find(category); | 386 auto providers_it = providers_by_category_.find(category); |
381 if (providers_it == providers_by_category_.end()) { | 387 if (providers_it == providers_by_category_.end()) { |
382 return; | 388 return; |
383 } | 389 } |
384 | 390 |
| 391 metrics::RecordFetchAction(); |
| 392 |
385 providers_it->second->Fetch(category, known_suggestion_ids, callback); | 393 providers_it->second->Fetch(category, known_suggestion_ids, callback); |
386 } | 394 } |
387 | 395 |
388 void ContentSuggestionsService::ReloadSuggestions() { | 396 void ContentSuggestionsService::ReloadSuggestions() { |
389 for (const auto& provider : providers_) { | 397 for (const auto& provider : providers_) { |
390 provider->ReloadSuggestions(); | 398 provider->ReloadSuggestions(); |
391 } | 399 } |
392 } | 400 } |
393 | 401 |
394 void ContentSuggestionsService::SetRemoteSuggestionsEnabled(bool enabled) { | 402 void ContentSuggestionsService::SetRemoteSuggestionsEnabled(bool enabled) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 673 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
666 base::ListValue list; | 674 base::ListValue list; |
667 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 675 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
668 list.AppendInteger(category_provider_pair.first.id()); | 676 list.AppendInteger(category_provider_pair.first.id()); |
669 } | 677 } |
670 | 678 |
671 pref_service_->Set(prefs::kDismissedCategories, list); | 679 pref_service_->Set(prefs::kDismissedCategories, list); |
672 } | 680 } |
673 | 681 |
674 } // namespace ntp_snippets | 682 } // namespace ntp_snippets |
OLD | NEW |