| 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 "ios/chrome/browser/reading_list/offline_url_utils.h" | 5 #include "components/reading_list/offline_url_utils.h" |
| 6 | 6 |
| 7 #include "base/md5.h" | 7 #include "base/md5.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "ios/chrome/browser/chrome_url_constants.h" | |
| 10 | 9 |
| 11 namespace { | 10 namespace { |
| 12 const char kOfflineDirectory[] = "Offline"; | 11 const char kOfflineDirectory[] = "Offline"; |
| 13 const char kMainPageFileName[] = "page.html"; | 12 const char kMainPageFileName[] = "page.html"; |
| 14 } // namespace | 13 } // namespace |
| 15 | 14 |
| 16 namespace reading_list { | 15 namespace reading_list { |
| 17 | 16 |
| 18 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { | 17 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { |
| 19 return profile_path.Append(FILE_PATH_LITERAL(kOfflineDirectory)); | 18 return profile_path.Append(FILE_PATH_LITERAL(kOfflineDirectory)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 const base::FilePath& profile_path, | 31 const base::FilePath& profile_path, |
| 33 const GURL& url) { | 32 const GURL& url) { |
| 34 return OfflineRootDirectoryPath(profile_path) | 33 return OfflineRootDirectoryPath(profile_path) |
| 35 .Append(OfflineURLDirectoryID(url)); | 34 .Append(OfflineURLDirectoryID(url)); |
| 36 } | 35 } |
| 37 | 36 |
| 38 base::FilePath OfflinePageAbsolutePath(const base::FilePath& profile_path, | 37 base::FilePath OfflinePageAbsolutePath(const base::FilePath& profile_path, |
| 39 const GURL& url) { | 38 const GURL& url) { |
| 40 return OfflineRootDirectoryPath(profile_path).Append(OfflinePagePath(url)); | 39 return OfflineRootDirectoryPath(profile_path).Append(OfflinePagePath(url)); |
| 41 } | 40 } |
| 42 | |
| 43 GURL DistilledURLForPath(const base::FilePath& distilled_path) { | |
| 44 if (distilled_path.empty()) { | |
| 45 return GURL(); | |
| 46 } | |
| 47 return GURL(kChromeUIOfflineURL + distilled_path.value()); | |
| 48 } | 41 } |
| 49 | |
| 50 GURL FileURLForDistilledURL(const GURL& distilled_url, | |
| 51 const base::FilePath& profile_path, | |
| 52 GURL* resources_root_url) { | |
| 53 if (!distilled_url.is_valid()) { | |
| 54 return GURL(); | |
| 55 } | |
| 56 DCHECK(distilled_url.SchemeIs(kChromeUIScheme)); | |
| 57 base::FilePath offline_path = profile_path.AppendASCII(kOfflineDirectory); | |
| 58 | |
| 59 GURL file_url(base::StringPrintf("%s%s", url::kFileScheme, | |
| 60 url::kStandardSchemeSeparator) + | |
| 61 offline_path.value() + distilled_url.path()); | |
| 62 if (resources_root_url) { | |
| 63 *resources_root_url = file_url.Resolve("."); | |
| 64 } | |
| 65 return file_url; | |
| 66 } | |
| 67 } | |
| OLD | NEW |