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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils.cc

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: Address more feedback Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/offline_pages/offline_page_utils.h" 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
15 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" 15 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
16 #include "chrome/browser/android/tab_android.h" 16 #include "chrome/browser/android/tab_android.h"
17 #include "components/offline_pages/client_namespace_constants.h" 17 #include "components/offline_pages/client_namespace_constants.h"
18 #include "components/offline_pages/offline_page_feature.h" 18 #include "components/offline_pages/offline_page_feature.h"
19 #include "components/offline_pages/offline_page_item.h" 19 #include "components/offline_pages/offline_page_item.h"
20 #include "components/offline_pages/offline_page_model.h" 20 #include "components/offline_pages/offline_page_model.h"
21 #include "components/offline_pages/request_header/offline_page_header.h"
21 #include "content/public/browser/browser_context.h" 22 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 namespace offline_pages { 26 namespace offline_pages {
26 namespace { 27 namespace {
27 28
28 // Returns an offline page that is stored as the |offline_url|. 29 // Returns an offline page that is stored as the |offline_url|.
29 const OfflinePageItem* GetOfflinePageForOfflineURL( 30 const OfflinePageItem* GetOfflinePageForOfflineURL(
30 content::BrowserContext* browser_context, 31 content::BrowserContext* browser_context,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GetOfflinePageForOfflineURL(browser_context, offline_url); 146 GetOfflinePageForOfflineURL(browser_context, offline_url);
146 if (!offline_page) 147 if (!offline_page)
147 return; 148 return;
148 149
149 OfflinePageModel* offline_page_model = 150 OfflinePageModel* offline_page_model =
150 OfflinePageModelFactory::GetForBrowserContext(browser_context); 151 OfflinePageModelFactory::GetForBrowserContext(browser_context);
151 DCHECK(offline_page_model); 152 DCHECK(offline_page_model);
152 offline_page_model->MarkPageAccessed(offline_page->offline_id); 153 offline_page_model->MarkPageAccessed(offline_page->offline_id);
153 } 154 }
154 155
156 // static
155 const OfflinePageItem* OfflinePageUtils::GetOfflinePageFromWebContents( 157 const OfflinePageItem* OfflinePageUtils::GetOfflinePageFromWebContents(
156 content::WebContents* web_contents) { 158 content::WebContents* web_contents) {
157 OfflinePageTabHelper* tab_helper = 159 OfflinePageTabHelper* tab_helper =
158 OfflinePageTabHelper::FromWebContents(web_contents); 160 OfflinePageTabHelper::FromWebContents(web_contents);
159 return tab_helper ? tab_helper->offline_page() : nullptr; 161 return tab_helper ? tab_helper->offline_page() : nullptr;
160 } 162 }
161 163
162 // static 164 // static
165 const OfflinePageHeader* OfflinePageUtils::GetOfflineHeaderFromWebContents(
166 content::WebContents* web_contents) {
167 OfflinePageTabHelper* tab_helper =
168 OfflinePageTabHelper::FromWebContents(web_contents);
169 return tab_helper ? &(tab_helper->offline_header()) : nullptr;
170 }
171
172 // static
163 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents, 173 bool OfflinePageUtils::GetTabId(content::WebContents* web_contents,
164 int* tab_id) { 174 int* tab_id) {
165 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents); 175 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents);
166 if (!tab_android) 176 if (!tab_android)
167 return false; 177 return false;
168 *tab_id = tab_android->GetAndroidId(); 178 *tab_id = tab_android->GetAndroidId();
169 return true; 179 return true;
170 } 180 }
171 181
172 } // namespace offline_pages 182 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698