Chromium Code Reviews| 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> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "components/variations/variations_associated_data.h" | 27 #include "components/variations/variations_associated_data.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 | 31 |
| 32 using base::Time; | 32 using base::Time; |
| 33 using base::TimeDelta; | 33 using base::TimeDelta; |
| 34 using sessions::SerializedNavigationEntry; | 34 using sessions::SerializedNavigationEntry; |
| 35 using sessions::SessionTab; | 35 using sessions::SessionTab; |
| 36 using sessions::SessionWindow; | 36 using sessions::SessionWindow; |
| 37 using sync_sessions::SyncedSessionWindow; | |
| 37 using sync_sessions::SyncedSession; | 38 using sync_sessions::SyncedSession; |
| 38 | 39 |
| 39 using DismissedFilter = base::Callback<bool(const std::string& id)>; | 40 using DismissedFilter = base::Callback<bool(const std::string& id)>; |
| 40 | 41 |
| 41 namespace ntp_snippets { | 42 namespace ntp_snippets { |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 const int kMaxForeignTabsTotal = 10; | 45 const int kMaxForeignTabsTotal = 10; |
| 45 const int kMaxForeignTabsPerDevice = 3; | 46 const int kMaxForeignTabsPerDevice = 3; |
| 46 const int kMaxForeignTabAgeInMinutes = 180; | 47 const int kMaxForeignTabAgeInMinutes = 180; |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 359 } |
| 359 | 360 |
| 360 std::vector<ForeignSessionsSuggestionsProvider::SessionData> | 361 std::vector<ForeignSessionsSuggestionsProvider::SessionData> |
| 361 ForeignSessionsSuggestionsProvider::GetSuggestionCandidates( | 362 ForeignSessionsSuggestionsProvider::GetSuggestionCandidates( |
| 362 const DismissedFilter& suggestions_filter) { | 363 const DismissedFilter& suggestions_filter) { |
| 363 const std::vector<const SyncedSession*>& foreign_sessions = | 364 const std::vector<const SyncedSession*>& foreign_sessions = |
| 364 foreign_sessions_provider_->GetAllForeignSessions(); | 365 foreign_sessions_provider_->GetAllForeignSessions(); |
| 365 const TimeDelta max_foreign_tab_age = GetMaxForeignTabAge(); | 366 const TimeDelta max_foreign_tab_age = GetMaxForeignTabAge(); |
| 366 std::vector<SessionData> suggestion_candidates; | 367 std::vector<SessionData> suggestion_candidates; |
| 367 for (const SyncedSession* session : foreign_sessions) { | 368 for (const SyncedSession* session : foreign_sessions) { |
| 368 for (const std::pair<const SessionID::id_type, | 369 for (const std::pair<const SessionID::id_type, |
|
Patrick Noland
2017/03/28 20:42:00
[nit] This would be a little less verbose with aut
Nicolas Zea
2017/03/29 19:01:33
Done.
| |
| 369 std::unique_ptr<sessions::SessionWindow>>& key_value : | 370 std::unique_ptr<SyncedSessionWindow>>& key_value : |
| 370 session->windows) { | 371 session->windows) { |
| 371 for (const std::unique_ptr<SessionTab>& tab : key_value.second->tabs) { | 372 for (const std::unique_ptr<SessionTab>& tab : |
| 373 key_value.second->wrapped_window.tabs) { | |
| 372 if (tab->navigations.empty()) { | 374 if (tab->navigations.empty()) { |
| 373 continue; | 375 continue; |
| 374 } | 376 } |
| 375 | 377 |
| 376 const SerializedNavigationEntry& navigation = tab->navigations.back(); | 378 const SerializedNavigationEntry& navigation = tab->navigations.back(); |
| 377 const std::string id = navigation.virtual_url().spec(); | 379 const std::string id = navigation.virtual_url().spec(); |
| 378 // TODO(skym): Filter out internal pages. Tabs that contain only | 380 // TODO(skym): Filter out internal pages. Tabs that contain only |
| 379 // non-syncable content should never reach the local client. However, | 381 // non-syncable content should never reach the local client. However, |
| 380 // sync will let tabs through whose current navigation entry is | 382 // sync will let tabs through whose current navigation entry is |
| 381 // internal, as long as a back or forward navigation entry is valid. We | 383 // internal, as long as a back or forward navigation entry is valid. We |
| (...skipping 16 matching lines...) Expand all 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 |