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

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

Issue 1959393002: Choose the best offline page when given an online URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits. Created 4 years, 7 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/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
11 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 11 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
12 #include "components/offline_pages/offline_page_feature.h" 12 #include "components/offline_pages/offline_page_feature.h"
13 #include "components/offline_pages/offline_page_item.h" 13 #include "components/offline_pages/offline_page_item.h"
14 #include "components/offline_pages/offline_page_model.h" 14 #include "components/offline_pages/offline_page_model.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace offline_pages { 18 namespace offline_pages {
19 namespace { 19 namespace {
20 20
21 // Returns an offline page originated from the |online_url|. 21 // Returns an offline page originated from the |online_url|.
22 const OfflinePageItem* GetOfflinePageForOnlineURL( 22 const OfflinePageItem* MaybeGetBestOfflinePageForOnlineURL(
23 content::BrowserContext* browser_context, 23 content::BrowserContext* browser_context,
24 const GURL& online_url) { 24 const GURL& online_url) {
25 DCHECK(browser_context); 25 DCHECK(browser_context);
26 26
27 if (!IsOfflinePagesEnabled()) 27 if (!IsOfflinePagesEnabled())
28 return nullptr; 28 return nullptr;
29 29
30 OfflinePageModel* offline_page_model = 30 OfflinePageModel* offline_page_model =
31 OfflinePageModelFactory::GetForBrowserContext(browser_context); 31 OfflinePageModelFactory::GetForBrowserContext(browser_context);
32 if (!offline_page_model) 32 if (!offline_page_model)
33 return nullptr; 33 return nullptr;
34 34
35 return offline_page_model->MaybeGetPageByOnlineURL(online_url); 35 return offline_page_model->MaybeGetBestPageForOnlineURL(online_url);
36 } 36 }
37 37
38 // Returns an offline page that is stored as the |offline_url|. 38 // Returns an offline page that is stored as the |offline_url|.
39 const OfflinePageItem* GetOfflinePageForOfflineURL( 39 const OfflinePageItem* GetOfflinePageForOfflineURL(
40 content::BrowserContext* browser_context, 40 content::BrowserContext* browser_context,
41 const GURL& offline_url) { 41 const GURL& offline_url) {
42 DCHECK(browser_context); 42 DCHECK(browser_context);
43 43
44 if (!IsOfflinePagesEnabled()) 44 if (!IsOfflinePagesEnabled())
45 return nullptr; 45 return nullptr;
(...skipping 21 matching lines...) Expand all
67 base::EndsWith(url.spec(), 67 base::EndsWith(url.spec(),
68 OfflinePageMHTMLArchiver::GetFileNameExtension(), 68 OfflinePageMHTMLArchiver::GetFileNameExtension(),
69 base::CompareCase::INSENSITIVE_ASCII); 69 base::CompareCase::INSENSITIVE_ASCII);
70 } 70 }
71 71
72 // static 72 // static
73 GURL OfflinePageUtils::GetOfflineURLForOnlineURL( 73 GURL OfflinePageUtils::GetOfflineURLForOnlineURL(
74 content::BrowserContext* browser_context, 74 content::BrowserContext* browser_context,
75 const GURL& online_url) { 75 const GURL& online_url) {
76 const OfflinePageItem* offline_page = 76 const OfflinePageItem* offline_page =
77 GetOfflinePageForOnlineURL(browser_context, online_url); 77 MaybeGetBestOfflinePageForOnlineURL(browser_context, online_url);
78 if (!offline_page) 78 if (!offline_page)
79 return GURL(); 79 return GURL();
80 80
81 return offline_page->GetOfflineURL(); 81 return offline_page->GetOfflineURL();
82 } 82 }
83 83
84 // static 84 // static
85 GURL OfflinePageUtils::GetOnlineURLForOfflineURL( 85 GURL OfflinePageUtils::GetOnlineURLForOfflineURL(
86 content::BrowserContext* browser_context, 86 content::BrowserContext* browser_context,
87 const GURL& offline_url) { 87 const GURL& offline_url) {
(...skipping 29 matching lines...) Expand all
117 bool OfflinePageUtils::IsOfflinePage(content::BrowserContext* browser_context, 117 bool OfflinePageUtils::IsOfflinePage(content::BrowserContext* browser_context,
118 const GURL& offline_url) { 118 const GURL& offline_url) {
119 return GetOfflinePageForOfflineURL(browser_context, offline_url) != nullptr; 119 return GetOfflinePageForOfflineURL(browser_context, offline_url) != nullptr;
120 } 120 }
121 121
122 // static 122 // static
123 bool OfflinePageUtils::HasOfflinePageForOnlineURL( 123 bool OfflinePageUtils::HasOfflinePageForOnlineURL(
124 content::BrowserContext* browser_context, 124 content::BrowserContext* browser_context,
125 const GURL& online_url) { 125 const GURL& online_url) {
126 const OfflinePageItem* offline_page = 126 const OfflinePageItem* offline_page =
127 GetOfflinePageForOnlineURL(browser_context, online_url); 127 MaybeGetBestOfflinePageForOnlineURL(browser_context, online_url);
128 return offline_page && !offline_page->file_path.empty(); 128 return offline_page && !offline_page->file_path.empty();
129 } 129 }
130 130
131 // static 131 // static
132 void OfflinePageUtils::MarkPageAccessed( 132 void OfflinePageUtils::MarkPageAccessed(
133 content::BrowserContext* browser_context, const GURL& offline_url) { 133 content::BrowserContext* browser_context, const GURL& offline_url) {
134 DCHECK(browser_context); 134 DCHECK(browser_context);
135 135
136 const OfflinePageItem* offline_page = 136 const OfflinePageItem* offline_page =
137 GetOfflinePageForOfflineURL(browser_context, offline_url); 137 GetOfflinePageForOfflineURL(browser_context, offline_url);
138 if (!offline_page) 138 if (!offline_page)
139 return; 139 return;
140 140
141 OfflinePageModel* offline_page_model = 141 OfflinePageModel* offline_page_model =
142 OfflinePageModelFactory::GetForBrowserContext(browser_context); 142 OfflinePageModelFactory::GetForBrowserContext(browser_context);
143 DCHECK(offline_page_model); 143 DCHECK(offline_page_model);
144 offline_page_model->MarkPageAccessed(offline_page->offline_id); 144 offline_page_model->MarkPageAccessed(offline_page->offline_id);
145 } 145 }
146 146
147 } // namespace offline_pages 147 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_bridge.cc ('k') | components/offline_pages/offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698