| OLD | NEW |
| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const GURL& offline_url) { | 87 const GURL& offline_url) { |
| 88 const OfflinePageItem* offline_page = | 88 const OfflinePageItem* offline_page = |
| 89 GetOfflinePageForOfflineURL(browser_context, offline_url); | 89 GetOfflinePageForOfflineURL(browser_context, offline_url); |
| 90 if (!offline_page) | 90 if (!offline_page) |
| 91 return GURL(); | 91 return GURL(); |
| 92 | 92 |
| 93 return offline_page->url; | 93 return offline_page->url; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 int64_t OfflinePageUtils::GetBookmarkIdForOfflineURL( | |
| 98 content::BrowserContext* browser_context, | |
| 99 const GURL& offline_url) { | |
| 100 const OfflinePageItem* offline_page = | |
| 101 GetOfflinePageForOfflineURL(browser_context, offline_url); | |
| 102 if (!offline_page) | |
| 103 return -1; | |
| 104 | |
| 105 if (offline_page->client_id.name_space != offline_pages::kBookmarkNamespace) { | |
| 106 return -1; | |
| 107 } | |
| 108 | |
| 109 int64_t result; | |
| 110 if (base::StringToInt64(offline_page->client_id.id, &result)) { | |
| 111 return result; | |
| 112 } | |
| 113 return -1; | |
| 114 } | |
| 115 | |
| 116 // static | |
| 117 bool OfflinePageUtils::IsOfflinePage(content::BrowserContext* browser_context, | 97 bool OfflinePageUtils::IsOfflinePage(content::BrowserContext* browser_context, |
| 118 const GURL& offline_url) { | 98 const GURL& offline_url) { |
| 119 return GetOfflinePageForOfflineURL(browser_context, offline_url) != nullptr; | 99 return GetOfflinePageForOfflineURL(browser_context, offline_url) != nullptr; |
| 120 } | 100 } |
| 121 | 101 |
| 122 // static | 102 // static |
| 123 bool OfflinePageUtils::HasOfflinePageForOnlineURL( | 103 bool OfflinePageUtils::HasOfflinePageForOnlineURL( |
| 124 content::BrowserContext* browser_context, | 104 content::BrowserContext* browser_context, |
| 125 const GURL& online_url) { | 105 const GURL& online_url) { |
| 126 const OfflinePageItem* offline_page = | 106 const OfflinePageItem* offline_page = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 138 if (!offline_page) | 118 if (!offline_page) |
| 139 return; | 119 return; |
| 140 | 120 |
| 141 OfflinePageModel* offline_page_model = | 121 OfflinePageModel* offline_page_model = |
| 142 OfflinePageModelFactory::GetForBrowserContext(browser_context); | 122 OfflinePageModelFactory::GetForBrowserContext(browser_context); |
| 143 DCHECK(offline_page_model); | 123 DCHECK(offline_page_model); |
| 144 offline_page_model->MarkPageAccessed(offline_page->offline_id); | 124 offline_page_model->MarkPageAccessed(offline_page->offline_id); |
| 145 } | 125 } |
| 146 | 126 |
| 147 } // namespace offline_pages | 127 } // namespace offline_pages |
| OLD | NEW |