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/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "base/time/default_clock.h" | 17 #include "base/time/default_clock.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "components/favicon/core/large_icon_service.h" | 19 #include "components/favicon/core/large_icon_service.h" |
20 #include "components/favicon_base/fallback_icon_style.h" | 20 #include "components/favicon_base/fallback_icon_style.h" |
21 #include "components/favicon_base/favicon_types.h" | 21 #include "components/favicon_base/favicon_types.h" |
| 22 #include "components/ntp_snippets/content_suggestions_metrics.h" |
22 #include "components/ntp_snippets/pref_names.h" | 23 #include "components/ntp_snippets/pref_names.h" |
23 #include "components/prefs/pref_registry_simple.h" | 24 #include "components/prefs/pref_registry_simple.h" |
24 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
25 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
26 | 27 |
27 namespace ntp_snippets { | 28 namespace ntp_snippets { |
28 | 29 |
29 ContentSuggestionsService::ContentSuggestionsService( | 30 ContentSuggestionsService::ContentSuggestionsService( |
30 State state, | 31 State state, |
31 SigninManagerBase* signin_manager, | 32 SigninManagerBase* signin_manager, |
(...skipping 15 matching lines...) Expand all Loading... |
47 // Can be null in tests. | 48 // Can be null in tests. |
48 if (signin_manager) { | 49 if (signin_manager) { |
49 signin_observer_.Add(signin_manager); | 50 signin_observer_.Add(signin_manager); |
50 } | 51 } |
51 | 52 |
52 if (history_service) { | 53 if (history_service) { |
53 history_service_observer_.Add(history_service); | 54 history_service_observer_.Add(history_service); |
54 } | 55 } |
55 | 56 |
56 RestoreDismissedCategoriesFromPrefs(); | 57 RestoreDismissedCategoriesFromPrefs(); |
| 58 metrics::RecordRemoteSuggestionsProviderState(AreRemoteSuggestionsEnabled()); |
57 } | 59 } |
58 | 60 |
59 ContentSuggestionsService::~ContentSuggestionsService() = default; | 61 ContentSuggestionsService::~ContentSuggestionsService() = default; |
60 | 62 |
61 void ContentSuggestionsService::Shutdown() { | 63 void ContentSuggestionsService::Shutdown() { |
62 remote_suggestions_provider_ = nullptr; | 64 remote_suggestions_provider_ = nullptr; |
63 remote_suggestions_scheduler_ = nullptr; | 65 remote_suggestions_scheduler_ = nullptr; |
64 suggestions_by_category_.clear(); | 66 suggestions_by_category_.clear(); |
65 providers_by_category_.clear(); | 67 providers_by_category_.clear(); |
66 categories_.clear(); | 68 categories_.clear(); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 340 |
339 providers_it->second->Fetch(category, known_suggestion_ids, callback); | 341 providers_it->second->Fetch(category, known_suggestion_ids, callback); |
340 } | 342 } |
341 | 343 |
342 void ContentSuggestionsService::ReloadSuggestions() { | 344 void ContentSuggestionsService::ReloadSuggestions() { |
343 for (const auto& provider : providers_) { | 345 for (const auto& provider : providers_) { |
344 provider->ReloadSuggestions(); | 346 provider->ReloadSuggestions(); |
345 } | 347 } |
346 } | 348 } |
347 | 349 |
348 void ContentSuggestionsService::SetRemoteSuggestionsServiceEnabled( | 350 void ContentSuggestionsService::SetRemoteSuggestionsEnabled(bool enabled) { |
349 bool enabled) { | |
350 pref_service_->SetBoolean(prefs::kEnableSnippets, enabled); | 351 pref_service_->SetBoolean(prefs::kEnableSnippets, enabled); |
351 } | 352 } |
352 | 353 |
353 bool ContentSuggestionsService::IsRemoteSuggestionsServiceEnabled() const { | 354 bool ContentSuggestionsService::AreRemoteSuggestionsEnabled() const { |
354 return pref_service_->GetBoolean(prefs::kEnableSnippets); | 355 return pref_service_->GetBoolean(prefs::kEnableSnippets); |
355 } | 356 } |
356 | 357 |
357 bool ContentSuggestionsService::IsRemoteSuggestionsServiceManaged() const { | 358 bool ContentSuggestionsService::AreRemoteSuggestionsManaged() const { |
358 return pref_service_->IsManagedPreference(prefs::kEnableSnippets); | 359 return pref_service_->IsManagedPreference(prefs::kEnableSnippets); |
359 } | 360 } |
360 | 361 |
361 bool ContentSuggestionsService::IsRemoteSuggestionsServiceManagedByCustodian() | 362 bool ContentSuggestionsService::AreRemoteSuggestionsManagedByCustodian() const { |
362 const { | |
363 return pref_service_->IsPreferenceManagedByCustodian(prefs::kEnableSnippets); | 363 return pref_service_->IsPreferenceManagedByCustodian(prefs::kEnableSnippets); |
364 } | 364 } |
365 | 365 |
366 //////////////////////////////////////////////////////////////////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// |
367 // Private methods | 367 // Private methods |
368 | 368 |
369 void ContentSuggestionsService::OnNewSuggestions( | 369 void ContentSuggestionsService::OnNewSuggestions( |
370 ContentSuggestionsProvider* provider, | 370 ContentSuggestionsProvider* provider, |
371 Category category, | 371 Category category, |
372 std::vector<ContentSuggestion> suggestions) { | 372 std::vector<ContentSuggestion> suggestions) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 621 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
622 base::ListValue list; | 622 base::ListValue list; |
623 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 623 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
624 list.AppendInteger(category_provider_pair.first.id()); | 624 list.AppendInteger(category_provider_pair.first.id()); |
625 } | 625 } |
626 | 626 |
627 pref_service_->Set(prefs::kDismissedCategories, list); | 627 pref_service_->Set(prefs::kDismissedCategories, list); |
628 } | 628 } |
629 | 629 |
630 } // namespace ntp_snippets | 630 } // namespace ntp_snippets |
OLD | NEW |