| 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/sessions/foreign_sessions_suggestions_provider
.h" | 5 #include "components/ntp_snippets/sessions/foreign_sessions_suggestions_provider
.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/ntp_snippets/category_factory.h" | 15 #include "components/ntp_snippets/category_factory.h" |
| 16 #include "components/ntp_snippets/category_info.h" | 16 #include "components/ntp_snippets/category_info.h" |
| 17 #include "components/ntp_snippets/content_suggestion.h" | 17 #include "components/ntp_snippets/content_suggestion.h" |
| 18 #include "components/ntp_snippets/features.h" | 18 #include "components/ntp_snippets/features.h" |
| 19 #include "components/ntp_snippets/pref_names.h" | 19 #include "components/ntp_snippets/pref_names.h" |
| 20 #include "components/ntp_snippets/pref_util.h" | 20 #include "components/ntp_snippets/pref_util.h" |
| 21 #include "components/prefs/pref_registry_simple.h" | 21 #include "components/prefs/pref_registry_simple.h" |
| 22 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 23 #include "components/sessions/core/session_types.h" | 23 #include "components/sessions/core/session_types.h" |
| 24 #include "components/sync_sessions/synced_session.h" | 24 #include "components/sync_sessions/synced_session.h" |
| 25 #include "components/variations/variations_associated_data.h" |
| 25 #include "grit/components_strings.h" | 26 #include "grit/components_strings.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 using base::Time; | 31 using base::Time; |
| 31 using base::TimeDelta; | 32 using base::TimeDelta; |
| 32 using sessions::SerializedNavigationEntry; | 33 using sessions::SerializedNavigationEntry; |
| 33 using sessions::SessionTab; | 34 using sessions::SessionTab; |
| 34 using sessions::SessionWindow; | 35 using sessions::SessionWindow; |
| 35 using sync_sessions::SyncedSession; | 36 using sync_sessions::SyncedSession; |
| 36 | 37 |
| 37 using DismissedFilter = base::Callback<bool(const std::string& id)>; | 38 using DismissedFilter = base::Callback<bool(const std::string& id)>; |
| 38 | 39 |
| 39 namespace ntp_snippets { | 40 namespace ntp_snippets { |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 const int kMaxForeignTabsTotal = 10; | 43 const int kMaxForeignTabsTotal = 10; |
| 43 const int kMaxForeignTabsPerDevice = 3; | 44 const int kMaxForeignTabsPerDevice = 3; |
| 44 const int kMaxForeignTabAgeInMinutes = 180; | 45 const int kMaxForeignTabAgeInMinutes = 180; |
| 45 | 46 |
| 46 const char* kMaxForeignTabsTotalParamName = "max_foreign_tabs_total"; | 47 const char* kMaxForeignTabsTotalParamName = "max_foreign_tabs_total"; |
| 47 const char* kMaxForeignTabsPerDeviceParamName = "max_foreign_tabs_per_device"; | 48 const char* kMaxForeignTabsPerDeviceParamName = "max_foreign_tabs_per_device"; |
| 48 const char* kMaxForeignTabAgeInMinutesParamName = | 49 const char* kMaxForeignTabAgeInMinutesParamName = |
| 49 "max_foreign_tabs_age_in_minutes"; | 50 "max_foreign_tabs_age_in_minutes"; |
| 50 | 51 |
| 51 int GetMaxForeignTabsTotal() { | 52 int GetMaxForeignTabsTotal() { |
| 52 return GetParamAsInt(ntp_snippets::kForeignSessionsSuggestionsFeature, | 53 return variations::GetVariationParamByFeatureAsInt( |
| 53 kMaxForeignTabsTotalParamName, kMaxForeignTabsTotal); | 54 ntp_snippets::kForeignSessionsSuggestionsFeature, |
| 55 kMaxForeignTabsTotalParamName, kMaxForeignTabsTotal); |
| 54 } | 56 } |
| 55 | 57 |
| 56 int GetMaxForeignTabsPerDevice() { | 58 int GetMaxForeignTabsPerDevice() { |
| 57 return GetParamAsInt(ntp_snippets::kForeignSessionsSuggestionsFeature, | 59 return variations::GetVariationParamByFeatureAsInt( |
| 58 kMaxForeignTabsPerDeviceParamName, | 60 ntp_snippets::kForeignSessionsSuggestionsFeature, |
| 59 kMaxForeignTabsPerDevice); | 61 kMaxForeignTabsPerDeviceParamName, kMaxForeignTabsPerDevice); |
| 60 } | 62 } |
| 61 | 63 |
| 62 TimeDelta GetMaxForeignTabAge() { | 64 TimeDelta GetMaxForeignTabAge() { |
| 63 return TimeDelta::FromMinutes(GetParamAsInt( | 65 return TimeDelta::FromMinutes(variations::GetVariationParamByFeatureAsInt( |
| 64 ntp_snippets::kForeignSessionsSuggestionsFeature, | 66 ntp_snippets::kForeignSessionsSuggestionsFeature, |
| 65 kMaxForeignTabAgeInMinutesParamName, kMaxForeignTabAgeInMinutes)); | 67 kMaxForeignTabAgeInMinutesParamName, kMaxForeignTabAgeInMinutes)); |
| 66 } | 68 } |
| 67 | 69 |
| 68 // This filter does two things. Most importantly it lets through only ids that | 70 // This filter does two things. Most importantly it lets through only ids that |
| 69 // have not been dismissed. The other responsibility this class has is it tracks | 71 // have not been dismissed. The other responsibility this class has is it tracks |
| 70 // all of the ids that fly past it, and it will save the intersection of | 72 // all of the ids that fly past it, and it will save the intersection of |
| 71 // initially dismissed ids, and seen ids. This will aggressively prune any | 73 // initially dismissed ids, and seen ids. This will aggressively prune any |
| 72 // dismissal that is not currently blocking a recent tab. | 74 // dismissal that is not currently blocking a recent tab. |
| 73 class PrefsPruningDismissedItemFilter { | 75 class PrefsPruningDismissedItemFilter { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 data.navigation->virtual_url().spec(), | 400 data.navigation->virtual_url().spec(), |
| 399 data.navigation->virtual_url()); | 401 data.navigation->virtual_url()); |
| 400 suggestion.set_title(data.navigation->title()); | 402 suggestion.set_title(data.navigation->title()); |
| 401 suggestion.set_publish_date(data.tab->timestamp); | 403 suggestion.set_publish_date(data.tab->timestamp); |
| 402 suggestion.set_publisher_name( | 404 suggestion.set_publisher_name( |
| 403 base::UTF8ToUTF16(data.navigation->virtual_url().host())); | 405 base::UTF8ToUTF16(data.navigation->virtual_url().host())); |
| 404 return suggestion; | 406 return suggestion; |
| 405 } | 407 } |
| 406 | 408 |
| 407 } // namespace ntp_snippets | 409 } // namespace ntp_snippets |
| OLD | NEW |