| 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 #include "base/strings/utf_string_conversions.h" |
| 9 | 10 |
| 10 using offline_pages::MultipleOfflinePageItemResult; | 11 using offline_pages::MultipleOfflinePageItemResult; |
| 11 using offline_pages::OfflinePageModel; | 12 using offline_pages::OfflinePageModel; |
| 12 using offline_pages::OfflinePageItem; | 13 using offline_pages::OfflinePageItem; |
| 13 | 14 |
| 14 namespace ntp_snippets { | 15 namespace ntp_snippets { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const int kMaxSuggestionsCount = 5; | 19 const int kMaxSuggestionsCount = 5; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // TODO(pke): Make sure the URL is actually opened as an offline URL. | 113 // TODO(pke): Make sure the URL is actually opened as an offline URL. |
| 113 // Currently, the browser opens the offline URL and then immediately | 114 // Currently, the browser opens the offline URL and then immediately |
| 114 // redirects to the online URL if the device is online. | 115 // redirects to the online URL if the device is online. |
| 115 ContentSuggestion suggestion( | 116 ContentSuggestion suggestion( |
| 116 MakeUniqueID(provided_category_, base::IntToString(item.offline_id)), | 117 MakeUniqueID(provided_category_, base::IntToString(item.offline_id)), |
| 117 item.GetOfflineURL()); | 118 item.GetOfflineURL()); |
| 118 | 119 |
| 119 // TODO(pke): Sort my most recently visited and only keep the top one of | 120 // TODO(pke): Sort my most recently visited and only keep the top one of |
| 120 // multiple entries for the same URL. | 121 // multiple entries for the same URL. |
| 121 // TODO(pke): Get more reasonable data from the OfflinePageModel here. | 122 // TODO(pke): Get more reasonable data from the OfflinePageModel here. |
| 122 suggestion.set_title(item.url.spec()); | 123 suggestion.set_title(base::UTF8ToUTF16(item.url.spec())); |
| 123 suggestion.set_snippet_text(std::string()); | 124 suggestion.set_snippet_text(base::string16()); |
| 124 suggestion.set_publish_date(item.creation_time); | 125 suggestion.set_publish_date(item.creation_time); |
| 125 suggestion.set_publisher_name(item.url.host()); | 126 suggestion.set_publisher_name(base::UTF8ToUTF16(item.url.host())); |
| 126 suggestions.emplace_back(std::move(suggestion)); | 127 suggestions.emplace_back(std::move(suggestion)); |
| 127 if (suggestions.size() == kMaxSuggestionsCount) | 128 if (suggestions.size() == kMaxSuggestionsCount) |
| 128 break; | 129 break; |
| 129 } | 130 } |
| 130 | 131 |
| 131 observer_->OnNewSuggestions(provided_category_, std::move(suggestions)); | 132 observer_->OnNewSuggestions(provided_category_, std::move(suggestions)); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void OfflinePageSuggestionsProvider::NotifyStatusChanged( | 135 void OfflinePageSuggestionsProvider::NotifyStatusChanged( |
| 135 CategoryStatus new_status) { | 136 CategoryStatus new_status) { |
| 136 if (category_status_ == new_status) | 137 if (category_status_ == new_status) |
| 137 return; | 138 return; |
| 138 category_status_ = new_status; | 139 category_status_ = new_status; |
| 139 | 140 |
| 140 if (!observer_) | 141 if (!observer_) |
| 141 return; | 142 return; |
| 142 observer_->OnCategoryStatusChanged(provided_category_, new_status); | 143 observer_->OnCategoryStatusChanged(provided_category_, new_status); |
| 143 } | 144 } |
| 144 | 145 |
| 145 } // namespace ntp_snippets | 146 } // namespace ntp_snippets |
| OLD | NEW |