Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: ios/chrome/browser/reading_list/reading_list_web_state_observer.mm

Issue 2578973002: Reload offline version on load failure (Closed)
Patch Set: cleaner Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/reading_list/reading_list_web_state_observer.mm
diff --git a/ios/chrome/browser/reading_list/reading_list_web_state_observer.mm b/ios/chrome/browser/reading_list/reading_list_web_state_observer.mm
index b4aa9c0983e0990ab5f7f49a9064cd8bef3b5f2b..369962fbe7284d67141d39dbee8904710402c839 100644
--- a/ios/chrome/browser/reading_list/reading_list_web_state_observer.mm
+++ b/ios/chrome/browser/reading_list/reading_list_web_state_observer.mm
@@ -9,7 +9,8 @@
#include "base/memory/ptr_util.h"
#include "components/reading_list/ios/reading_list_model.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
-#include "ios/chrome/browser/reading_list/reading_list_entry_loading_util.h"
+#include "ios/chrome/browser/chrome_url_constants.h"
+#include "ios/chrome/browser/reading_list/offline_url_utils.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h"
@@ -83,15 +84,78 @@ ReadingListWebStateObserver::ReadingListWebStateObserver(
DCHECK(reading_list_model_);
}
-void ReadingListWebStateObserver::DidStopLoading() {
- StopCheckingProgress();
+web::NavigationItem* ReadingListWebStateObserver::CurrentItem() {
+ web::NavigationManager* manager = web_state()->GetNavigationManager();
+ if (!manager) {
+ return nullptr;
+ }
+ web::NavigationItem* item = manager->GetTransientItem();
Eugene But (OOO till 7-30) 2016/12/19 17:52:32 Should this just be GetVisibleItem instead?
Olivier 2016/12/19 18:26:38 Yes, this seems the correct method. Replaced in co
Olivier 2016/12/20 12:29:46 I cannot use GetVisibleItem after all as it does n
Eugene But (OOO till 7-30) 2016/12/20 18:11:03 I think GetVisibleItem is WAI, but looks like it's
+ if (item) {
+ return item;
+ }
+ item = manager->GetPendingItem();
+ if (item) {
+ return item;
+ }
+ item = manager->GetLastCommittedItem();
+ if (item) {
+ return item;
+ }
+ return nullptr;
+}
+
+void ReadingListWebStateObserver::DidStartLoading() {
+ if (!reading_list_model_->loaded() || !web_state()) {
+ StopCheckingProgress();
+ return;
+ }
+ web::NavigationItem* item = CurrentItem();
+
+ if (!item) {
+ StopCheckingProgress();
+ return;
+ }
+
+ GURL virtual_url = item->GetVirtualURL();
+ GURL loading_url = item->GetURL();
+ if (virtual_url.is_empty()) {
+ virtual_url = loading_url;
+ }
+ if (loading_url.SchemeIs(kChromeUIScheme) &&
+ loading_url.host() == kChromeUIOfflineHost) {
+ StopCheckingProgress();
+ return;
+ }
+ const ReadingListEntry* entry =
+ reading_list_model_->GetEntryByURL(virtual_url);
+ if (!entry || (entry->DistilledState() != ReadingListEntry::PROCESSED)) {
+ StopCheckingProgress();
+ return;
+ }
+ StartCheckingProgress(virtual_url);
}
void ReadingListWebStateObserver::PageLoaded(
web::PageLoadCompletionStatus load_completion_status) {
- if (load_completion_status == web::PageLoadCompletionStatus::SUCCESS &&
- pending_url_.is_valid()) {
+ if (!reading_list_model_->loaded() || !web_state() ||
+ !pending_url_.is_valid()) {
+ StopCheckingProgress();
+ return;
+ }
+ web::NavigationItem* item = CurrentItem();
+ if (!item) {
+ StopCheckingProgress();
+ return;
+ }
+
+ if (load_completion_status == web::PageLoadCompletionStatus::SUCCESS) {
reading_list_model_->SetReadStatus(pending_url_, true);
+ } else {
+ const ReadingListEntry* entry =
+ reading_list_model_->GetEntryByURL(pending_url_);
+ if (entry) {
+ LoadReadingListDistilled();
+ }
}
StopCheckingProgress();
}
@@ -133,11 +197,30 @@ void ReadingListWebStateObserver::VerifyIfReadingListEntryStartedLoading() {
double progress = web_state()->GetLoadingProgress();
const double kMinimumExpectedProgressPerStep = 0.25;
if (progress < try_number_ * kMinimumExpectedProgressPerStep) {
- reading_list::LoadReadingListDistilled(*entry, reading_list_model_,
- web_state());
+ LoadReadingListDistilled();
}
if (try_number_ >= 3) {
// Loading reached 75%, let the page finish normal loading.
timer_->Stop();
}
}
+
+void ReadingListWebStateObserver::LoadReadingListDistilled() {
+ const ReadingListEntry* entry =
+ reading_list_model_->GetEntryByURL(pending_url_);
+ DCHECK(entry->DistilledState() == ReadingListEntry::PROCESSED);
+ GURL url =
+ reading_list::DistilledURLForPath(entry->DistilledPath(), entry->URL());
+ web::NavigationItem* item = CurrentItem();
+ if (!item) {
+ return;
+ }
+ if (pending_url_.SchemeIs(kChromeUIScheme) &&
+ pending_url_.host() == kChromeUIOfflineHost) {
+ return;
+ }
+ item->SetURL(url);
+ item->SetVirtualURL(pending_url_);
+ web_state()->GetNavigationManager()->Reload(NO);
+ reading_list_model_->SetReadStatus(entry->URL(), true);
+}

Powered by Google App Engine
This is Rietveld 408576698