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 "chrome/browser/ntp_snippets/download_suggestions_provider.h" | 5 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // ContentSuggestion move constructor noexcept. | 391 // ContentSuggestion move constructor noexcept. |
392 while (suggestions.size() > kMaxSuggestionsCount) | 392 while (suggestions.size() > kMaxSuggestionsCount) |
393 suggestions.pop_back(); | 393 suggestions.pop_back(); |
394 | 394 |
395 observer()->OnNewSuggestions(this, provided_category_, | 395 observer()->OnNewSuggestions(this, provided_category_, |
396 std::move(suggestions)); | 396 std::move(suggestions)); |
397 } | 397 } |
398 | 398 |
399 ContentSuggestion DownloadSuggestionsProvider::ConvertOfflinePage( | 399 ContentSuggestion DownloadSuggestionsProvider::ConvertOfflinePage( |
400 const OfflinePageItem& offline_page) const { | 400 const OfflinePageItem& offline_page) const { |
401 // TODO(vitaliii): Make sure the URL is actually opened as an offline URL even | |
402 // when the user is online. See crbug.com/641568. | |
403 ContentSuggestion suggestion( | 401 ContentSuggestion suggestion( |
404 ContentSuggestion::ID(provided_category_, GetOfflinePagePerCategoryID( | 402 ContentSuggestion::ID(provided_category_, GetOfflinePagePerCategoryID( |
405 offline_page.offline_id)), | 403 offline_page.offline_id)), |
406 offline_page.url); | 404 offline_page.url); |
407 | 405 |
408 if (offline_page.title.empty()) { | 406 if (offline_page.title.empty()) { |
409 // TODO(vitaliii): Remove this fallback once the OfflinePageModel provides | 407 // TODO(vitaliii): Remove this fallback once the OfflinePageModel provides |
410 // titles for all (relevant) OfflinePageItems. | 408 // titles for all (relevant) OfflinePageItems. |
411 suggestion.set_title(base::UTF8ToUTF16(offline_page.url.spec())); | 409 suggestion.set_title(base::UTF8ToUTF16(offline_page.url.spec())); |
412 } else { | 410 } else { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 638 |
641 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { | 639 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { |
642 DCHECK_NE(download_manager_, nullptr); | 640 DCHECK_NE(download_manager_, nullptr); |
643 | 641 |
644 std::vector<DownloadItem*> all_downloads; | 642 std::vector<DownloadItem*> all_downloads; |
645 download_manager_->GetAllDownloads(&all_downloads); | 643 download_manager_->GetAllDownloads(&all_downloads); |
646 | 644 |
647 for (DownloadItem* item : all_downloads) | 645 for (DownloadItem* item : all_downloads) |
648 item->RemoveObserver(this); | 646 item->RemoveObserver(this); |
649 } | 647 } |
OLD | NEW |