| 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.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 "components/variations/variations_associated_data.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // value, so always use SessionTab::timestamp() instead. | 154 // value, so always use SessionTab::timestamp() instead. |
| 155 // TODO(skym): It might be better if we sorted by recency of session, and | 155 // TODO(skym): It might be better if we sorted by recency of session, and |
| 156 // only then by recency of the tab. Right now this causes a single | 156 // only then by recency of the tab. Right now this causes a single |
| 157 // device's tabs to be interleaved with another devices' tabs. | 157 // device's tabs to be interleaved with another devices' tabs. |
| 158 return tab->timestamp > other.tab->timestamp; | 158 return tab->timestamp > other.tab->timestamp; |
| 159 } | 159 } |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 ForeignSessionsSuggestionsProvider::ForeignSessionsSuggestionsProvider( | 162 ForeignSessionsSuggestionsProvider::ForeignSessionsSuggestionsProvider( |
| 163 ContentSuggestionsProvider::Observer* observer, | 163 ContentSuggestionsProvider::Observer* observer, |
| 164 CategoryFactory* category_factory, | |
| 165 std::unique_ptr<ForeignSessionsProvider> foreign_sessions_provider, | 164 std::unique_ptr<ForeignSessionsProvider> foreign_sessions_provider, |
| 166 PrefService* pref_service) | 165 PrefService* pref_service) |
| 167 : ContentSuggestionsProvider(observer, category_factory), | 166 : ContentSuggestionsProvider(observer), |
| 168 category_status_(CategoryStatus::INITIALIZING), | 167 category_status_(CategoryStatus::INITIALIZING), |
| 169 provided_category_( | 168 provided_category_( |
| 170 category_factory->FromKnownCategory(KnownCategories::FOREIGN_TABS)), | 169 Category::FromKnownCategory(KnownCategories::FOREIGN_TABS)), |
| 171 foreign_sessions_provider_(std::move(foreign_sessions_provider)), | 170 foreign_sessions_provider_(std::move(foreign_sessions_provider)), |
| 172 pref_service_(pref_service) { | 171 pref_service_(pref_service) { |
| 173 foreign_sessions_provider_->SubscribeForForeignTabChange( | 172 foreign_sessions_provider_->SubscribeForForeignTabChange( |
| 174 base::Bind(&ForeignSessionsSuggestionsProvider::OnForeignTabChange, | 173 base::Bind(&ForeignSessionsSuggestionsProvider::OnForeignTabChange, |
| 175 base::Unretained(this))); | 174 base::Unretained(this))); |
| 176 | 175 |
| 177 // If sync is already initialzed, try suggesting now, though this is unlikely. | 176 // If sync is already initialzed, try suggesting now, though this is unlikely. |
| 178 OnForeignTabChange(); | 177 OnForeignTabChange(); |
| 179 } | 178 } |
| 180 | 179 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 data.navigation->virtual_url().spec(), | 399 data.navigation->virtual_url().spec(), |
| 401 data.navigation->virtual_url()); | 400 data.navigation->virtual_url()); |
| 402 suggestion.set_title(data.navigation->title()); | 401 suggestion.set_title(data.navigation->title()); |
| 403 suggestion.set_publish_date(data.tab->timestamp); | 402 suggestion.set_publish_date(data.tab->timestamp); |
| 404 suggestion.set_publisher_name( | 403 suggestion.set_publisher_name( |
| 405 base::UTF8ToUTF16(data.navigation->virtual_url().host())); | 404 base::UTF8ToUTF16(data.navigation->virtual_url().host())); |
| 406 return suggestion; | 405 return suggestion; |
| 407 } | 406 } |
| 408 | 407 |
| 409 } // namespace ntp_snippets | 408 } // namespace ntp_snippets |
| OLD | NEW |