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/offline_pages/offline_page_suggestions_provide r.h" | 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide r.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 | 9 |
| 10 using offline_pages::MultipleOfflinePageItemResult; | 10 using offline_pages::MultipleOfflinePageItemResult; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 base::Bind(&OfflinePageSuggestionsProvider::OnOfflinePagesLoaded, | 88 base::Bind(&OfflinePageSuggestionsProvider::OnOfflinePagesLoaded, |
| 89 base::Unretained(this))); | 89 base::Unretained(this))); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded( | 92 void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded( |
| 93 const MultipleOfflinePageItemResult& result) { | 93 const MultipleOfflinePageItemResult& result) { |
| 94 NotifyStatusChanged(ContentSuggestionsCategoryStatus::AVAILABLE); | 94 NotifyStatusChanged(ContentSuggestionsCategoryStatus::AVAILABLE); |
| 95 if (!observer_) | 95 if (!observer_) |
| 96 return; | 96 return; |
| 97 | 97 |
| 98 int counter = 0; | |
| 98 std::vector<ContentSuggestion> suggestions; | 99 std::vector<ContentSuggestion> suggestions; |
| 99 for (const OfflinePageItem& item : result) { | 100 for (const OfflinePageItem& item : result) { |
| 101 // TODO(pke): Make sure the URL is actually opened as an offline URL. | |
| 102 // Currently, the browser opens the offline URL and then immediately | |
| 103 // redirects to the online URL if the device is online. | |
| 100 ContentSuggestion suggestion( | 104 ContentSuggestion suggestion( |
| 101 MakeUniqueID(ContentSuggestionsCategory::OFFLINE_PAGES, | 105 MakeUniqueID(ContentSuggestionsCategory::OFFLINE_PAGES, |
| 102 base::IntToString(item.offline_id)), | 106 base::IntToString(item.offline_id)), |
| 103 item.GetOfflineURL()); | 107 item.GetOfflineURL()); |
| 104 | 108 |
| 105 // TODO(pke): Sort my most recently visited and only keep the top one of | 109 // TODO(pke): Sort my most recently visited and only keep the top one of |
| 106 // multiple entries for the same URL. | 110 // multiple entries for the same URL. |
| 107 // TODO(pke): Get more reasonable data from the OfflinePageModel here. | 111 // TODO(pke): Get more reasonable data from the OfflinePageModel here. |
| 108 suggestion.set_title(item.url.spec()); | 112 suggestion.set_title(item.url.spec()); |
| 109 suggestion.set_snippet_text(std::string()); | 113 suggestion.set_snippet_text(std::string()); |
| 110 suggestion.set_publish_date(item.creation_time); | 114 suggestion.set_publish_date(item.creation_time); |
| 111 suggestion.set_publisher_name(item.url.host()); | 115 suggestion.set_publisher_name(item.url.host()); |
| 112 suggestions.emplace_back(std::move(suggestion)); | 116 suggestions.emplace_back(std::move(suggestion)); |
| 117 // TODO(pke): Refine the number of offline pages to be returned, introduce | |
| 118 // a constant? | |
|
Marc Treib
2016/07/26 14:00:00
Yup, you should probably introduce a constant :)
A
Philipp Keck
2016/07/26 15:47:20
Good idea. Constant is there, I put a question abo
| |
| 119 if (5 == ++counter) | |
| 120 break; | |
| 113 } | 121 } |
| 114 | 122 |
| 115 observer_->OnNewSuggestions(ContentSuggestionsCategory::OFFLINE_PAGES, | 123 observer_->OnNewSuggestions(ContentSuggestionsCategory::OFFLINE_PAGES, |
| 116 std::move(suggestions)); | 124 std::move(suggestions)); |
| 117 } | 125 } |
| 118 | 126 |
| 119 void OfflinePageSuggestionsProvider::NotifyStatusChanged( | 127 void OfflinePageSuggestionsProvider::NotifyStatusChanged( |
| 120 ContentSuggestionsCategoryStatus new_status) { | 128 ContentSuggestionsCategoryStatus new_status) { |
| 121 if (category_status_ == new_status) | 129 if (category_status_ == new_status) |
| 122 return; | 130 return; |
| 123 category_status_ = new_status; | 131 category_status_ = new_status; |
| 124 | 132 |
| 125 if (!observer_) | 133 if (!observer_) |
| 126 return; | 134 return; |
| 127 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::OFFLINE_PAGES, | 135 observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::OFFLINE_PAGES, |
| 128 new_status); | 136 new_status); |
| 129 } | 137 } |
| 130 | 138 |
| 131 } // namespace ntp_snippets | 139 } // namespace ntp_snippets |
| OLD | NEW |