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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 downloads_status_ = new_status; | 293 downloads_status_ = new_status; |
294 observer()->OnCategoryStatusChanged(this, category, new_status); | 294 observer()->OnCategoryStatusChanged(this, category, new_status); |
295 } else { | 295 } else { |
296 NOTREACHED() << "Unknown category " << category.id(); | 296 NOTREACHED() << "Unknown category " << category.id(); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 ContentSuggestion OfflinePageSuggestionsProvider::ConvertOfflinePage( | 300 ContentSuggestion OfflinePageSuggestionsProvider::ConvertOfflinePage( |
301 Category category, | 301 Category category, |
302 const OfflinePageItem& offline_page) const { | 302 const OfflinePageItem& offline_page) const { |
303 // TODO(pke): Make sure the URL is actually opened as an offline URL. | 303 // TODO(pke/jianli): Hook up to always load offline page regardless the |
304 // Currently, the browser opens the offline URL and then immediately | 304 // network conditions. |
305 // redirects to the online URL if the device is online. | |
306 ContentSuggestion suggestion( | 305 ContentSuggestion suggestion( |
307 MakeUniqueID(category, base::IntToString(offline_page.offline_id)), | 306 MakeUniqueID(category, base::IntToString(offline_page.offline_id)), |
308 offline_page.GetOfflineURL()); | 307 offline_page.url); |
309 | 308 |
310 if (offline_page.title.empty()) { | 309 if (offline_page.title.empty()) { |
311 // TODO(pke): Remove this fallback once the OfflinePageModel provides titles | 310 // TODO(pke): Remove this fallback once the OfflinePageModel provides titles |
312 // for all (relevant) OfflinePageItems. | 311 // for all (relevant) OfflinePageItems. |
313 suggestion.set_title(base::UTF8ToUTF16(offline_page.url.spec())); | 312 suggestion.set_title(base::UTF8ToUTF16(offline_page.url.spec())); |
314 } else { | 313 } else { |
315 suggestion.set_title(offline_page.title); | 314 suggestion.set_title(offline_page.title); |
316 } | 315 } |
317 suggestion.set_publish_date(offline_page.creation_time); | 316 suggestion.set_publish_date(offline_page.creation_time); |
318 suggestion.set_publisher_name(base::UTF8ToUTF16(offline_page.url.host())); | 317 suggestion.set_publisher_name(base::UTF8ToUTF16(offline_page.url.host())); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( | 375 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( |
377 Category category, | 376 Category category, |
378 const std::set<std::string>& dismissed_ids) { | 377 const std::set<std::string>& dismissed_ids) { |
379 base::ListValue list; | 378 base::ListValue list; |
380 for (const std::string& dismissed_id : dismissed_ids) | 379 for (const std::string& dismissed_id : dismissed_ids) |
381 list.AppendString(dismissed_id); | 380 list.AppendString(dismissed_id); |
382 pref_service_->Set(GetDismissedPref(category), list); | 381 pref_service_->Set(GetDismissedPref(category), list); |
383 } | 382 } |
384 | 383 |
385 } // namespace ntp_snippets | 384 } // namespace ntp_snippets |
OLD | NEW |