| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/reading_list/offline_url_utils.h" |
| 6 |
| 7 #include "base/md5.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "ios/chrome/browser/chrome_url_constants.h" |
| 10 |
| 11 namespace { |
| 12 const char kOfflineDirectory[] = "Offline"; |
| 13 const char kMainPageFileName[] = "page.html"; |
| 14 } // namespace |
| 15 |
| 16 namespace reading_list { |
| 17 |
| 18 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { |
| 19 return profile_path.Append(FILE_PATH_LITERAL(kOfflineDirectory)); |
| 20 } |
| 21 |
| 22 std::string OfflineURLDirectoryID(const GURL& url) { |
| 23 return base::MD5String(url.spec()); |
| 24 } |
| 25 |
| 26 base::FilePath OfflinePagePath(const GURL& url) { |
| 27 base::FilePath directory(OfflineURLDirectoryID(url)); |
| 28 return directory.Append(FILE_PATH_LITERAL(kMainPageFileName)); |
| 29 } |
| 30 |
| 31 base::FilePath OfflineURLDirectoryAbsolutePath( |
| 32 const base::FilePath& profile_path, |
| 33 const GURL& url) { |
| 34 return OfflineRootDirectoryPath(profile_path) |
| 35 .Append(OfflineURLDirectoryID(url)); |
| 36 } |
| 37 |
| 38 base::FilePath OfflinePageAbsolutePath(const base::FilePath& profile_path, |
| 39 const GURL& url) { |
| 40 return OfflineRootDirectoryPath(profile_path).Append(OfflinePagePath(url)); |
| 41 } |
| 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 } |
| 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 |